diff --git a/src/Model/Context/AddSearchCriteriaToContext.php b/src/Model/Context/AddSearchCriteriaToContext.php
index ebb07d2..71cf29e 100644
--- a/src/Model/Context/AddSearchCriteriaToContext.php
+++ b/src/Model/Context/AddSearchCriteriaToContext.php
@@ -25,9 +25,7 @@ class AddSearchCriteriaToContext implements ContextParametersProcessorInterface
public function execute(
ContextParametersInterface $contextParameters
) : ContextParametersInterface {
-
$contextParameters->addExtensionAttribute('search_criteria', null);
-
return $contextParameters;
}
}
diff --git a/src/Model/Resolver/Product/PriceRange.php b/src/Model/Resolver/Product/PriceRange.php
index e52f09c..4c56b28 100644
--- a/src/Model/Resolver/Product/PriceRange.php
+++ b/src/Model/Resolver/Product/PriceRange.php
@@ -9,6 +9,7 @@
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool as PriceProviderPool;
+use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Catalog\Model\Product;
@@ -68,7 +69,6 @@ public function resolve(
/** @var Product $product */
$product = $value['model'];
- // literally single line got removed here
$requestedFields = $info->getFieldSelection(10);
$returnArray = [];
diff --git a/src/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/PriceProcessor.php b/src/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/PriceProcessor.php
index f821f27..d628077 100644
--- a/src/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/PriceProcessor.php
+++ b/src/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/PriceProcessor.php
@@ -19,7 +19,6 @@
class PriceProcessor implements CollectionProcessorInterface
{
const PRICE_FIELD = 'price_range';
- const FLAG_CUSTOMER_GROUP_PRICE_ADDED = 'customer_group_price_data_added';
/**
* {@inheritdoc}
@@ -29,15 +28,9 @@ public function process(
SearchCriteriaInterface $searchCriteria,
array $attributeNames
): Collection {
- $isPriceDataAdded = $collection->getFlag(self::FLAG_CUSTOMER_GROUP_PRICE_ADDED);
-
// add tax percent, no-matter what
$collection->addTaxPercents();
- if ($isPriceDataAdded) {
- return $collection;
- }
-
if (in_array(self::PRICE_FIELD, $attributeNames, true)) {
/** @var $collection Collection */
$collection->addPriceData();
diff --git a/src/Model/Resolver/Products/Query/Search.php b/src/Model/Resolver/Products/Query/Search.php
index d1aabd8..d0b06d0 100644
--- a/src/Model/Resolver/Products/Query/Search.php
+++ b/src/Model/Resolver/Products/Query/Search.php
@@ -7,6 +7,7 @@
namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Products\Query;
+use Exception;
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ProductSearch;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
@@ -112,7 +113,7 @@ public function __construct(
* @param array $args
* @param ResolveInfo $info
* @return SearchResult
- * @throws \Exception
+ * @throws Exception
*/
public function getResult(
array $args,
diff --git a/src/Model/Variant/Collection.php b/src/Model/Variant/Collection.php
index df18621..3163a16 100755
--- a/src/Model/Variant/Collection.php
+++ b/src/Model/Variant/Collection.php
@@ -254,31 +254,9 @@ protected function getChildCollectionMapAndList(): array {
protected function getSearchCriteria(array $childrenIds): SearchCriteriaInterface {
// build a search criteria based on original one and filter of product ids
- $searchCriteria = $this->searchCriteriaBuilder
+ return $this->searchCriteriaBuilder
->addFilter('entity_id', $childrenIds, 'in')
->create();
-
- $isSingleProduct = CriteriaCheck::isSingleProductFilter($this->searchCriteria);
-
- $customFilterGroups = $searchCriteria->getFilterGroups();
- $originalFilterGroups = $this->searchCriteria->getFilterGroups();
-
- if (!$isSingleProduct) {
- $filterGroups = array_merge($customFilterGroups, $originalFilterGroups);
- } else {
- // special case for customer group price - it is needed to be added to filter
- foreach ($originalFilterGroups as $filterGroup) {
- foreach ($filterGroup->getFilters() as $filter) {
- if ($filter->getField() === 'customer_group_id') {
- $filterGroups = array_merge($customFilterGroups, [$filterGroup]);
- }
- }
- }
- }
-
- $searchCriteria->setFilterGroups($filterGroups ?? $customFilterGroups);
-
- return $searchCriteria;
}
/**
diff --git a/src/Plugin/Resolver/Products.php b/src/Plugin/Resolver/Products.php
new file mode 100644
index 0000000..d36a910
--- /dev/null
+++ b/src/Plugin/Resolver/Products.php
@@ -0,0 +1,68 @@
+
+ * @copyright Copyright (c) 2018 Scandiweb, Ltd (https://scandiweb.com)
+ */
+
+declare(strict_types=1);
+
+namespace ScandiPWA\CatalogGraphQl\Plugin\Resolver;
+
+use Magento\CatalogGraphQl\Model\Resolver\Products as CoreProducts;
+use Magento\Customer\Model\Session;
+use Magento\Framework\GraphQl\Config\Element\Field;
+use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder;
+use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
+
+class Products {
+ /** @var Builder */
+ protected $searchCriteriaBuilder;
+
+ /** @var Session */
+ protected $customerSession;
+
+ /**
+ * Products constructor.
+ * @param Builder $searchCriteriaBuilder
+ * @param Session $customerSession
+ */
+ public function __construct(
+ Builder $searchCriteriaBuilder,
+ Session $customerSession
+ ) {
+ $this->searchCriteriaBuilder = $searchCriteriaBuilder;
+ $this->customerSession = $customerSession;
+ }
+
+ public function beforeResolve(
+ CoreProducts $products,
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ $searchCriteria = $this->searchCriteriaBuilder->build('products', $args);
+ $context->getExtensionAttributes()->setSearchCriteria($searchCriteria);
+
+ foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
+ foreach ($filterGroup->getFilters() as $filter) {
+ if ($filter->getField() === 'customer_group_id') {
+ $this->customerSession->setCustomerGroupId($filter->getValue());
+ }
+ }
+ }
+
+ return [
+ $field,
+ $context,
+ $info,
+ $value,
+ $args
+ ];
+ }
+}
diff --git a/src/etc/graphql/di.xml b/src/etc/graphql/di.xml
index a72aacd..6980f0f 100644
--- a/src/etc/graphql/di.xml
+++ b/src/etc/graphql/di.xml
@@ -20,6 +20,15 @@
/>
+
+
+
+