diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bfcec5..8aea875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ CHANGELOG for Shopware PWA =================== +### Unreleased + +**Added** + +* Field `configurator` to product detail page responses from `store-api/v{version}/pwa/page` endpoint. + +**Removed** + +* Field `aggregations` from product detail page responses from `store-api/v{version}/pwa/page` endpoint. + ### v0.2.0 **Added** diff --git a/src/Pwa/PageLoader/ProductPageLoader.php b/src/Pwa/PageLoader/ProductPageLoader.php index 7b8cefd..426f3b1 100644 --- a/src/Pwa/PageLoader/ProductPageLoader.php +++ b/src/Pwa/PageLoader/ProductPageLoader.php @@ -3,6 +3,7 @@ namespace SwagShopwarePwa\Pwa\PageLoader; use Shopware\Core\Content\Product\Exception\ProductNumberNotFoundException; +use Shopware\Core\Content\Product\SalesChannel\Detail\ProductDetailRoute; use Shopware\Core\Content\Product\SalesChannel\ProductAvailableFilter; use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductDefinition; use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity; @@ -27,9 +28,9 @@ class ProductPageLoader implements PageLoaderInterface private const RESOURCE_TYPE = 'frontend.detail.page'; /** - * @var SalesChannelRepositoryInterface + * @var ProductDetailRoute */ - private $productRepository; + private $productRoute; /** * @var ProductPageResultHydrator @@ -52,13 +53,13 @@ public function getResourceType(): string } public function __construct( - SalesChannelRepositoryInterface $productRepository, + ProductDetailRoute $productDetailRoute, ProductPageResultHydrator $resultHydrator, RequestCriteriaBuilder $requestCriteriaBuilder, SalesChannelProductDefinition $productDefinition ) { - $this->productRepository = $productRepository; + $this->productRoute = $productDetailRoute; $this->resultHydrator = $resultHydrator; $this->requestCriteriaBuilder = $requestCriteriaBuilder; $this->productDefinition = $productDefinition; @@ -88,17 +89,13 @@ public function load(PageLoaderContext $pageLoaderContext): ProductPageResult new EqualsFilter('active', 1) ); - $searchResult = $this->productRepository->search($criteria, $pageLoaderContext->getContext()); - - if($searchResult->count() < 1) - { - throw new ProductNumberNotFoundException($pageLoaderContext->getResourceIdentifier()); - } - - /** @var SalesChannelProductEntity $product */ - $product = $searchResult->first(); - $aggregations = $searchResult->getAggregations(); + $result = $this->productRoute->load( + $pageLoaderContext->getResourceIdentifier(), + $pageLoaderContext->getRequest(), + $pageLoaderContext->getContext(), + $criteria + ); - return $this->resultHydrator->hydrate($pageLoaderContext, $product, $aggregations); + return $this->resultHydrator->hydrate($pageLoaderContext, $result->getProduct(), $result->getConfigurator()); } } diff --git a/src/Pwa/PageResult/Product/ProductPageResult.php b/src/Pwa/PageResult/Product/ProductPageResult.php index 2ad4d5d..fde5ac2 100644 --- a/src/Pwa/PageResult/Product/ProductPageResult.php +++ b/src/Pwa/PageResult/Product/ProductPageResult.php @@ -3,6 +3,7 @@ namespace SwagShopwarePwa\Pwa\PageResult\Product; use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity; +use Shopware\Core\Content\Property\PropertyGroupCollection; use Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\AggregationResultCollection; use SwagShopwarePwa\Pwa\PageResult\AbstractPageResult; @@ -14,9 +15,9 @@ class ProductPageResult extends AbstractPageResult protected $product; /** - * @var AggregationResultCollection + * @var PropertyGroupCollection */ - protected $aggregations; + protected $configurator; /** * @return SalesChannelProductEntity @@ -35,16 +36,18 @@ public function setProduct(SalesChannelProductEntity $product) } /** - * @param AggregationResultCollection $aggregations + * @return PropertyGroupCollection */ - public function setAggregations(AggregationResultCollection $aggregations) { - $this->aggregations = $aggregations; + public function getConfigurator(): PropertyGroupCollection + { + return $this->configurator; } /** - * @return AggregationResultCollection + * @param PropertyGroupCollection $configurator */ - public function getAggregations() { - return $this->aggregations; + public function setConfigurator(PropertyGroupCollection $configurator) + { + $this->configurator = $configurator; } } diff --git a/src/Pwa/PageResult/Product/ProductPageResultHydrator.php b/src/Pwa/PageResult/Product/ProductPageResultHydrator.php index 89aae78..8932ec5 100644 --- a/src/Pwa/PageResult/Product/ProductPageResultHydrator.php +++ b/src/Pwa/PageResult/Product/ProductPageResultHydrator.php @@ -3,7 +3,7 @@ namespace SwagShopwarePwa\Pwa\PageResult\Product; use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity; -use Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\AggregationResultCollection; +use Shopware\Core\Content\Property\PropertyGroupCollection; use SwagShopwarePwa\Pwa\PageLoader\Context\PageLoaderContext; /** @@ -17,13 +17,13 @@ */ class ProductPageResultHydrator { - public function hydrate(PageLoaderContext $pageLoaderContext, SalesChannelProductEntity $product, AggregationResultCollection $aggregations): ProductPageResult + public function hydrate(PageLoaderContext $pageLoaderContext, SalesChannelProductEntity $product, ?PropertyGroupCollection $configurator): ProductPageResult { $pageResult = new ProductPageResult(); $pageResult->setProduct($product); - $pageResult->setAggregations($aggregations); + $pageResult->setConfigurator($configurator); $pageResult->setResourceType($pageLoaderContext->getResourceType()); $pageResult->setResourceIdentifier($pageLoaderContext->getResourceIdentifier()); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 54e4094..09b645c 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -46,7 +46,7 @@ - +