| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace WSW\SiftScience\Support\Traits\Transformers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use WSW\SiftScience\Collections\Items; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use WSW\SiftScience\Collections\PaymentMethods; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use WSW\SiftScience\Collections\Promotions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use WSW\SiftScience\Entities\Address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use WSW\SiftScience\Entities\CreditPoint; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use WSW\SiftScience\Entities\Discount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use WSW\SiftScience\Entities\PaymentMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use WSW\SiftScience\Transformers\Entities\AddressTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use WSW\SiftScience\Transformers\Entities\CreditPointTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use WSW\SiftScience\Transformers\Entities\DiscountTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use WSW\SiftScience\Transformers\Entities\ItemTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use WSW\SiftScience\Transformers\Entities\PaymentMethodTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use WSW\SiftScience\Transformers\Entities\PromotionTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Trait Relationships | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @package WSW\SiftScience\Support\Traits\Transformers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author Ronaldo Matos Rodrigues <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | trait Relationships | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     use Fractal; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param Address|null $address | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 13 |  |     public function address($address = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 13 |  |         return (!$address instanceof Address) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 12 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 13 |  |             : $this->loadItem($address, new AddressTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param Discount|null $discount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 3 |  |     public function discount($discount = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 3 |  |         return (!$discount instanceof Discount) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 2 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 3 |  |             : $this->loadItem($discount, new DiscountTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param CreditPoint|null $creditPoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 3 |  |     public function creditPoint($creditPoint = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 3 |  |         return (!$creditPoint instanceof CreditPoint) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 2 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 3 |  |             : $this->loadItem($creditPoint, new CreditPointTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param PaymentMethods|null $collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 11 |  |     public function paymentMethods($collection = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 11 |  |         return (!$collection instanceof  PaymentMethods) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 11 |  |             : $this->loadCollection($collection->getValues(), new PaymentMethodTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @param PaymentMethod|null $item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 82 | 4 |  |     public function paymentMethod($item = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 4 |  |         return (!$item instanceof  PaymentMethod) | 
            
                                                                        
                            
            
                                    
            
            
                | 85 | 3 |  |             ? null | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 4 |  |             : $this->loadItem($item, new PaymentMethodTransformer)->toArray(); | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param Items|null $items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 6 |  |     public function items($items) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 6 |  |         return (!$items instanceof Items) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 6 |  |             : $this->loadCollection($items->getValues(), new ItemTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @param Promotions|null $promotions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 6 |  |     public function promotions($promotions = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 6 |  |         return (!$promotions instanceof Promotions) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 1 |  |             ? null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 6 |  |             : $this->loadCollection($promotions->getValues(), new PromotionTransformer)->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |  |