Skip to content

Commit

Permalink
Merge pull request Smile-SA#160 from romainruaud/fix_virtual-category…
Browse files Browse the repository at this point in the history
…-empty-preview

Prioritize the default store view for virtual category previews, if t…
  • Loading branch information
afoucret authored Oct 10, 2016
2 parents 90512ec + 4c06f32 commit 507505e
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Smile\ElasticsuiteVirtualCategory\Plugin\Catalog\Category;

use Magento\Catalog\Model\Category\DataProvider as CategoryDataProvider;
use Magento\Store\Model\StoreManagerInterface;
use \Smile\ElasticsuiteVirtualCategory\Model\ResourceModel\Category\Product\Position as ProductPositionResource;
use Magento\Catalog\Model\Category;

Expand Down Expand Up @@ -44,21 +45,29 @@ class DataProviderPlugin
*/
private $localeFormat;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* Constructor.
*
* @param ProductPositionResource $productPositionResource Product position resource model.
* @param \Magento\Framework\Locale\FormatInterface $localeFormat Locale formater.
* @param \Magento\Backend\Model\UrlInterface $urlBuilder Admin URL Builder.
* @param StoreManagerInterface $storeManagerInterface Store Manager.
*/
public function __construct(
ProductPositionResource $productPositionResource,
\Magento\Framework\Locale\FormatInterface $localeFormat,
\Magento\Backend\Model\UrlInterface $urlBuilder
\Magento\Backend\Model\UrlInterface $urlBuilder,
StoreManagerInterface $storeManagerInterface
) {
$this->productPositionResource = $productPositionResource;
$this->localeFormat = $localeFormat;
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManagerInterface;
}

/**
Expand Down Expand Up @@ -98,7 +107,11 @@ private function getProductSorterLoadUrl(Category $category)
$storeId = $category->getStoreId();

if ($storeId === 0) {
$storeId = current(array_filter($category->getStoreIds()));
$defaultStoreId = $this->storeManager->getDefaultStoreView()->getId();
$storeId = current(array_filter($category->getStoreIds()));
if (in_array($defaultStoreId, $category->getStoreIds())) {
$storeId = $defaultStoreId;
}
}

$urlParams = ['ajax' => true, 'store' => $storeId];
Expand Down

0 comments on commit 507505e

Please sign in to comment.