vendor/shopware/core/Content/Product/Aggregate/ProductPrice/ProductPriceCollection.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\Aggregate\ProductPrice;
  3. use Shopware\Core\Checkout\Cart\Price\Struct\CartPrice;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  6. /**
  7.  * @extends EntityCollection<ProductPriceEntity>
  8.  */
  9. class ProductPriceCollection extends EntityCollection
  10. {
  11.     public function getApiAlias(): string
  12.     {
  13.         return 'product_price_collection';
  14.     }
  15.     public function filterByRuleId(string $ruleId): self
  16.     {
  17.         return $this->filter(function (ProductPriceEntity $price) use ($ruleId) {
  18.             return $ruleId === $price->getRuleId();
  19.         });
  20.     }
  21.     public function sortByQuantity(): void
  22.     {
  23.         $this->sort(function (ProductPriceEntity $aProductPriceEntity $b) {
  24.             return $a->getQuantityStart() <=> $b->getQuantityStart();
  25.         });
  26.     }
  27.     public function sortByPrice(Context $context): void
  28.     {
  29.         $this->sort(function (ProductPriceEntity $aProductPriceEntity $b) use ($context) {
  30.             $a $a->getPrice()->first();
  31.             $b $b->getPrice()->first();
  32.             if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
  33.                 return ($a $a->getGross() : 0) <=> ($b $b->getGross() : 0);
  34.             }
  35.             return ($a $a->getNet() : 0) <=> ($b $b->getNet() : 0);
  36.         });
  37.     }
  38.     protected function getExpectedClass(): string
  39.     {
  40.         return ProductPriceEntity::class;
  41.     }
  42. }