vendor/shopware/core/Checkout/Promotion/Cart/Extension/CartExtension.php line 7

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Promotion\Cart\Extension;
  3. use Shopware\Core\Framework\Struct\Struct;
  4. class CartExtension extends Struct
  5. {
  6.     /**
  7.      * this is the key that should be
  8.      * used for the cart extension
  9.      */
  10.     public const KEY 'cart-promotions';
  11.     /**
  12.      * @var array<string>
  13.      */
  14.     protected $addedCodes = [];
  15.     /**
  16.      * @var array<string>
  17.      */
  18.     protected $blockedPromotionIds = [];
  19.     public function addCode(string $code): void
  20.     {
  21.         if (empty($code)) {
  22.             return;
  23.         }
  24.         if (!\in_array($code$this->addedCodestrue)) {
  25.             $this->addedCodes[] = $code;
  26.         }
  27.     }
  28.     public function hasCode(string $code): bool
  29.     {
  30.         return \in_array($code$this->addedCodestrue);
  31.     }
  32.     public function removeCode(string $code): void
  33.     {
  34.         if (empty($code)) {
  35.             return;
  36.         }
  37.         if (\in_array($code$this->addedCodestrue)) {
  38.             $newList = [];
  39.             foreach ($this->addedCodes as $existingCode) {
  40.                 if ($existingCode !== $code) {
  41.                     $newList[] = $existingCode;
  42.                 }
  43.             }
  44.             $this->addedCodes $newList;
  45.         }
  46.     }
  47.     /**
  48.      * @return array<string>
  49.      */
  50.     public function getCodes(): array
  51.     {
  52.         return $this->addedCodes;
  53.     }
  54.     public function blockPromotion(string $id): void
  55.     {
  56.         if (empty($id)) {
  57.             return;
  58.         }
  59.         if (!\in_array($id$this->blockedPromotionIdstrue)) {
  60.             $this->blockedPromotionIds[] = $id;
  61.         }
  62.     }
  63.     public function isPromotionBlocked(string $id): bool
  64.     {
  65.         return \in_array($id$this->blockedPromotionIdstrue);
  66.     }
  67. }