| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Setono\SyliusLagersystemPlugin\Factory\Order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Setono\SyliusLagersystemPlugin\Factory\Product\ProductVariantViewFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Setono\SyliusLagersystemPlugin\View\Order\ItemView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sylius\Component\Core\Model\OrderItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Sylius\Component\Core\Model\OrderItemUnitInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ItemViewFactory implements ItemViewFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** @var ProductVariantViewFactoryInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected $productVariantViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** @var ItemUnitViewFactoryInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $itemUnitViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     protected $itemViewClass; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         ProductVariantViewFactoryInterface $productVariantViewFactory, | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         ItemUnitViewFactoryInterface $itemUnitViewFactory, | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         string $itemViewClass | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->productVariantViewFactory = $productVariantViewFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $this->itemUnitViewFactory = $itemUnitViewFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->itemViewClass = $itemViewClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function create(OrderItemInterface $item, string $localeCode): ItemView | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         /** @var ItemView $itemView */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $itemView = new $this->itemViewClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $itemView->id = $item->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $itemView->quantity = $item->getQuantity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $itemView->total = $item->getTotal(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $itemView->variant = $this->productVariantViewFactory->create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $item->getVariant(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             $localeCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         /** @var OrderItemUnitInterface $itemUnit */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         foreach ($item->getUnits() as $itemUnit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $itemView->units[] = $this->itemUnitViewFactory->create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 $itemUnit, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 $localeCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return $itemView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |  |