PriceFacade example

 {
    }

    /** * `getPrice()` returns the calculated price of the line-item. * * @return PriceFacade|null Returns the price of the line-item as a `PriceFacade` or null if the line-item has no calculated price. */
    public function getPrice(): ?PriceFacade
    {
        if ($this->item->getPrice()) {
            return new PriceFacade($this->item, $this->item->getPrice()$this->priceStubs, $this->context);
        }

        return null;
    }

    /** * `take()` splits an existing line-item by a given quantity. * It removes the given quantity from the existing line-item and returns a new line-item with exactly that quantity. * * @param int $quantity The quantity that should be taken. * @param string|null $key Optional: The id of the new line-item. A random UUID will be used if none is provided. * * @return ItemFacade|null Returns the new line-item as an `ItemFacade` or null if taking is not possible because the line-item has no sufficient quantity. * * @example split-product/split-product.twig Take a quantity of 2 from an existing product line-item and add it to the cart again. */

        }
    }

    /** * @internal */
    public function getIterator(): \Traversable
    {
        return new \ArrayIterator(
            $this->prices->map(function DCalculatedPrice $price) {
                return new PriceFacade($this->product, $price$this->priceStubs, $this->context);
            })
        );
    }

    /** * The `count()` function returns the number of prices which are stored inside this collection. * * @return int Returns the number of prices which are stored inside this collection */
    public function count(): int
    {
        

class PriceFacadeTest extends TestCase
{
    public function testLineItemsGetUpdatePriceDefinition(): void
    {
        $item = new LineItem('test', 'test', 'temp');

        $original = new CalculatedPrice(1, 1, new CalculatedTaxCollection()new TaxRuleCollection());
        $price = new PriceFacade($item$original$this->createMock(ScriptPriceStubs::class)$this->createMock(SalesChannelContext::class));

        $price->change(new PriceCollection([
            new Price(Defaults::CURRENCY, 2, 2, false),
        ]));

        static::assertInstanceOf(QuantityPriceDefinition::class$item->getPriceDefinition());
        static::assertEquals(2, $item->getPriceDefinition()->getPrice());
        static::assertNull($item->getPrice());
    }

    public function testChangesAreAppliedDirectlyForEntities(): void
    {
 : null;
    }

    /** * The `calculatedPrice` property returns the price of the product. The price object will * be wrapped into a `PriceFacade` object which allows to manipulate the price. * * @return PriceFacade|null Returns a `PriceFacade` if the product has a price, otherwise `null` */
    public function calculatedPrice(): ?PriceFacade
    {
        return $this->product->get('calculatedPrice') ? new PriceFacade(
            $this->product,
            $this->product->get('calculatedPrice'),
            $this->priceStubs,
            $this->context
        ) : null;
    }

    /** * The `calculatedPrices` property returns the price of the product. The price object will * be wrapped into a `PriceCollectionFacade` object which allows to manipulate the collection. * * @return PriceCollectionFacade|null Returns a `PriceCollectionFacade` if the product has graduated prices, otherwise `null` */
public function testChangeWithPriceFacade(): void
    {
        $ids = new IdsCollection([
            'default' => Defaults::CURRENCY,
            'usd' => Uuid::randomHex(),
        ]);

        $price = $this->rampUpPriceFacade($ids, 'default', CartPrice::TAX_STATE_GROSS);

        $price->change(
            new PriceFacade(
                new Entity(),
                new CalculatedPrice(5, 5, new CalculatedTaxCollection()new TaxRuleCollection()),
                $this->createMock(ScriptPriceStubs::class),
                $this->createMock(SalesChannelContext::class)
            )
        );

        static::assertEquals(5, $price->getUnit());
    }

    public function testChangeWithNullFacade(): void
    {
Home | Imprint | This part of the site doesn't use cookies.