custom/plugins/Neon6Configurator/src/Subscribers/OnCheckoutFinishPageLoaded.php line 34

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Neon\Configurator\Subscribers;
  3. use Neon\Configurator\Neon6Configurator;
  4. use Shopware\Core\Checkout\Cart\LineItem\LineItem;
  5. use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity;
  6. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Filesystem\Filesystem;
  9. class OnCheckoutFinishPageLoaded implements EventSubscriberInterface
  10. {
  11.     private $projectDir;
  12.     public function __construct($projectDir)
  13.     {
  14.         $this->projectDir $projectDir '/';
  15.     }
  16.     /**
  17.      * @inheritDoc
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             CheckoutFinishPageLoadedEvent::class => 'OnCheckoutFinishPageLoaded'
  23.         ];
  24.     }
  25.     /**
  26.      * @param CheckoutFinishPageLoadedEvent $event
  27.      */
  28.     public function OnCheckoutFinishPageLoaded(CheckoutFinishPageLoadedEvent $event): void
  29.     {
  30.         $page $event->getPage();
  31.         $order $page->getOrder();
  32.         $orderId $order->getId();
  33.         $lineItems $order->getLineItems()->getElements();
  34.         $filesystem = new Filesystem();
  35.         /** @var OrderLineItemEntity $lineItem */
  36.         foreach ($lineItems as $lineItem) {
  37.             $unitarticlePayloadValue array_key_exists(Neon6Configurator::PAYLOAD_KEY$lineItem->getPayload())
  38.                 ? $lineItem->getPayload()[Neon6Configurator::PAYLOAD_KEY]
  39.                 : null;
  40.             if ($unitarticlePayloadValue != null) {
  41.                 foreach ($unitarticlePayloadValue[Neon6Configurator::PAYLOAD_KEY_USER_CONFIGURATION] as $field) {
  42.                     if ($field['field_type'] == 'upload' &&
  43.                         $field['user_value_addon'] !== null &&
  44.                         $field['user_value_addon'][0] !== null) {
  45.                         if (!$filesystem->exists($this->projectDir Neon6Configurator::FILE_FOLDER 'uploads/orders/' $orderId)) {
  46.                             $filesystem->mkdir($this->projectDir Neon6Configurator::FILE_FOLDER 'uploads/orders/' $orderId);
  47.                         }
  48.                         $fileName $field['user_value']['uuid'] . '--' $field['user_value_addon'][0]['name'];
  49.                         if (!$filesystem->exists($this->projectDir Neon6Configurator::FILE_FOLDER 'uploads/orders/' $orderId '/' $fileName)) {
  50.                             $filesystem->copy($this->projectDir Neon6Configurator::FILE_FOLDER 'uploads/tmp/' $fileName$this->projectDir Neon6Configurator::FILE_FOLDER 'uploads/orders/' $orderId '/' $fileName);
  51.                         }
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }