Skip to content

Commit

Permalink
Merge pull request #64 from elkmod/feature/added-configurator-removed…
Browse files Browse the repository at this point in the history
…-aggregations-detail

Added configurator options to product detail page
  • Loading branch information
elkmod authored Dec 17, 2020
2 parents 40d13ff + fcd42c4 commit 1832333
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
27 changes: 12 additions & 15 deletions src/Pwa/PageLoader/ProductPageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}
19 changes: 11 additions & 8 deletions src/Pwa/PageResult/Product/ProductPageResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,9 +15,9 @@ class ProductPageResult extends AbstractPageResult
protected $product;

/**
* @var AggregationResultCollection
* @var PropertyGroupCollection
*/
protected $aggregations;
protected $configurator;

/**
* @return SalesChannelProductEntity
Expand All @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/Pwa/PageResult/Product/ProductPageResultHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!-- Page loaders -->

<service id="SwagShopwarePwa\Pwa\PageLoader\ProductPageLoader">
<argument id="sales_channel.product.repository" type="service"/>
<argument id="Shopware\Core\Content\Product\SalesChannel\Detail\ProductDetailRoute" type="service"/>
<argument type="service" id="SwagShopwarePwa\Pwa\PageResult\Product\ProductPageResultHydrator"/>
<argument id="Shopware\Core\Framework\DataAbstractionLayer\Search\RequestCriteriaBuilder" type="service"/>
<argument id="Shopware\Core\Content\Product\SalesChannel\SalesChannelProductDefinition" type="service"/>
Expand Down

0 comments on commit 1832333

Please sign in to comment.