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

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