How can i get different new products store wise? [closed]
-
13-12-2019 - |
Question
I am getting same new products in my all store, i am using TATVA SOFT Catalog Extensions Configuration.
{{block type="catalogextensions/newproduct_home_list" name="newproduct_list" category_id="2276" template="catalogextensions/home_newproduct.phtml"}}
And this is my block code which i added in static block for assign different store, even i have added category_id="2276"
for different store different id. But displaying same products in all store.
Please guide me how can i solve this ! Here is the site link.
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of List
*
* @author om
*/
class Tatva_Catalogextensions_Block_Newproduct_Home_List extends Tatva_Catalogextensions_Block_Newproduct_List
{
protected function _getProductCollection()
{
parent::__construct();
$storeId = Mage::app()->getStore()->getStoreId();
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addStoreFilter($storeId, false)
->addAttributeToSort("entity_id","DESC")
->addAttributeToSelect(array('name', 'price', 'small_image'))
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
->setOrder($this->get_order(), $this->get_order_dir());
if(Mage::getStoreConfig('catalogextensions/config4/max_product'))
{
$products->setPageSize(Mage::getStoreConfig('catalogextensions/config4/max_product'));
}
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
$this->_productCollection = $products;
return $this->_productCollection;
}
function get_prod_count()
{
//unset any saved limits
Mage::getSingleton('catalog/session')->unsLimitPage();
return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 9;
}// get_prod_count
function get_cur_page()
{
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}// get_cur_page
function get_order()
{
return (isset($_REQUEST['order'])) ? ($_REQUEST['order']) : 'position';
}// get_order
function get_order_dir()
{
return (isset($_REQUEST['dir'])) ? ($_REQUEST['dir']) : 'desc';
}// get_direction
public function getToolbarHtml()
{
}
}
Solution
I think you post the wrong block file here as per your block
{{block type="catalogextensions/newproduct_home_list" name="newproduct_list" category_id="2276" template="catalogextensions/home_newproduct.phtml"}}
File path should be app/code/local/Tatva/Catalogextensions/Block/Newproduct/Home/List.php
and class should be called Tatva_Catalogextensions_Block_Newproduct_Home_List
which I find in your extension.
In this file in function _getProductCollection
I didn't see any filter by the category id. you might be need to add category filter in collection so your function should be like
protected function _getProductCollection()
{
parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$categoryId = $this->getCategoryId();
$category_model = Mage::getModel('catalog/category')->load($categoryId);
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToSort("entity_id", "DESC")
->addCategoryFilter($category_model)
->addAttributeToSelect(array('name', 'price', 'small_image'))
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
->setOrder($this->get_order(), $this->get_order_dir());
if (Mage::getStoreConfig('catalogextensions/config4/max_product')) {
$products->setPageSize(Mage::getStoreConfig('catalogextensions/config4/max_product'));
}
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
$this->_productCollection = $products;
return $this->_productCollection;
}