src/EventSubscriber/Product/ProductVariantResourceSubscriber.php line 24

  1. <?php
  2. namespace App\EventSubscriber\Product;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\EventDispatcher\GenericEvent;
  6. use Webmozart\Assert\Assert;
  7. use Sylius\Component\Customer\Model\CustomerInterface;
  8. use App\Repository\Customer\CustomerRepository;
  9. use App\Entity\Channel\ChannelEcodaAccountInfo;
  10. use App\Repository\Channel\ChannelEcodaAccountInfoRepository;
  11. use App\Repository\Channel\ChannelEcodaAccountTypeRepository;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  15. use App\Manager\EcodaAccountManager;
  16. use App\Entity\Product\ProductVariant;
  17. class ProductVariantResourceSubscriber  implements EventSubscriberInterface
  18.      
  19.     public function onSyliusProductVariantPreCreate(GenericEvent $event)
  20.     {  
  21.         $entity $event->getSubject();  
  22.         Assert::isInstanceOf($entityProductVariant::class); 
  23.         $this->updateDimensions($entity);
  24.     } 
  25.     public function onSyliusProductVariantPreUpdate(GenericEvent $event)
  26.     {  
  27.         $entity $event->getSubject();  
  28.         Assert::isInstanceOf($entityProductVariant::class); 
  29.         dd(5);
  30.         $this->updateDimensions($entity);
  31.     } 
  32.     private function updateDimensions($entity){
  33.         if($dimension $entity->getDimension()){
  34.             $entity->setHeight($dimension->getHeight());
  35.             $entity->setWidth($dimension->getWidth());
  36.             $entity->setDepth($dimension->getDepth());
  37.             $entity->setMesurementUnit($dimension->getUnit()->getCode());
  38.         } 
  39.     }
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return [
  43.            'sylius.product_variant.pre_create' => 'onSyliusProductVariantPreCreate'
  44.            'sylius.product_variant.pre_update' => 'onSyliusProductVariantPreUpdate'
  45.         ];
  46.     }
  47. }