replacePayload example


        foreach ($operations as $operation) {
            if ($operation->getAction() === SyncOperation::ACTION_DELETE && $operation->hasCriteria()) {
                $this->handleCriteriaDelete($operation$context);

                continue;
            }

            if ($operation->getAction() === SyncOperation::ACTION_UPSERT) {
                $resolved = $this->syncFkResolver->resolve($operation->getEntity()$operation->getPayload());

                $operation->replacePayload($resolved);
            }
        }
    }

    private function handleCriteriaDelete(SyncOperation $operation, Context $context): void
    {
        $definition = $this->registry->getByEntityName($operation->getEntity());

        if (!$definition instanceof MappingEntityDefinition) {
            throw ApiException::invalidSyncCriteriaException($operation->getKey());
        }

        
public function add(iterable $lineItems, CartDataCollection $data, SalesChannelContext $context): void
    {
        foreach ($lineItems as $lineItem) {
            $product = $data->get(
                $this->getDataKey($lineItem->getReferencedId())
            );

            if (!($product instanceof SalesChannelProductEntity)) {
                continue;
            }

            $lineItem->replacePayload([
                'features' => $this->buildFeatures($data$lineItem$product),
            ]);
        }
    }

    private function buildFeatures(CartDataCollection $data, LineItem $lineItem, SalesChannelProductEntity $product): array
    {
        $features = [];
        $featureSet = $product->getFeatureSet();

        if ($featureSet === null) {
            
'taxId' => $product->getTaxId(),
            'tagIds' => $product->getTagIds(),
            'categoryIds' => $product->getCategoryTree(),
            'propertyIds' => $product->getPropertyIds(),
            'optionIds' => $product->getOptionIds(),
            'options' => $product->getVariation(),
            'streamIds' => $product->getStreamIds(),
            'parentId' => $product->getParentId(),
            'stock' => $product->getStock(),
        ];

        $lineItem->replacePayload($payload['purchasePrices' => true]);
    }

    private function getPriceDefinition(SalesChannelProductEntity $product, SalesChannelContext $context, int $quantity): QuantityPriceDefinition
    {
        $this->priceCalculator->calculate([$product]$context);

        if ($product->getCalculatedPrices()->count() === 0) {
            return $this->buildPriceDefinition($product->getCalculatedPrice()$quantity);
        }

        // keep loop reference to $price variable to get last quantity price in case of "null"

        $match = $this->createLineItemTagRule([Uuid::randomHex()], Rule::OPERATOR_NEQ)->match(
            new LineItemScope($this->createLineItem()$this->createMock(SalesChannelContext::class))
        );

        static::assertTrue($match);
    }

    public function testLineItemMatchWithMatchingTags(): void
    {
        $tagIds = [Uuid::randomHex(), Uuid::randomHex(), Uuid::randomHex()];
        $lineItem = $this->createLineItem()->replacePayload(['tagIds' => $tagIds]);

        $match = $this->createLineItemTagRule($tagIds)->match(
            new LineItemScope($lineItem$this->createMock(SalesChannelContext::class))
        );

        static::assertTrue($match);
    }

    public function testLineItemMatchWithPartialMatchingTags(): void
    {
        $tagIds = [Uuid::randomHex(), Uuid::randomHex(), Uuid::randomHex()];
        
Home | Imprint | This part of the site doesn't use cookies.