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

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