Skip to main content
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with no winning answer by CommunityBot

I have enabled Show out of stock products in the admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub categorysubcategory) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in the search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used the below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me on how to implement this functionality.? I am unable to write a join query to match the above requirement. Please check and update me about this. Thanks for the help.

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Please check and update me about this. Thanks for the help.

I have enabled Show out of stock products in the admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its subcategory) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in the search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used the below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me on how to implement this functionality? I am unable to write a join query to match the above requirement. Please check and update me about this. Thanks for the help.

Tweeted twitter.com/StackMagento/status/1233044312855924737
added 51 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Please check and update me about this. Thanks!! for the help.

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Thanks!!

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Please check and update me about this. Thanks for the help.

deleted 215 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
        
    $getProductAllIds = $collection->getAllIds();
    $productUniqueIds = array_unique($getProductAllIds);
    $select->where("search_index.entity_id IN ('" . join("','", $productUniqueIds) . "')");     
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Thanks!!

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
        
    $getProductAllIds = $collection->getAllIds();
    $productUniqueIds = array_unique($getProductAllIds);
    $select->where("search_index.entity_id IN ('" . join("','", $productUniqueIds) . "')");     
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Thanks!!

I have enabled Show out of stock products in admin Inventory section.

I have to show all in stock and out of stock products of one category(id=10 and its sub category) in list and search result page. by hiding all out of stock products in remaining categories(But should show all in-stock products).

So when we are in category page(id is 10) need to show all in_stock and out of stock,

category page(id is not 10), Need to show only in_stock products.

If in search result page, have to show both in_stock and out_of_stock(only from category id 10).

I used below plugin.

Vendor\Module\etc\di.xml

<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
  <plugin name="Custom_Layernavigation::CustomLayernavigation"
  type="Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>

Then Vendor\Module\Plugin\CatalogSearch\Model\Search\IndexBuilder.php

<?php
use Magento\Framework\Search\RequestInterface;

class IndexBuilder {    
protected $_request;
protected $_categoryHelper;
 protected $_logger;

public function __construct(
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
    \Magento\Catalog\Helper\Category $categoryHelper,
    \Magento\Framework\App\Request\Http $request,
    \Psr\Log\LoggerInterface $logger
) {
    $this->_productCollectionFactory   = $productCollectionFactory;
    $this->_categoryHelper = $categoryHelper;
    $this->_request = $request;
    $this->_logger = $logger;
}

public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
    $select = $proceed($request);

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');     
    $collection->joinField(
        'qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
    );
    $collection->addAttributeToFilter('qty',['gt'=>0])->load();
    $collection->getSelect()
        ->join(array('cat_index'=> 'catalog_category_product_index_store1'), "cat_index.product_id = e.entity_id")
        ->where('cat_index.category_id <> 10');
            
    return $select;
  }
}

Can someone update me how to implement this functionality. I am unable to write join query to match the above requirement. Thanks!!

added 245 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 99 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
Notice added Authoritative reference needed by Jafar Pinjar
Bounty Started worth 200 reputation by Jafar Pinjar
added 1247 characters in body; edited tags; edited title
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
edited title
Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 60 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 7 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 1 character in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 2 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 3 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 4 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 7 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
added 11 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144
Loading