Skip to content

Commit

Permalink
Fix random category
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed Apr 7, 2022
1 parent 7140fbe commit 66de340
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 20 additions & 2 deletions Block/Category/GridProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Catalog\Block\Product\AbstractProduct;

class GridProduct extends \Magiccart\Magicproduct\Block\Product\ListProduct
class GridProduct extends \Magento\Catalog\Block\Product\ListProduct
{

protected $_limit; // Limit Product
protected $_types; // types is types filter bestseller, featured ...

/**
* Product collection factory
*
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $_productCollectionFactory;

/**
* Product collection factory
*
Expand All @@ -40,13 +48,15 @@ public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
CategoryRepositoryInterface $categoryRepository,
\Magento\Framework\Url\Helper\Data $urlHelper,
\Magento\CatalogWidget\Model\RuleFactory $ruleFactory,
\Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
\Magiccart\Magicproduct\Model\Magicproduct $magicproduct,
array $data = []
) {
$this->_productCollectionFactory = $productCollectionFactory;
$this->_ruleFactory = $ruleFactory;
$this->sqlBuilder = $sqlBuilder;
$this->_magicproduct = $magicproduct;
Expand Down Expand Up @@ -94,7 +104,15 @@ protected function _getProductCollection()

if (is_null($this->_productCollection)) {
$this->setCategoryId($this->getTypeFilter());
$this->_productCollection = parent::_getProductCollection();
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection = $this->_productCollectionFactory->create();
$collection->addCategoriesFilter(['in' => $this->getTypeFilter()]);
$this->_catalogLayer->prepareProductCollection($collection);
$collection = $this->_addProductAttributesAndPrices(
$collection
);
$collection->addStoreFilter();
$this->_productCollection = $collection;
}

$this->_limit = (int) $this->getWidgetCfg('limit');
Expand Down
7 changes: 6 additions & 1 deletion view/frontend/web/js/magicproduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ define([
},

actionLoad: function(tab, productsActivated) {
if(tab.data('type') == 'random'){
var isRandom = (tab.data('type') == 'random');
if(!isRandom){
var ajax = tab.closest('.magictabs').data('ajax');
isRandom = (ajax.hasOwnProperty('types') && ajax.types == 'random');
}
if(isRandom){
tab.removeClass('loaded activated').trigger('click');
productsActivated.find('.products.items').html('');
} else {
Expand Down

0 comments on commit 66de340

Please sign in to comment.