src/EventSubscriber/Product/ProductResourceSubscriber.php line 25
<?phpnamespace App\EventSubscriber\Product;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\EventDispatcher\GenericEvent;use Webmozart\Assert\Assert;use Sylius\Component\Customer\Model\CustomerInterface;use App\Repository\Customer\CustomerRepository;use App\Entity\Channel\ChannelEcodaAccountInfo;use App\Entity\Product\Product;use App\Repository\Channel\ChannelEcodaAccountInfoRepository;use App\Repository\Channel\ChannelEcodaAccountTypeRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use App\Manager\EcodaAccountManager;use App\Entity\Product\ProductVariant;class ProductResourceSubscriber implements EventSubscriberInterface{public function onPreCreate(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, Product::class);$this->updateDimensions($entity);}public function onPreUpdate(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, Product::class);$this->updateDimensions($entity);}private function updateDimensions($entity){if($entity->getVariants()[0] !== null && ($dimension = $entity->getVariants()[0]->getDimension())){$entity->getVariants()[0]->setHeight($dimension->getHeight());$entity->getVariants()[0]->setWidth($dimension->getWidth());$entity->getVariants()[0]->setDepth($dimension->getDepth());$entity->getVariants()[0]->setMesurementUnit($dimension->getUnit()->getCode());}}public static function getSubscribedEvents(){return ['sylius.product.pre_create' => 'onPreCreate','sylius.product.pre_update' => 'onPreUpdate',];}}