getRuleId example

$products = $this->repository->search($criteria$context);
        static::assertTrue($products->has($id));

        /** @var ProductEntity $product */
        $product = $products->get($id);

        static::assertInstanceOf(ProductPriceCollection::class$product->getPrices());
        static::assertCount(1, $product->getPrices());

        /** @var ProductPriceEntity $price */
        $price = $product->getPrices()->first();
        static::assertSame($ruleA$price->getRuleId());

        $data = [
            'id' => $id,
            'prices' => [
                // update existing rule with new price and quantity end to add another graduation                 [
                    'id' => $id,
                    'quantityEnd' => 20,
                    'price' => [
                        ['currencyId' => Defaults::CURRENCY, 'gross' => 5000, 'net' => 4000, 'linked' => false],
                    ],
                ],
static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        /** @var ProductEntity $product */
        $product = $this->productRepository->search((new Criteria([$productId]))->addAssociation('prices')$context)->first();

        static::assertInstanceOf(ProductPriceCollection::class$product->getPrices());
        static::assertEquals(2, $product->getPrices()->count());
        $firstPrice = $product->getPrices()->first();

        static::assertInstanceOf(ProductPriceEntity::class$firstPrice);
        static::assertEquals($ruleId$firstPrice->getRuleId());
        static::assertInstanceOf(Price::class$firstPrice->getPrice()->first());
        static::assertEquals(7.89, $firstPrice->getPrice()->first()->getNet());
        static::assertEquals(9.39, $firstPrice->getPrice()->first()->getGross());
        static::assertEquals(1, $firstPrice->getQuantityStart());
        static::assertEquals(10, $firstPrice->getQuantityEnd());
        $lastPrice = $product->getPrices()->last();
        static::assertInstanceOf(ProductPriceEntity::class$lastPrice);
        static::assertEquals($ruleId$lastPrice->getRuleId());
        static::assertInstanceOf(Price::class$lastPrice->getPrice()->first());
        static::assertEquals(5.67, $lastPrice->getPrice()->first()->getNet());
        static::assertEquals(6.75, $lastPrice->getPrice()->first()->getGross());
        

            ]
        ));
        $priceWithRule->setRuleId(Uuid::randomHex());

        $shippingMethod->setPrices(new ShippingMethodPriceCollection([$priceWithoutRule$priceWithRule]));

        $context = $this->createMock(SalesChannelContext::class);
        $baseContext = Context::createDefaultContext();

        $context->expects(static::atLeastOnce())->method('getContext')->willReturn($baseContext);
        $context->expects(static::atLeastOnce())->method('getRuleIds')->willReturn([$priceWithRule->getRuleId()]);
        $context->expects(static::atLeastOnce())->method('getShippingMethod')->willReturn($shippingMethod);
        $context->method('getItemRounding')->willReturn(new CashRoundingConfig(2, 0.01, true));

        $lineItem = new LineItem(Uuid::randomHex(), 'product');
        $lineItem->setDeliveryInformation(
            new DeliveryInformation(
                10,
                12.0,
                false,
                null,
                $this->deliveryTime
            )

#[Package('inventory')] class ProductPriceCollection extends EntityCollection
{
    public function getApiAlias(): string
    {
        return 'product_price_collection';
    }

    public function filterByRuleId(string $ruleId): self
    {
        return $this->filter(fn (ProductPriceEntity $price) => $ruleId === $price->getRuleId());
    }

    public function sortByQuantity(): void
    {
        $this->sort(fn (ProductPriceEntity $a, ProductPriceEntity $b) => $a->getQuantityStart() <=> $b->getQuantityStart());
    }

    public function sortByPrice(Context $context): void
    {
        $this->sort(function DProductPriceEntity $a, ProductPriceEntity $b) use ($context) {
            $a = $a->getPrice()->first();
            
/** @var OrderDeliveryEntity $delivery */
        $delivery = $deliveries->first();

        /** @var ShippingMethodEntity $shippingMethod */
        $shippingMethod = $delivery->getShippingMethod();

        /** @var ShippingMethodPriceEntity $firstPriceRule */
        $firstPriceRule = $shippingMethod->getPrices()->first();
        /** @var ShippingMethodPriceEntity $secondPriceRule */
        $secondPriceRule = $shippingMethod->getPrices()->last();

        static::assertSame($firstPriceRule->getRuleId()$secondPriceRule->getRuleId());
        static::assertGreaterThan($firstPriceRule->getQuantityStart()$firstPriceRule->getQuantityEnd());
        static::assertGreaterThan($firstPriceRule->getQuantityEnd()$secondPriceRule->getQuantityStart());
        static::assertGreaterThan($secondPriceRule->getQuantityStart()$secondPriceRule->getQuantityEnd());
    }

    public function testIfCorrectConditionIsUsedCalculationByLineItemCount(): void
    {
        $priceRuleId = Uuid::randomHex();
        $shippingMethodId = Uuid::randomHex();
        $shippingMethod = $this->addSecondShippingMethodPriceRule($priceRuleId$shippingMethodId);
        $this->salesChannelContext->setRuleIds(array_merge($this->salesChannelContext->getRuleIds()[$priceRuleId]));

        
$products = $this->repository->search($criteria$context);
        static::assertTrue($products->has($id));

        /** @var ProductEntity $product */
        $product = $products->get($id);

        static::assertCount(1, $product->getPrices());

        /** @var ProductPriceEntity $price */
        $price = $product->getPrices()->first();
        static::assertEquals($ruleA$price->getRuleId());

        $data = [
            'id' => $id,
            'prices' => [
                // update existing rule with new price and quantity end to add another graduation                 [
                    'id' => $id,
                    'quantityEnd' => 20,
                    'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 5000, 'net' => 4000, 'linked' => false]],
                ],

                
'ruleId' => null,
                    'actionName' => null,
                ]);

                $isRoot = true;

                for ($s = 0; $s < $sequenceCount; ++$s) {
                    $parent = $sequence;

                    $falseCase = null;

                    if ($parent->getRuleId()) {
                        $generateFalseCase = $this->faker->boolean();

                        if ($generateFalseCase) {
                            $falseCase = $this->buildRandomSequence($parent, false);

                            $sequences->add($falseCase);

                            $parent->setPosition($parent->getPosition() + 1);
                        }
                    }

                    
Home | Imprint | This part of the site doesn't use cookies.