diff --git a/src/Controller/Ajax/Stores.php b/src/Controller/Ajax/Stores.php index f33118c..96fc585 100755 --- a/src/Controller/Ajax/Stores.php +++ b/src/Controller/Ajax/Stores.php @@ -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. @@ -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); } @@ -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); } -} +} \ No newline at end of file diff --git a/src/Model/ResourceModel/Stores/Collection.php b/src/Model/ResourceModel/Stores/Collection.php index 7b4e2e4..d6c91b6 100755 --- a/src/Model/ResourceModel/Stores/Collection.php +++ b/src/Model/ResourceModel/Stores/Collection.php @@ -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; }