BaseProduct example



    /** * @return array */
    private function getProducts(QueryBuilder $query)
    {
        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $products = [];

        foreach ($data as $row) {
            $product = new BaseProduct(
                (int) $row['__product_id'],
                (int) $row['__variant_id'],
                $row['__variant_ordernumber']
            );

            $product->addAttribute('search', new Attribute($row));
            $products[$product->getNumber()] = $product;
        }

        return $products;
    }

    
/** * @param array[] $data * * @return \Shopware\Bundle\StoreFrontBundle\Struct\BaseProduct[] */
    private function createProducts(array $data): array
    {
        $products = [];
        foreach ($data['hits']['hits'] as $row) {
            $source = $row['_source'];

            $product = new BaseProduct(
                (int) $source['id'],
                (int) $source['variantId'],
                $source['number']
            );

            $product->addAttribute(
                'elastic_search',
                new Attribute(array_merge(
                    $row['_source'],
                    ['score' => $row['_score']]
                ))
            );
'variant.ordernumber as number',
            'variant.articleID as productId',
        ]);
        $query->from('s_articles_details', 'variant')
            ->where('variant.ordernumber IN(:numbers)')
            ->setParameter(':numbers', $numbers, Connection::PARAM_STR_ARRAY);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        $products = [];
        foreach ($data as $row) {
            $product = new BaseProduct(
                (int) $row['productId'],
                (int) $row['variantId'],
                $row['number']
            );
            $products[$product->getNumber()] = $product;
        }

        return $products;
    }
}
Criteria $criteria,
        array $articles,
        ShopContextInterface $context,
        $categoryId = null
    ) {
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        $conditions = array_filter($conditionsfunction DVariantCondition $condition) {
            return $condition->expandVariants();
        });

        $products = array_map(function Darray $product) {
            return new BaseProduct($product['articleID']$product['articleDetailsID']$product['ordernumber']);
        }$articles);

        $configurations = [];
        if (!empty($conditions)) {
            $configurations = $this->configuratorService->getProductsConfigurations($products$context);
        }

        $urls = array_map(function D$product) use ($categoryId) {
            if ($categoryId !== null) {
                return $product['linkDetails'] . '&sCategory=' . (int) $categoryId;
            }

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