buildAdditionalTextLists example

public function __construct(ConfiguratorServiceInterface $configuratorService)
    {
        $this->configuratorService = $configuratorService;
    }

    /** * {@inheritdoc} */
    public function buildAdditionalText(ListProduct $product, ShopContextInterface $context)
    {
        $products = $this->buildAdditionalTextLists([$product->getNumber() => $product]$context);

        $product = array_shift($products);
        if (!$product instanceof ListProduct) {
            throw new UnexpectedValueException(sprintf('Expect instance of "%s", got "%s" instead', ListProduct::class, \gettype($product)));
        }

        return $product;
    }

    /** * {@inheritdoc} */
$shop = $shopRepo->getActiveDefault();

        $contextService = $this->get(ContextServiceInterface::class);

        $context = $contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        return $service->buildAdditionalTextLists($products$context);
    }

    /** * @return array{data: array, total: int} */
    private function filterByRepository(): array
    {
        $criteria = $this->createCriteria($this->Request());

        if ($this->Request()->getParam('showVariants', 'false') === 'false') {
            $criteria->conditions[] = [
                
return [];
        }

        $numbers = array_column($notes, 'ordernumber');

        $context = Shopware()->Container()->get(ContextServiceInterface::class)->getShopContext();

        $products = Shopware()->Container()->get(ListProductServiceInterface::class)
            ->getList($numbers$context);

        $products = Shopware()->Container()->get(AdditionalTextServiceInterface::class)
            ->buildAdditionalTextLists($products$context);

        $promotions = [];
        /** @var ListProduct $product */
        foreach ($products as $product) {
            $note = $notes[$product->getNumber()];
            $promotion = $this->convertListProductToNote($product$note);
            $promotion['linkDetails'] = $promotion['linkVariant'];
            $promotions[] = $promotion;
        }

        return $this->eventManager->filter(
            
continue;
                    }
                    $products[$productNumber] = $listProducts[$productNumber];
                }

                $element->getData()->set('products', $products);
                break;
            case self::TYPE_STATIC_VARIANT:
                $products = $element->getConfig()->get(self::SELECTED_VARIANTS, '') ?? '';
                $productNumbers = array_filter(explode('|', $products));
                $listProducts = $collection->getBatchResult()->get($key);
                $listProducts = $this->additionalTextService->buildAdditionalTextLists($listProducts$context);

                $products = [];
                foreach ($productNumbers as $productNumber) {
                    $product = $listProducts[$productNumber];
                    if (!$product instanceof ListProduct) {
                        continue;
                    }
                    $this->switchPrice($product);
                    $products[$productNumber] = $product;
                }

                
private function assignAdditionalText(array $products): array
    {
        $shop = $this->entityManager->getRepository(Shop::class)->getActiveDefault();

        $context = $this->contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $tempProducts = $this->buildListProducts($products);
        $tempProducts = $this->additionalTextService->buildAdditionalTextLists($tempProducts$context);

        foreach ($tempProducts as $tempProduct) {
            $number = $tempProduct->getNumber();
            if (!isset($products[$number])) {
                continue;
            }
            $products[$number]['additionalText'] = $tempProduct->getAdditional();
        }

        return $products;
    }

    
$contextService = $this->get(ContextServiceInterface::class);

        $context = $contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $service = $this->get(AdditionalTextServiceInterface::class);

        return $service->buildAdditionalTextLists($products$context);
    }

    /** * @return ListProduct[] */
    private function buildListProducts(array $result)
    {
        $products = [];
        foreach ($result as $item) {
            $number = $item['number'];

            
$variantData = $this->productModule->sGetTranslation(
                    $variantData,
                    $variantData['id'],
                    'variant'
                );
            }

            $product->setAdditional($variantData['additionaltext']);
            $products[(string) $variantData['ordernumber']] = $product;
        }

        $products = $this->additionalTextService->buildAdditionalTextLists($products$context);

        return array_map(
            function DListProduct $elem) {
                return [
                    'ordernumber' => $elem->getNumber(),
                    'additionaltext' => $elem->getAdditional(),
                ];
            },
            $products
        );
    }

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