Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category Product Collection shows products out of stock #41

Open
Krapulat opened this issue Jun 17, 2016 · 2 comments
Open

Category Product Collection shows products out of stock #41

Krapulat opened this issue Jun 17, 2016 · 2 comments

Comments

@Krapulat
Copy link

When using $_productCollection=$this->getLoadedProductCollection(); inside catalog/product/list.phtml it shows all products (including out of stock). And Mage::getStoreConfig('cataloginventory/options/show_out_of_stock') is false.

I've tried

$_productCollection->getSelect()->join(
                        array(
                            'stock_status_index' => Mage::getSingleton('core/resource')->getTableName('demac_multilocationinventory/stock_status_index')
                        ),
                        'e.entity_id = stock_status_index.product_id' .
                        ' AND stock_status_index.qty > 0' .
                        ' AND stock_status_index.is_in_stock = 1' .
                        ' AND stock_status_index.store_id = ' . $storeId,
                        array()
                    );

with no luck.

How can I get it working with this extension?

@L-M-ICA40511
Copy link

L-M-ICA40511 commented Jun 27, 2016

See also pull request #42
If you look just before that exact snippet in Demac_MultiLocationInventory_Model_Observer, it's trying to check isset($filters['visibility']) but $filters is a category Id. Not the catalog product limitations.
Instead of:

$filters = $observer->getCategoryId();

Use:

if ($collection = $observer->getCollection()) {
            $filters = $collection->getLimitationFilters();

(In full)

public function catalogProductCollectionApplyLimitationsBefore(Varien_Event_Observer $observer) {
    $categoryId = $observer->getCategoryId();
    if ($collection = $observer->getCollection()) {
        $filters = $collection->getLimitationFilters();
        if(isset($filters['visibility']) && !Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')) {
            $storeId = Mage::app()->getStore()->getId();
            $selectFrom = $collection->getSelect()->getPart(Zend_Db_Select::FROM);
            if(!isset($selectFrom['stock_status_index'])) {
                $collection
                    ->getSelect()
                    ->join(
                        array(
                            'stock_status_index' => Mage::getSingleton('core/resource')->getTableName('demac_multilocationinventory/stock_status_index')
                        ),
                        'e.entity_id = stock_status_index.product_id' .
                        ' AND stock_status_index.qty > 0' .
                        ' AND stock_status_index.is_in_stock = 1' .
                        ' AND stock_status_index.store_id = ' . $storeId,
                        array()
                    );
            }
        }
    }
}

@iambaljitdhanoa
Copy link

Hello There

We are using brand extension in magento 1.9.2.4.
brand extension displaying only instock product we need in stock and out of stock both .

We are using this query

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('manufacturer');

    $products->addFieldToFilter(array(
        array('attribute'=>'manufacturer', 'eq'=> $option_id,          
    )));
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
    $products->addAttributeToFilter('status',1); 
    $products->addAttributeToFilter('visibility', 4);
   foreach ($products as $product) 
   {
      $_productIds[] = $product['entity_id'];
   }
            
    if (is_null($this->_productCollection)) {
        
    $product_ids = $_productIds;
    //getting product model
    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('*');
    $collection->addFieldToFilter('entity_id',array('in' =>$product_ids));

    $collection->joinField(
      'stock_status',
      'cataloginventory/stock_status',
      'stock_status',
      'product_id=entity_id', array(
        'stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK,
        'website_id' => Mage::app()->getWebsite()->getWebsiteId(),
      )
    );

     $collection
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
        $collection->setStore(Mage::app()->getStore())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addStoreFilter()
        ->addUrlRewrite();
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

Please let me know how we can display both product in result page please suggest me how can change query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants