custom/plugins/AcrisTaxCS/src/Core/Checkout/Cart/TaxRuleLoader.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\Tax\Core\Checkout\Cart;
  3. use Shopware\Core\Checkout\Cart\CachedRuleLoader;
  4. use Shopware\Core\Checkout\Cart\Cart;
  5. use Shopware\Core\Content\Rule\RuleCollection;
  6. use Shopware\Core\Framework\Context;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
  9. class TaxRuleLoader
  10. {
  11.     /**
  12.      * @var RuleCollection|null
  13.      */
  14.     private $rules;
  15.     /**
  16.      * @var TagAwareAdapterInterface
  17.      */
  18.     private $cache;
  19.     /**
  20.      * @var CachedRuleLoader
  21.      */
  22.     private $ruleLoader;
  23.     public function __construct(
  24.         TagAwareAdapterInterface $cache,
  25.         CachedRuleLoader $ruleLoader
  26.     ) {
  27.         $this->cache $cache;
  28.         $this->ruleLoader $ruleLoader;
  29.         $this->rules null;
  30.     }
  31.     public function loadRulesIdsForContext(SalesChannelContext $salesChannelContext): array
  32.     {
  33.         $cart = new Cart($salesChannelContext->getSalesChannel()->getTypeId(), $salesChannelContext->getToken());
  34.         return $this->loadRules($salesChannelContext->getContext())->filterMatchingRules($cart$salesChannelContext)->getIds();
  35.     }
  36.     private function loadRules(Context $context): RuleCollection
  37.     {
  38.         if ($this->rules !== null) {
  39.             return $this->rules;
  40.         }
  41.         return $this->rules $this->ruleLoader->load($context);
  42.     }
  43. }