custom/plugins/ProcLivePrice/src/Subscriber/LivePriceSubscriber.php line 369

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Proc\ProcLivePrice\Subscriber;
  3. use Proc\ProcOrderSimulate\Subscriber\OrderSimulateSubscriber;
  4. use Shopware\Core\Checkout\Customer\CustomerEntity;
  5. use Shopware\Core\Content\Product\DataAbstractionLayer\CheapestPrice\CheapestPriceContainer;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Pricing\Price;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollection;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Shopware\Core\Checkout\Cart\Price\Struct\ListPrice;
  11. use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice;
  12. use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
  13. use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRule;
  14. use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
  15. use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax;
  16. use Shopware\Core\Content\Product\ProductEntity;
  17. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
  18. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  19. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  20. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  21. use Shopware\Core\Framework\DataAbstractionLayer\Pricing\CalculatedListingPrice;
  22. use Shopware\Core\Content\Product\DataAbstractionLayer\CheapestPrice\CalculatedCheapestPrice;
  23. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  24. use Shopware\Core\Content\Product\Events\ProductListingResultEvent;
  25. use Shopware\Core\Framework\Event\NestedEvent;
  26. use Swag\EnterpriseSearch\Search\Page\SearchPageLoadedEvent;
  27. use Proc\ProcLivePrice\Helper\BuildRequestHelper;
  28. use Proc\ProcFoundation\Helper\ErrorHandler;
  29. use Proc\ProcFoundation\Helper\RequestHandler;
  30. use Proc\ProcFoundation\Service\ProcFoundationService;
  31. use Symfony\Component\HttpFoundation\RedirectResponse;
  32. use Symfony\Component\Routing\RouterInterface;
  33. /**
  34.  * Class LivePriceSubscriber
  35.  * @package Proc\ProcLivePrice\Subscriber
  36.  */
  37. class LivePriceSubscriber implements EventSubscriberInterface
  38. {
  39.     private const PATH '/iman/live-price';
  40.     private const CUSTOM_ZLOTY 'PLN';
  41.     /**
  42.      * @var RequestHandler
  43.      */
  44.     private $requestHandler;
  45.     /**
  46.      * @var ErrorHandler
  47.      */
  48.     private $errorHandler;
  49.     /**
  50.      * @var string
  51.      */
  52.     private
  53.         $host,
  54.         $port,
  55.         $customerNumber;
  56.     private $error null;
  57.     /**
  58.      * @var ProcFoundationService
  59.      */
  60.     private $foundationService;
  61.     /**
  62.      * @var EntityRepositoryInterface
  63.      */
  64.     private $productRepository;
  65.     /**
  66.      * @var ProductPageLoadedEvent | ProductListingResultEvent | SearchPageLoadedEvent
  67.      */
  68.     private $event;
  69.     /**
  70.      * @var array
  71.      */
  72.     private $result;
  73.     /**
  74.      * @var CalculatedTaxCollection
  75.      */
  76.     private $calculatedTaxCollection;
  77.     /**
  78.      * @var TaxRuleCollection
  79.      */
  80.     private $taxRuleCollection;
  81.     /**
  82.      * @var RouterInterface
  83.      */
  84.     private RouterInterface $router;
  85.     /**
  86.      * @inheritDoc
  87.      */
  88.     public static function getSubscribedEvents(): array
  89.     {
  90.         return [
  91.             ProductPageLoadedEvent::class => ['onProductPageLoaded'1],
  92.             ProductListingResultEvent::class => ['onListingResultLoaded'1],
  93.             SearchPageLoadedEvent::class => ['onListingResultLoaded']
  94.         ];
  95.     }
  96.     /**
  97.      * LivePriceSubscriber constructor.
  98.      * @param ProcFoundationService $foundationService
  99.      * @param RequestHandler $requestHandler
  100.      * @param ErrorHandler $errorHandler
  101.      * @param EntityRepositoryInterface $repositoryInterface
  102.      */
  103.     function __construct(
  104.         ProcFoundationService $foundationService,
  105.         RequestHandler $requestHandler,
  106.         ErrorHandler $errorHandler,
  107.         EntityRepositoryInterface $repositoryInterface,
  108.         RouterInterface $router
  109.     ) {
  110.         $this->foundationService $foundationService;
  111.         $this->requestHandler $requestHandler;
  112.         $this->errorHandler $errorHandler;
  113.         $this->productRepository $repositoryInterface;
  114.         $this->router $router;
  115.     }
  116.     /**
  117.      * @param NestedEvent $event
  118.      * @throws \Exception
  119.      */
  120.     public function onListingResultLoaded(NestedEvent $event)
  121.     {
  122.         $this->event $event;
  123.         /**
  124.          * Prüfung ob Benutzer angemeldet ist, sonst keine Live-Abfrage.
  125.          */
  126.         if (!($this->customerNumber $this->foundationService->checkLogin($this->event->getSalesChannelContext(),
  127.             get_class($this)))) {
  128.             if ($this->event instanceof ProductListingResultEvent) {
  129.                 $products $this->event->getResult()->getElements();
  130.             } else {
  131.                 $products $this->event->getPage()->getListing()?->getElements();
  132.             }
  133.             $this->multiplyByPurchaseUnit($products);
  134.             return;
  135.         }
  136.         /**
  137.          * Prüfen ob der Benutzer eine Artikel-Whitelist hat.
  138.          */
  139.         $customFields $this->event->getSalesChannelContext()->getCustomer()->getCustomFields();
  140.         if (array_key_exists('custom_product_listing_numbers'$customFields) &&
  141.             $customFields['custom_product_listing_numbers'] != null &&
  142.             $customFields['custom_product_listing_numbers'] != &&
  143.             $customFields['custom_product_listing_numbers'] != '') {
  144.             $allowedArticles explode(','$customFields['custom_product_listing_numbers']);
  145.         } else {
  146.             return;
  147.         }
  148.         /**
  149.          * Configeinstellungen prüfen und setzen.
  150.          */
  151.         if (!$this->checkConfig()) {
  152.             return;
  153.         }
  154.         $productArray = array();
  155.         if ($this->event instanceof ProductListingResultEvent) {
  156.             $resultItems $this->event->getResult()->getIterator();
  157.         } else {
  158.             $resultItems $this->event->getPage()->getListing()->getIterator();
  159.         }
  160.         $articles = [];
  161.         $counter 0;
  162.         while ($resultItems->current() !== null) {
  163.             /**
  164.              * @var SalesChannelProductEntity $product
  165.              */
  166.             $product $resultItems->current();
  167.             // benutzer holen. -> custom field holen.(siehe oben) String in array umwandeln. Prüfen ob artikelnummer vorhanden. Wenn ja dann durchlaufen, wenn nein, continue.
  168.             if (!in_array($product->getProductNumber(), $allowedArticles)) {
  169.                 $resultItems->next();
  170.                 continue;
  171.             }
  172.             $counter++;
  173.             if ($product->getParentId()) {
  174.                 /**
  175.                  * @var ProductEntity $parentProduct
  176.                  */
  177.                 $parentProduct $this->getProduct($product->getParentId(), ['children']);
  178.                 $childArticles = array();
  179.                 foreach ($parentProduct->getChildren()->getElements() as $children) {
  180.                     $childArticle['position-id'] = $counter;
  181.                     $childArticle['article-number'] = $children->getProductNumber();
  182.                     $childArticle['quantity'] = 1;
  183.                     $childArticle['quantity-unit'] = $children->getPackUnit();
  184.                     $childArticles[] = $childArticle;
  185.                 }
  186.                 $childResult $this->getArticleInfo($childArticles);
  187.                 if ($childResult['head']['status'] == 'NOK') {
  188.                     return;
  189.                 }
  190. //                 $this->error = $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUEST, get_class($this), print_r($childResult, true));
  191. //                 $this->errorHandler->writeErrorLog($this->error);
  192.                 $countProductItems sizeof($childResult);
  193.                 $from 0;
  194.                 $to 0;
  195.                 $x 0;
  196.                 foreach ($childResult['articles']['article'] as $childArticle) {
  197.                     // $unitPrice = (float)$childArticle['conditions']['condition'][0]['condition-value'];
  198.                     // $mwstValue = (float)$childArticle['conditions']['condition'][2]['condition-value'];
  199.                     // $unitPrice = $unitPrice + $mwstValue;
  200.                     $unitPrice = (float)$childArticle['price'] / (float)$childArticle['quantity'];
  201.                     if ($x === 0) {
  202.                         $from $unitPrice;
  203.                         $to $unitPrice;
  204.                     } elseif ($unitPrice $from) {
  205.                         $from $unitPrice;
  206.                     } elseif ($unitPrice $to) {
  207.                         $to $unitPrice;
  208.                     }
  209.                     $x++;
  210.                 }
  211.                 /**
  212.                  * @var CalculatedCheapestPrice $productListingPrice
  213.                  */
  214.                 $productListingPrice $product->getCalculatedCheapestPrice();
  215.                 /**
  216.                  * @var CalculatedPrice $fromPrice , $toPrice
  217.                  */
  218.                 $fromPrice = new CalculatedPrice(
  219.                     $from,
  220.                     $from,
  221.                     $productListingPrice->getCalculatedTaxes(),
  222.                     $productListingPrice->getTaxRules(),
  223.                     1);
  224.                 $toPrice = new CalculatedPrice(
  225.                     $to,
  226.                     $to,
  227.                     $productListingPrice->getCalculatedTaxes(),
  228.                     $productListingPrice->getTaxRules(),
  229.                     1);
  230.                 /**
  231.                  * @var CalculatedCheapestPrice $newListingPrice
  232.                  */
  233.                 $newListingPrice = new CalculatedCheapestPrice($from$to$productListingPrice->getCalculatedTaxes(),
  234.                     $productListingPrice->getTaxRules());
  235.                 $product->setCalculatedCheapestPrice($newListingPrice);
  236.                 $product->getCheapestPrice()->getPrice()->first()->setGross($to);
  237.                 $product->getCheapestPrice()->getPrice()->first()->setNet($to);
  238.             }
  239.             $productArray[] = $product;
  240.             $article['position-id'] = $counter;
  241.             $article['article-number'] = $product->getProductNumber();
  242.             $article['quantity'] = 1;
  243.             $article['quantity-unit'] = $product->getPackUnit();
  244.             $articles[] = $article;
  245.             $resultItems->next();
  246.         }
  247.         if (count($articles) <= 0) {
  248.             return;
  249.         }
  250.         $this->result $this->getArticleInfo($articles);
  251.         if ($this->result['head']['status'] == 'NOK') {
  252.             return;
  253.         }
  254.         $countProductItems sizeof($productArray);
  255.         $x 0;
  256.         foreach ($productArray as $productItem) {
  257.             if ($countProductItems 1) {
  258.                 // $unitPrice = (float)$this->result['articles']['article'][$x]['conditions']['condition'][0]['condition-value'];
  259.                 $totalPrice = (float)$this->result['articles']['article'][$x]['price'];
  260.                 $unitPrice = (float)$totalPrice / (float)$this->result['articles']['article'][$x]['quantity'];
  261.                 $mwstRate 0.0// (float)$this->result['articles']['article'][$x]['conditions']['condition'][2]['condition-rate'];
  262.                 $mwstValue 0.0// (float)$this->result['articles']['article'][$x]['conditions']['condition'][2]['condition-value'];
  263.             } else {
  264.                 // $unitPrice = (float)$this->result['articles']['article']['conditions']['condition'][0]['condition-value'];
  265.                 $totalPrice = (float)$this->result['articles']['article']['price'];
  266.                 $unitPrice = (float)$totalPrice / (float)$this->result['articles']['article']['quantity'];
  267.                 $mwstRate 0.0// (float)$this->result['articles']['article']['conditions']['condition'][2]['condition-rate'];
  268.                 $mwstValue 0.0// (float)$this->result['articles']['article']['conditions']['condition'][2]['condition-value'];
  269.             }
  270.             /**
  271.              * @var CalculatedPrice $price
  272.              */
  273.             $price $product->getCalculatedPrice();
  274.             /**
  275.              * @var TaxRule $newTaxRule
  276.              */
  277.             $newTaxRule = new TaxRule($mwstRate);
  278.             /**
  279.              * @var TaxRuleCollection $newTaxRuleCollection
  280.              */
  281.             $newTaxRuleCollection = new TaxRuleCollection();
  282.             $newTaxRuleCollection->add($newTaxRule);
  283.             /**
  284.              * @var CalculatedTax $newCalculateTax
  285.              */
  286.             $newCalculateTax = new CalculatedTax($mwstValue$mwstRate$totalPrice);
  287.             /**
  288.              * @var CalculatedTaxCollection $newCalculatedTaxCollection
  289.              */
  290.             $newCalculatedTaxCollection = new CalculatedTaxCollection();
  291.             $newCalculatedTaxCollection->add($newCalculateTax);
  292.             /**
  293.              * @var CalculatedPrice $newPrice
  294.              */
  295.             $newPrice = new CalculatedPrice(
  296.                 ($unitPrice $mwstValue),
  297.                 $totalPrice,
  298.                 $newCalculatedTaxCollection,
  299.                 $newTaxRuleCollection,
  300.                 $price->getQuantity(),
  301.                 $price->getReferencePrice(),
  302.                 $price->getListPrice()
  303.             );
  304.             $productItem->setCalculatedPrice($newPrice);
  305.             $x++;
  306.         }
  307.     }
  308.     /**
  309.      * @param ProductPageLoadedEvent $event
  310.      */
  311.     public function onProductPageLoaded(ProductPageLoadedEvent $event)
  312.     {
  313.         $this->event $event;
  314.         /**
  315.          * Prüfung ob Benutzer angemeldet ist, sonst keine Live-Abfrage.
  316.          */
  317.         if (!($this->customerNumber $this->foundationService->checkLogin($this->event->getSalesChannelContext(),
  318.             get_class($this)))) {
  319.             // If not logged in, update calculated price.
  320.             $this->multiplyByPurchaseUnit([$event->getPage()->getProduct()]);
  321.             return;
  322.         } else {
  323.             if (array_key_exists('custom_product_listing_numbers',
  324.                 $this->event->getSalesChannelContext()->getCustomer()->getCustomFields())) {
  325.                 $articles explode(',',
  326.                     $this->event->getSalesChannelContext()->getCustomer()->getCustomFields()['custom_product_listing_numbers']);
  327.                 if (!in_array($this->event->getPage()->getProduct()->getProductNumber(), $articles)) {
  328.                     $redirectResponse = new RedirectResponse($this->router->generate('frontend.home.page'));
  329.                     return $redirectResponse->send();
  330.                 }
  331.             }
  332.         }
  333.         /**
  334.          * Configeinstellungen prüfen und setzen.
  335.          */
  336.         if (!$this->checkConfig()) {
  337.             return;
  338.         }
  339.         /**
  340.          * @var SalesChannelProductEntity $product
  341.          */
  342.         $product $this->event->getPage()->getProduct();
  343.         /**
  344.          * @todo Die position-id noch richtig machen
  345.          * @var array $article
  346.          */
  347.         $article['position-id'] = 1;
  348.         $article['article-number'] = $product->getProductNumber();
  349.         $article['quantity'] = 1;
  350.         $article['quantity-unit'] = $product->getPackUnit();
  351.         $this->result $this->getArticleInfo([$article]);
  352. //         $this->error = $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUEST, get_class($this), 'Nach getAticleInfo()');
  353. //         $this->errorHandler->writeErrorLog($this->error);
  354.         if ($this->result['head']['status'] == 'NOK') {
  355.             return;
  356.         }
  357.         // $unitPrice = (float)$this->result['articles']['article']['conditions']['condition'][0]['condition-value'];
  358.         $totalPrice = (float)$this->result['articles']['article']['price'];
  359.         $unitPrice $totalPrice / (float)$this->result['articles']['article']['quantity'];
  360.         $mwstRate 0.0// (float)$this->result['articles']['article']['conditions']['condition'][2]['condition-rate'];
  361.         $mwstValue 0.0// (float)$this->result['articles']['article']['conditions']['condition'][2]['condition-value'];
  362.         /**
  363.          * @var CalculatedPrice $price
  364.          */
  365.         $price $product->getCalculatedPrice();
  366.         /**
  367.          * @var TaxRule $newTaxRule
  368.          */
  369.         $newTaxRule = new TaxRule($mwstRate);
  370.         /** a
  371.          * @var TaxRuleCollection $newTaxRuleCollection
  372.          */
  373.         $newTaxRuleCollection = new TaxRuleCollection();
  374.         $newTaxRuleCollection->add($newTaxRule);
  375.         /**
  376.          * @var CalculatedTax $newCalculateTax
  377.          */
  378.         $newCalculateTax = new CalculatedTax($mwstValue$mwstRate$unitPrice);
  379.         /**
  380.          * @var CalculatedTaxCollection $newCalculatedTaxCollection
  381.          */
  382.         $newCalculatedTaxCollection = new CalculatedTaxCollection();
  383.         $newCalculatedTaxCollection->add($newCalculateTax);
  384.         /**
  385.          * @var TaxRule $newTaxRule
  386.          */
  387.         $newTaxRule = new TaxRule(0.0); // (float)$this->result['articles']['article']['conditions']['condition'][2]['condition-value']);
  388.         $price->getTaxRules()->add($newTaxRule);
  389.         // Get from request or pick default
  390.         if (array_key_exists('free-shipping-threshold'$this->result['shipping-cost'])) {
  391.             $freeShippingThreshold = ['freeShippingThreshold' => $this->result['shipping-cost']['free-shipping-threshold']];
  392.         } else {
  393.             $freeShippingThreshold = ['freeShippingThreshold' => $this->calculateShippingThreshold($event->getSalesChannelContext())];
  394.         }
  395.         $this->event->getContext()->addArrayExtension('deliveryInformations'$freeShippingThreshold);
  396. //        $newReferencePrice = new ReferencePrice(
  397. //            $totalPrice, 1.0, 1.0, $price->getReferencePrice()->getUnitName()
  398. //        );
  399.         /**
  400.          * @var CalculatedPrice $newPrice
  401.          */
  402.         $newPrice = new CalculatedPrice(
  403.         //(float)$this->result['articles']['article']['price'],
  404.             $totalPrice,
  405.             $totalPrice,
  406.             $newCalculatedTaxCollection,
  407.             $newTaxRuleCollection,
  408.             1,
  409.             null,
  410.             // $price->getReferencePrice(),
  411.             // $newReferencePrice,
  412.             ListPrice::createFromUnitPrice($totalPrice$totalPrice)
  413.         );
  414.         $newCalculatedCheapestPrice = new CalculatedCheapestPrice($totalPrice$totalPrice$newCalculatedTaxCollection,
  415.             $newTaxRuleCollection1);
  416. //         $this->error = $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUEST, get_class($this), 'totalPrice - ' . $totalPrice);
  417. //         $this->errorHandler->writeErrorLog($this->error);
  418. //         $this->error = $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUEST, get_class($this), 'unitPrice - ' . $unitPrice);
  419. //         $this->errorHandler->writeErrorLog($this->error);
  420. //        $this->error = $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUEST, get_class($this), 'Price - ' . $newPrice->getPrice());
  421. //        $this->errorHandler->writeErrorLog($this->error);
  422.         $product->setCalculatedCheapestPrice($newCalculatedCheapestPrice);
  423.         $product->setCalculatedPrice($newPrice);
  424.         $product->getPrice()->first()->setNet($totalPrice);
  425.         $product->getPrice()->first()->setGross($totalPrice);
  426.         $product->getCheapestPrice()->getPrice()->first()->setGross($totalPrice);
  427.         $product->getCheapestPrice()->getPrice()->first()->setNet($totalPrice);
  428.         $product->getCalculatedPrices()->clear();
  429.         $product->setCheapestPrice(null);
  430.         $newCPContainer = new CheapestPriceContainer([]);
  431.         $product->setCheapestPriceContainer($newCPContainer);
  432.     }
  433.     /**
  434.      * @param array $articles
  435.      * @param int $shopInstance
  436.      * @param string $currency
  437.      * @param string $language
  438.      * @return
  439.      */
  440.     private function getArticleInfo(
  441.         array $articles,
  442.         int $shopInstance 1,
  443.         string $language 'DE'
  444.     ) {
  445.         $params = [
  446.             'customer' => $this->customerNumber,
  447.             'shop-instance' => $shopInstance,
  448.             'currency' => $this->getCurrencyISO()
  449.         ];
  450.         $buildRequestHelper = new BuildRequestHelper($params$articles$this->errorHandler);
  451.         /**
  452.          * @var string $request
  453.          */
  454.         $request $this->requestHandler->buildRequest($buildRequestHelperget_class($this));
  455.         $this->error $this->errorHandler->error($this->errorHandler::GENERAL_ERRORget_class($this),
  456.             "Request: " print_r($requesttrue));
  457.         $this->errorHandler->writeErrorLog($this->error);
  458.         if ($request !== '') {
  459.             /**
  460.              * @var string $result
  461.              */
  462.             $result $this->requestHandler->sendRequest($this->host$this->portself::PATH$request);
  463.         } else {
  464.             $this->error $this->errorHandler->error($this->errorHandler::UNKNOWN_REQUESTget_class($this),
  465.                 'Fehler im Aufbau des Request');
  466.             $this->errorHandler->writeErrorLog($this->error);
  467.             return;
  468.         }
  469.         /**
  470.          * @var array $resultArray
  471.          */
  472.         $resultArray $this->requestHandler->parseResult($result);
  473.         if ($resultArray['head']['status'] == 'NOK') {
  474.             $this->error $this->errorHandler->error($this->errorHandler::SAP_RESPONSE_ERRORget_class($this),
  475.                 'SAP Status Fehler. - ' print_r($resultArraytrue));
  476.             $this->errorHandler->writeErrorLog($this->error);
  477.             // } else {
  478.             //  $this->error = $this->errorHandler->error($this->errorHandler::WRONG_ARTICLE_ERROR, get_class($this), 'LivePrice-Response after success. - ' . print_r($resultArray, true));
  479.             //  $this->errorHandler->writeErrorLog($this->error);
  480.         }
  481.         return $resultArray;
  482.     }
  483.     /**
  484.      * @return bool
  485.      */
  486.     private function checkConfig(): bool
  487.     {
  488.         if ($this->foundationService->getConfigStatus()) {
  489.             $this->host $this->foundationService->getHost();
  490.             $this->port $this->foundationService->getPort();
  491.             return true;
  492.         }
  493.         $this->error $this->errorHandler->error($this->errorHandler::CONFIG_NOT_VALIDget_class($this),
  494.             'Konnte die Konfiguration nicht ermitteln');
  495.         $this->errorHandler->writeErrorLog($this->error);
  496.         return false;
  497.     }
  498.     /**
  499.      * @param string $productID
  500.      * @return ProductEntity
  501.      */
  502.     public function getProduct(string $productID, array $associations null): ProductEntity
  503.     {
  504.         /**
  505.          * @var Criteria $criteria
  506.          */
  507.         $criteria = new Criteria([$productID]);
  508.         if ($associations !== null) {
  509.             foreach ($associations as $association) {
  510.                 $criteria->addAssociation($association);
  511.             }
  512.         }
  513.         /**
  514.          * @var EntityCollection $products
  515.          */
  516.         $products $this->productRepository->search($criteria,
  517.             \Shopware\Core\Framework\Context::createDefaultContext());
  518.         /**
  519.          * @var array $productList
  520.          */
  521.         $productList $products->getElements();
  522.         /**
  523.          * @var ProductEntity $product
  524.          */
  525.         $product $productList[$productID];
  526.         return $product;
  527.     }
  528.     /**
  529.      * fts - Retrieve currency iso code from saleschannel context
  530.      * @return string
  531.      */
  532.     function getCurrencyISO(): string
  533.     {
  534.         return $this->event?->getSalesChannelContext()?->getCurrency()->getIsoCode() ?? "EUR";
  535.     }
  536.     /**
  537.      * If the current currency is not EUR, then the default threshold (250€)
  538.      * will be converted to the appropriate currency using the currency factor.
  539.      * @return int
  540.      */
  541.     private function calculateShippingThreshold(SalesChannelContext $context): int
  542.     {
  543.         if ($context->getCurrency()->getIsoCode() === "PLN") {
  544.             return OrderSimulateSubscriber::ZLOTY_THRESHOLD;
  545.         } else {
  546.             if ($context->getCurrency()->getIsoCode() === "GBP") {
  547.                 return OrderSimulateSubscriber::POUND_THRESHOLD;
  548.             } else {
  549.                 return OrderSimulateSubscriber::EUR_THRESHOLD;
  550.             }
  551.         }
  552.     }
  553.     /**
  554.      * Update the calculated unit price. Unit price * minPurchase
  555.      * @param SalesChannelProductEntity[] $products
  556.      * @return void
  557.      */
  558.     private function multiplyByPurchaseUnit(array $products): void
  559.     {
  560.         foreach ($products as $product) {
  561.             if (($unitPrice $product?->getCalculatedPrice()?->getUnitPrice()) && $unitPrice 0) {
  562.                 $unitPrice *= $product->getMinPurchase();
  563.                 $taxCollection = new CalculatedTaxCollection();
  564.                 $taxCollection->add(new CalculatedTax(00$unitPrice));
  565.                 $ruleCollection = new TaxRuleCollection();
  566.                 $ruleCollection->add(new TaxRule(00));
  567.                 $calculatedPrice = new CalculatedPrice($unitPrice$unitPrice$taxCollection$ruleCollection);
  568.                 $product->setCalculatedPrice($calculatedPrice);
  569.             }
  570.         }
  571.     }
  572. }