仅比较那些具有相同类别magento的产品 [英] compare only those product who have same category magento

查看:71
本文介绍了仅比较那些具有相同类别magento的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想比较那些具有相同父级的类别,

i want to compare only those category who have same parent,

例如, 用户可以将诺基亚手机与三星手机进行比较 但是如果用户想将诺基亚手机与鞋子进行比较,则不允许比较这些产品

for Example, user can compare nokia mobile with samsung mobile but if user want to compare nokia mobile with shoes than it will not allow to compare those products

给予了极大的帮助

先谢谢您

推荐答案

在app \ code \ core \ Mage \ Catalog \ controllers \ Product \ CompareController.php \中进行如下更改

In app\code\core\Mage\Catalog\controllers\Product\CompareController.php\ make changes like the following

if ($product->getId() /* && !$product->isSuper() */ ) {
$categoryIds = $product->getCategoryIds();
if (is_array($categoryIds) and count($categoryIds) > 1) {
$cat = Mage::getModel('catalog/category')->load($categoryIds[2]);
if(!isset($_SESSION['compare']))
{
$_SESSION['compare']=$cat->getId();
$_SESSION['comparecount']=0;
}
if($cat->getId() == $_SESSION['compare'] /* || $cat->getId() == 13 ||$cat->getId() == 18 ||$cat->getId() == 35*/ ) ///come back here
{
$_SESSION['comparecount']++;
Mage::getSingleton('catalog/product_compare_list')->addProduct($product);
Mage::getSingleton('catalog/session')->addSuccess(
$this->__('The product %s has been added to comparison list.:)', Mage::helper('core')->escapeHtml($product->getName()))
);
Mage::dispatchEvent('catalog_product_compare_add_product', array('product'=>$product));
}else
{
Mage::getSingleton('catalog/session')->addSuccess(
$this->__('The product %s not possible to add in comparison list.:(', Mage::helper('core')->escapeHtml($product->getName()))
);

}
}}

//// Same file in function removeAction() after condition
if($item->getId()) {
$item->delete();

/// add the following lines
$_SESSION['comparecount']--;
if($_SESSION['comparecount']<1) { unset($_SESSION['comparecount']); unset($_SESSION['compare']); }

//// Same file in function clearAction() after try { $items->clear();

//// add the following lines
unset($_SESSION['compare']);

这就是所有人……享受比较…… 这是我的博客.享受比较.

That’s all guys… Enjoy comparison… here is My blog. enjoy comparison.

这篇关于仅比较那些具有相同类别magento的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆