vendor/shopware/core/Content/Product/SalesChannel/Price/AppScriptProductPriceCalculator.php line 32

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Price;
  3. use Shopware\Core\Checkout\Cart\Facade\ScriptPriceStubs;
  4. use Shopware\Core\Content\Product\Hook\Pricing\ProductPricingHook;
  5. use Shopware\Core\Content\Product\Hook\Pricing\ProductProxy;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Framework\Script\Execution\ScriptExecutor;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. #[Package('inventory')]
  10. class AppScriptProductPriceCalculator extends AbstractProductPriceCalculator
  11. {
  12.     /**
  13.      * @internal
  14.      */
  15.     public function __construct(
  16.         private readonly AbstractProductPriceCalculator $decorated,
  17.         private readonly ScriptExecutor $scriptExecutor,
  18.         private readonly ScriptPriceStubs $priceStubs
  19.     ) {
  20.     }
  21.     public function getDecorated(): AbstractProductPriceCalculator
  22.     {
  23.         return $this->decorated;
  24.     }
  25.     public function calculate(iterable $productsSalesChannelContext $context): void
  26.     {
  27.         $this->decorated->calculate($products$context);
  28.         $proxies = [];
  29.         foreach ($products as $product) {
  30.             $proxies[$product->get('id')] = new ProductProxy($product$context$this->priceStubs);
  31.         }
  32.         $this->scriptExecutor->execute(new ProductPricingHook($proxies$context));
  33.     }
  34. }