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

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