Friday, August 27, 2010
Friday, August 20, 2010
magento set continueshoppingurl from any custom module
use this to set continue shopping url from any where in magento without editing any core files :-
Mage::getSingleton('checkout/session')->setContinueShoppingUrl(Mage::helper('core/url')->getCurrentUrl());
for more on magento visit:-
http://magentoexp.blogspot.com/
Mage::getSingleton('checkout/session')->setContinueShoppingUrl(Mage::helper('core/url')->getCurrentUrl());
for more on magento visit:-
http://magentoexp.blogspot.com/
Thursday, August 19, 2010
Magento – Filter by multiple categories
create local copy of this modal:
app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Product
edit collection.php add this function:-
public function addCategoriesFilter(array $categories)
{
// print_r($categories);
//echo $this->getStoreId() ;
$this->_prepareProductLimitationFilters();
$this->_productLimitationJoinWebsite();
$this->_productLimitationJoinPrice();
$filters = $this->_productLimitationFilters;
$conditions = array(
'cat_index.product_id=e.entity_id',
$this->getConnection()->quoteInto('cat_index.store_id=?', $this->getStoreId())
);
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
}
$conditions[] = $this->getConnection()
->quoteInto('cat_index.category_id IN(?)',$categories);
if (isset($filters['category_is_anchor'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
}
$joinCond = join(' AND ', $conditions);
$this->getSelect()->join(
array('cat_index' => $this->getTable('catalog/category_product_index')),
$joinCond,
array('cat_index_position' => 'position')
);
$this->_productLimitationJoinStore();
Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array(
'collection' => $this
));
return $this;
}
At your module block use this function to get products collection from multiple categories :-
public function _getProductCollection(){
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$categories=array(3,4,5,6,7,8);
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToFilter('visibility', $visibility)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;
}
app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Product
edit collection.php add this function:-
public function addCategoriesFilter(array $categories)
{
// print_r($categories);
//echo $this->getStoreId() ;
$this->_prepareProductLimitationFilters();
$this->_productLimitationJoinWebsite();
$this->_productLimitationJoinPrice();
$filters = $this->_productLimitationFilters;
$conditions = array(
'cat_index.product_id=e.entity_id',
$this->getConnection()->quoteInto('cat_index.store_id=?', $this->getStoreId())
);
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
}
$conditions[] = $this->getConnection()
->quoteInto('cat_index.category_id IN(?)',$categories);
if (isset($filters['category_is_anchor'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
}
$joinCond = join(' AND ', $conditions);
$this->getSelect()->join(
array('cat_index' => $this->getTable('catalog/category_product_index')),
$joinCond,
array('cat_index_position' => 'position')
);
$this->_productLimitationJoinStore();
Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array(
'collection' => $this
));
return $this;
}
At your module block use this function to get products collection from multiple categories :-
public function _getProductCollection(){
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$categories=array(3,4,5,6,7,8);
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToFilter('visibility', $visibility)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;
}
get attribute value for configurable product
//this function will get the configurable products set
public function getprodco_without_visib(){
$categories=$this->get_categories();
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;
}
function getatt_label_basedoncode($attrb_code,$product){
$attributeValue = Mage::getModel('catalog/product')
->load($product->getId())
->getAttributeText($attrb_code);
return $attributeValue;
}
//GET all product id with their attribute selected value in an array
function getproduct_attrbset_array(){
$prodattarr=array();
$prods = $this->getprodco_without_visib();
foreach ($prods as $product) {
//$product = Mage::getModel('catalog/product')->load(14);
$prodattarr[] = array(
'attset' => $this->getatt_label_basedoncode('your_attrib_code',$product),
'prod_id' =>$product->getId(),
);
}
return $prodattarr;
}
public function getprodco_without_visib(){
$categories=$this->get_categories();
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;
}
function getatt_label_basedoncode($attrb_code,$product){
$attributeValue = Mage::getModel('catalog/product')
->load($product->getId())
->getAttributeText($attrb_code);
return $attributeValue;
}
//GET all product id with their attribute selected value in an array
function getproduct_attrbset_array(){
$prodattarr=array();
$prods = $this->getprodco_without_visib();
foreach ($prods as $product) {
//$product = Mage::getModel('catalog/product')->load(14);
$prodattarr[] = array(
'attset' => $this->getatt_label_basedoncode('your_attrib_code',$product),
'prod_id' =>$product->getId(),
);
}
return $prodattarr;
}
Subscribe to:
Posts (Atom)