Skip to content

Commit

Permalink
Merge pull request #88 from AleksandrsKondratjevs/issue-3373
Browse files Browse the repository at this point in the history
Add products SKUs to stores filter
  • Loading branch information
carinadues authored Oct 25, 2021
2 parents 0e3fc8c + 2df32fd commit 939b335
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions src/Model/Resolver/GetStores.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
namespace ScandiPWA\QuoteGraphQl\Model\Resolver;

use Exception;
use Magento\Directory\Model\Country\Postcode\ConfigInterface;
use Magento\Directory\Model\CountryFactory;
use Magento\Directory\Model\Country\Postcode\ConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -27,9 +27,10 @@
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\InventoryInStorePickup\Model\GetPickupLocations;
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequestInterface;
use Magento\InventoryInStorePickupApi\Model\SearchRequestBuilderInterface;
use Magento\InventoryInStorePickupGraphQl\Model\Resolver\PickupLocations\SearchRequestBuilder\ExtensionProvider;
use Magento\InventoryInStorePickup\Model\GetPickupLocations;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\Store\Model\StoreManagerInterface;

Expand Down Expand Up @@ -74,6 +75,11 @@ class GetStores implements ResolverInterface
*/
protected $postCodesConfig;

/**
* @var ExtensionProvider
*/
protected $extensionProvider;

/**
* GetStores constructor.
* @param SearchRequestBuilderInterface $searchRequest
Expand All @@ -82,21 +88,24 @@ class GetStores implements ResolverInterface
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param ConfigInterface $postCodesConfig
* @param ExtensionProvider $extensionProvider
*/
public function __construct(
SearchRequestBuilderInterface $searchRequest,
GetPickupLocations $getPickupLocations,
CountryFactory $countryFactory,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
ConfigInterface $postCodesConfig
ConfigInterface $postCodesConfig,
ExtensionProvider $extensionProvider
) {
$this->searchRequest = $searchRequest;
$this->getPickupLocations = $getPickupLocations;
$this->countryFactory = $countryFactory;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->postCodesConfig = $postCodesConfig;
$this->extensionProvider = $extensionProvider;
}

/**
Expand Down Expand Up @@ -128,16 +137,16 @@ public function resolve(

$result = [];

if($args['search'] === '') {
$searchRequest = $this->getAllStores();
if($search === '') {
$searchRequest = $this->getAllStores($args);
} else {
$postCodes = $this->postCodesConfig->getPostCodes();

if (!isset($postCodes[$country])) {
throw new GraphQlInputException(__('No in-delivery support for provided country. Please select another country.'));
}

$searchRequest = $this->getStoresBySearch($search, $country);
$searchRequest = $this->getStoresBySearch($args);
}

try {
Expand Down Expand Up @@ -167,11 +176,12 @@ public function resolve(
* @return SearchRequestInterface
* @throws LocalizedException
*/
public function getAllStores() {
public function getAllStores($args) {
$searchRequest = $this->searchRequest
->setScopeType(SalesChannelInterface::TYPE_WEBSITE)
->setScopeCode($this->storeManager->getWebsite()->getCode())
->setPageSize(50)
->setSearchRequestExtension($this->extensionProvider->getExtensionAttributes($args))
->create();

return $searchRequest;
Expand All @@ -183,17 +193,18 @@ public function getAllStores() {
* @return SearchRequestInterface
* @throws LocalizedException
*/
public function getStoresBySearch($search, $country) {
public function getStoresBySearch($args) {
$searchRequest = $this->searchRequest
->setScopeType(SalesChannelInterface::TYPE_WEBSITE)
->setAreaSearchTerm(sprintf(
'%s:%s',
$search,
$country
$args['search'],
$args['country']
))
->setPageSize(50)
->setScopeCode($this->storeManager->getWebsite()->getCode())
->setAreaRadius((int) $this->scopeConfig->getValue(self::SEARCH_RADIUS))
->setSearchRequestExtension($this->extensionProvider->getExtensionAttributes($args))
->create();

return $searchRequest;
Expand Down
2 changes: 1 addition & 1 deletion src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Query {
getOrderById(id: Int!): Order @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\ExpandedOrderResolver") @doc(description: "The Sales Order query returns information about a Sales order")
getBraintreeConfig: Braintree @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\BraintreeResolver")
getCartDisplayConfig: CartDisplayConfig @doc(description: "Get cart display settings") @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\CartDisplayConfigResolver")
getStores(search: String, country: String): Stores @resolver(class: "ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\GetStores")
getStores(search: String, country: String, productsInfo: [ProductInfoInput]): Stores @resolver(class: "ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\GetStores")
}

type Mutation {
Expand Down

0 comments on commit 939b335

Please sign in to comment.