| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Setono\SyliusLagersystemPlugin\Factory\Shipping; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Setono\SyliusLagersystemPlugin\Factory\Product\ProductVariantViewFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Setono\SyliusLagersystemPlugin\View\Shipping\ShipmentUnitView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sylius\Component\Core\Model\OrderItemUnitInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Sylius\Component\Core\Model\ProductVariantInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Sylius\Component\Shipping\Model\ShipmentUnitInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Webmozart\Assert\Assert; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class ShipmentUnitViewFactory implements ShipmentUnitViewFactoryInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /** @var ProductVariantViewFactoryInterface */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     protected $shippableViewFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     /** @var string */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     protected $shipmentUnitViewClass; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         ProductVariantViewFactoryInterface $shippableViewFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         string $shipmentUnitViewClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->shippableViewFactory = $shippableViewFactory; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |         $this->shipmentUnitViewClass = $shipmentUnitViewClass; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function create(ShipmentUnitInterface $shipmentUnit, string $locale): ShipmentUnitView | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         /** @var ProductVariantInterface|null $shippable */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $shippable = $shipmentUnit->getShippable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         Assert::notNull($shippable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         /** @var ShipmentUnitView $shipmentUnitView */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $shipmentUnitView = new $this->shipmentUnitViewClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $shipmentUnitView->shippable = $this->shippableViewFactory->create($shippable, $locale); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if ($shipmentUnit instanceof OrderItemUnitInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $shipmentUnitView->total = $shipmentUnit->getTotal(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             $shipmentUnitView->adjustmentsTotal = $shipmentUnit->getAdjustmentsTotal(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 45 |  |  |         return $shipmentUnitView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |  |