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

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.  * @method Price[]    getIterator()
  7.  * @method Price[]    getElements()
  8.  * @method Price|null get(string $currencyId)
  9.  * @method Price|null first()
  10.  * @method Price|null last()
  11.  */
  12. class PriceCollection extends Collection
  13. {
  14.     public function add($element): void
  15.     {
  16.         $this->set($element->getCurrencyId(), $element);
  17.     }
  18.     public function set($key$element): void
  19.     {
  20.         parent::set($element->getCurrencyId(), $element);
  21.     }
  22.     public function getCurrencyPrice(string $currencyIdbool $fallback true): ?Price
  23.     {
  24.         $price $this->get($currencyId);
  25.         if ($price) {
  26.             return $price;
  27.         }
  28.         if ($currencyId === Defaults::CURRENCY) {
  29.             return null;
  30.         }
  31.         if (!$fallback) {
  32.             return null;
  33.         }
  34.         return $this->get(Defaults::CURRENCY);
  35.     }
  36.     public function getApiAlias(): string
  37.     {
  38.         return 'price_collection';
  39.     }
  40.     protected function getExpectedClass(): ?string
  41.     {
  42.         return Price::class;
  43.     }
  44. }