vendor/crehler/mojebambino-catalog/src/Subscriber/ProductLoadSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @copyright 2020 Crehler Sp. z o. o.
  5.  * @link https://crehler.com/
  6.  * @support support@crehler.com
  7.  *
  8.  * @author Mateusz FlasiƄski
  9.  *
  10.  * For the full copyright and license information, please view the LICENSE
  11.  * file that was distributed with this source code.
  12.  */
  13. namespace Crehler\Catalog\Subscriber;
  14. use Crehler\Catalog\Struct\CatalogProductTypeStruct;
  15. use Shopware\Core\Content\Product\ProductEntity;
  16. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
  17. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use function Symfony\Component\String\u;
  20. class ProductLoadSubscriber implements EventSubscriberInterface
  21. {
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return ['product.loaded' => 'onProductLoaded'];
  25.     }
  26.     public function onProductLoaded(EntityLoadedEvent $event)
  27.     {
  28. //        /** @var ProductEntity $entity */
  29. //        foreach ($event->getEntities() as $entity) {
  30. //            if ($entity->getProductNumber() === 'PLA-ZIM-0006') {
  31. //                dd($entity);
  32. //                dd(1);
  33. //            }
  34. //        }
  35.         /** @var SalesChannelProductEntity $product */
  36.         foreach ($event->getEntities() as $product) {
  37.             $struct = new CatalogProductTypeStruct();
  38.             $foreignKeys $product->getExtension('foreignKeys');
  39.             $struct->setArrangement($foreignKeys->offsetGet('arrangementId') !== null);
  40.             $struct->setInspirations($foreignKeys->offsetGet('inspirationId') !== null);
  41.             $product->addExtension(u($struct->getApiAlias())->camel()->toString(), $struct);
  42.         }
  43.     }
  44. }