setProduct example

$product->getMedia()->getElements()
            )));
        }

        if ($category = $product->getSeoCategory()) {
            $request->request->set('navigationId', $category->getId());
        }

        $page = $this->genericLoader->load($request$context);
        $page = ProductPage::createFrom($page);

        $page->setProduct($product);
        $page->setConfiguratorSettings($result->getConfigurator() ?? new PropertyGroupCollection());
        $page->setNavigationId($product->getId());

        if (!Feature::isActive('v6.6.0.0')) {
            $this->loadDefaultAdditions($product$page$request$context);
        } elseif ($cmsPage = $product->getCmsPage()) {
            $page->setCmsPage($cmsPage);
        }

        $this->loadOptions($page);
        $this->loadMetaData($page);

        
if ($productConfig->isMapped() && $resolverContext instanceof EntityResolverContext) {
            $product = $this->resolveEntityValue($resolverContext->getEntity()$productConfig->getStringValue());
        }

        if ($productConfig->isStatic()) {
            $product = $this->getSlotProduct($slot$result$productConfig->getStringValue());
        }

        /** @var SalesChannelProductEntity|null $product */
        if ($product !== null) {
            $buyBox->setProduct($product);
            $buyBox->setProductId($product->getId());
            $buyBox->setConfiguratorSettings($this->configuratorLoader->load($product$resolverContext->getSalesChannelContext()));
            $buyBox->setTotalReviews($this->getReviewsCount($product$resolverContext->getSalesChannelContext()));
        }
    }

    private function getReviewsCount(SalesChannelProductEntity $product, SalesChannelContext $context): int
    {
        $reviewCriteria = $this->createReviewCriteria($context$product->getParentId() ?? $product->getId());

        $aggregation = $this->repository->aggregate($reviewCriteria$context->getContext())->get('review-count');

        
$this->seoUrlPlaceholderHandlerMock,
            $this->productReviewLoaderMock,
            $this->systemConfigServiceMock
        );
    }

    public function testIndexCmsPage(): void
    {
        $this->productEntity = new SalesChannelProductEntity();
        $this->productEntity->setId('test');
        $this->productPage = new ProductPage();
        $this->productPage->setProduct($this->productEntity);
        $this->productPage->setCmsPage(new CmsPageEntity());

        $this->productPageLoaderMock->method('load')->willReturn($this->productPage);

        $response = $this->controller->index($this->createMock(SalesChannelContext::class)new Request());

        static::assertEquals(Response::HTTP_OK, $response->getStatusCode());
        static::assertInstanceOf(ProductPage::class$this->controller->renderStorefrontParameters['page']);
        static::assertEquals('test', $this->controller->renderStorefrontParameters['page']->getProduct()->getId());
        static::assertEquals('@Storefront/storefront/page/content/product-detail.html.twig', $this->controller->renderStorefrontView);
    }

    
if ($productConfig->isMapped() && $resolverContext instanceof EntityResolverContext) {
            $product = $this->resolveEntityValue($resolverContext->getEntity()$productConfig->getStringValue());
        }

        if ($productConfig->isStatic()) {
            $product = $this->getSlotProduct($slot$result$productConfig->getStringValue());
        }

        /** @var SalesChannelProductEntity|null $product */
        if ($product !== null) {
            $data->setProduct($product);
            $data->setReviews($this->loadProductReviews($product$request$resolverContext->getSalesChannelContext()));
        }
    }

    private function loadProductReviews(SalesChannelProductEntity $product, Request $request, SalesChannelContext $context): ProductReviewResult
    {
        $reviewCriteria = $this->createReviewCriteria($request$context);
        $reviews = $this->productReviewRoute
            ->load($product->getParentId() ?? $product->getId()$request$context$reviewCriteria)
            ->getResult();

        
throw new CustomValidationException(sprintf('Product with id %d is not assigned to the category', $sorting['product_id']));
            }

            $sortingObj = new ManualSorting();
            $sortingObj->setCategory($category);

            $product = $this->getManager()->find(Product::class$sorting['product_id']);
            if (!$product instanceof Product) {
                throw new ModelNotFoundException(Product::class$sorting['product_id']);
            }

            $sortingObj->setProduct($product);
            $sortingObj->setPosition((int) $sorting['position']);

            $collection[] = $sortingObj;
        }

        $category->setManualSorting(null);
        $this->getManager()->flush($category);
        $category->setManualSorting($collection);

        unset($data['manualSorting']);

        
$slot->setData($productBox);

        $productConfig = $slot->getFieldConfig()->get('product');
        if ($productConfig === null || $productConfig->getValue() === null) {
            return;
        }

        if ($resolverContext instanceof EntityResolverContext && $productConfig->isMapped()) {
            /** @var SalesChannelProductEntity $product */
            $product = $this->resolveEntityValue($resolverContext->getEntity()$productConfig->getStringValue());

            $productBox->setProduct($product);
            $productBox->setProductId($product->getId());
        }

        if ($productConfig->isStatic()) {
            $this->resolveProductFromRemote($slot$productBox$result$productConfig->getStringValue()$resolverContext->getSalesChannelContext());
        }
    }

    private function resolveProductFromRemote(
        CmsSlotEntity $slot,
        ProductBoxStruct $productBox,
        
Home | Imprint | This part of the site doesn't use cookies.