vendor/shopware/core/Framework/DataAbstractionLayer/Pricing/PriceCollection.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Pricing;
  3. use Shopware\Core\Defaults;
  4. use Shopware\Core\Framework\Struct\Collection;
  5. /**
  6.  * @extends Collection<Price>
  7.  */
  8. class PriceCollection extends Collection
  9. {
  10.     public function add($element): void
  11.     {
  12.         $this->set($element->getCurrencyId(), $element);
  13.     }
  14.     public function set($key$element): void
  15.     {
  16.         parent::set($element->getCurrencyId(), $element);
  17.     }
  18.     public function getCurrencyPrice(string $currencyIdbool $fallback true): ?Price
  19.     {
  20.         $price $this->get($currencyId);
  21.         if ($price) {
  22.             return $price;
  23.         }
  24.         if ($currencyId === Defaults::CURRENCY) {
  25.             return null;
  26.         }
  27.         if (!$fallback) {
  28.             return null;
  29.         }
  30.         return $this->get(Defaults::CURRENCY);
  31.     }
  32.     public function getApiAlias(): string
  33.     {
  34.         return 'price_collection';
  35.     }
  36.     protected function getExpectedClass(): ?string
  37.     {
  38.         return Price::class;
  39.     }
  40. }