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

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