getDataKey example

$items = array_column($lineItems, 'item');

            // find products in original cart which requires data from gateway             $ids = $this->getNotCompleted($data$items$context);

            if (!empty($ids)) {
                // fetch missing data over gateway                 $products = $this->productGateway->get($ids$context);

                // add products to data collection                 foreach ($products as $product) {
                    $data->set($this->getDataKey($product->getId())$product);
                }

                $hash = $this->generator->getSalesChannelContextHash($context[RuleAreas::PRODUCT_AREA]);

                // refresh data timestamp to prevent unnecessary gateway calls                 foreach ($items as $lineItem) {
                    if (!\in_array($lineItem->getReferencedId()$products->getIds(), true)) {
                        $lineItem->setDataTimestamp(null);

                        continue;
                    }
                    


    public function prepare(iterable $lineItems, CartDataCollection $data, SalesChannelContext $context): void
    {
        $this->loadCustomFields($lineItems$data$context);
    }

    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),
            ]);
        }
    }

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