Skip to content

Commit

Permalink
Merge pull request #33 from ConvertGroupsAS/store-filter-fix
Browse files Browse the repository at this point in the history
Fixed store filter for ajax call
  • Loading branch information
ClaudiuCreanga authored Mar 26, 2018
2 parents 60a000a + d097127 commit 408132c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Controller/Ajax/Stores.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Limesharp\Stockists\Model\ResourceModel\Stores\CollectionFactory;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Store\Model\StoreManagerInterface;

/**
* Responsible for loading page content.
Expand All @@ -41,14 +42,21 @@ class Stores extends \Magento\Framework\App\Action\Action
* @var CollectionFactory
*/
protected $collectionFactory;

/**
* @var StoreManagerInterface
*/
public $storeManager;

public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
StoreManagerInterface $storeManager
) {
$this->collectionFactory = $collectionFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->storeManager = $storeManager;
parent::__construct($context);
}

Expand All @@ -59,11 +67,13 @@ public function __construct(
*/
public function execute()
{
$collection = $this->collectionFactory->create()->getData();
$collection = $this->collectionFactory->create()
->addStoreFilter($this->storeManager->getStore()->getId())
->getData();
$json = [];
foreach ($collection as $stockist) {
$json[] = $stockist;
}
return $this->resultJsonFactory->create()->setData($json);
}
}
}
8 changes: 7 additions & 1 deletion src/Model/ResourceModel/Stores/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ public function addStoreFilter($store, bool $withAdmin = true)
$store[] = Store::DEFAULT_STORE_ID;
}

$this->addFilter('store_id', ['in' => $store], 'public');
$filterParams = [];

foreach ($store as $storeId) {
$filterParams[]['finset'] = $storeId;
}

$this->addFilter('store_id', $filterParams, 'public');
}
return $this;
}
Expand Down

0 comments on commit 408132c

Please sign in to comment.