1. rewrite core compare action
<?xml version="1.0"?> <config> <modules> <Bysoft_Mycatalog> <version>0.1.0</version> </Bysoft_Mycatalog> </modules> <global> <helpers> <mycatalog> <class>Bysoft_Mycatalog_Helper</class> </mycatalog> <catalog> <rewrite> <product_compare>Bysoft_Mycatalog_Helper_Product_Compare</product_compare> </rewrite> </catalog> </helpers> <resources> <mycatalog_setup> <setup> <module>Bysoft_Mycatalog</module> <class>Mage_Eav_Model_Entity_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </mycatalog_setup> <mycatalog_write> <connection> <use>core_write</use> </connection> </mycatalog_write> <mycatalog_read> <connection> <use>core_read</use> </connection> </mycatalog_read> </resources> <blocks> <mycatalog> <class>Bysoft_Mycatalog_Block</class> </mycatalog> <catalog> <rewrite> <layer_view>Bysoft_Mycatalog_Block_Layer_View</layer_view> <category_view>Bysoft_Mycatalog_Block_Category_View</category_view> </rewrite> </catalog> </blocks> </global> <frontend> <routers> <catalog> <args> <modules> <bysoft_mycatalog before="Mage_Catalog">Bysoft_Mycatalog</bysoft_mycatalog> </modules> </args> </catalog> </routers> <layout> <updates> <arithmetic> <file>mycatalog.xml</file> </arithmetic> </updates> </layout> </frontend> </config>
2. in controller file.
<?php require_once(Mage::getModuleDir('controllers','Mage_Catalog').DS.'Product'.DS.'CompareController.php'); class Bysoft_Mycatalog_Product_CompareController extends Mage_Catalog_Product_CompareController { public function changeajaxAction() { $productId = (int) $this->getRequest()->getParam('product'); if ($productId && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn()) ) { if ($this->is_compare($productId)) { // to uncompared $this->remove_compare($productId); } else { // to compared $this->add_compare($productId); } } } /** * check the product is compare or not * @param unknown $productId */ public function is_compare($productId) { $product = Mage::getModel('catalog/product')->load($productId); $item = Mage::getModel('catalog/product_compare_item'); $list = Mage::getModel('catalog/product_compare_list'); //$list->_addVisitorToItem($item); $item->addVisitorId(Mage::getSingleton('log/visitor')->getId()); if (Mage::getSingleton('customer/session')->isLoggedIn()) { $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer()); } $item->loadByProduct($product); if ($item->getId()) { return true; } else { return false; } } public function add_compare($productId) { try { if ($productId && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn()) ) { $product = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); if ($product->getId()/* && !$product->isSuper()*/) { 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)); } Mage::helper('catalog/product_compare')->calculate(); } echo json_encode(array('status'=>'1','is_compare'=>'1')); } catch (Exception $e) { echo json_encode(array('status'=>'2','msg'=>$e->getMessage())); } } public function remove_compare($productId) { try { if ((int) $productId) { $product = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); if($product->getId()) { /** @var $item Mage_Catalog_Model_Product_Compare_Item */ $item = Mage::getModel('catalog/product_compare_item'); if(Mage::getSingleton('customer/session')->isLoggedIn()) { $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer()); } elseif ($this->_customerId) { $item->addCustomerData( Mage::getModel('customer/customer')->load($this->_customerId) ); } else { $item->addVisitorId(Mage::getSingleton('log/visitor')->getId()); } $item->loadByProduct($product); if($item->getId()) { $item->delete(); Mage::getSingleton('catalog/session')->addSuccess( $this->__('The product %s has been removed from comparison list.', $product->getName()) ); Mage::dispatchEvent('catalog_product_compare_remove_product', array('product'=>$item)); Mage::helper('catalog/product_compare')->calculate(); } } } echo json_encode(array('status'=>'1','is_compare'=>0)); } catch (Exception $e) { echo json_encode(array('status'=>'2','msg'=>$e->getMessage())); } } } ?>
3. in frontend phtml file
<div class="compare-box"> <a class="compare-a <?php echo $this->getCompareClass($_product->getId());?>" to_url="<?php echo $_compare_helper->getChangeAjaxUrl($_product);?>" > <?php echo $this->getCompareLabel($_product->getId());?></a></div>
4. jquery ajax
<script type="text/javascript">//<![CDATA[ (function($){ $(".compare-a").click(function(){ var current_obj = $(this); var is_compare = $(this).attr('is_compare'); var ajax_url = $(this).attr('to_url'); $.ajax({ url: ajax_url, type: "POST", dataType:"json", success: function(json_obj) { if(json_obj.status == 1) { if (json_obj.is_compare == '1') { alert('is_compare:1'); current_obj.addClass('compared'); current_obj.removeClass('uncompared'); current_obj.html('Compared'); } else { alert('is_compare:0'); current_obj.addClass('uncompared'); current_obj.removeClass('compared'); current_obj.html('Uncompared'); } } else { alert(json_obj.msg); } } }); }) })(jQuery); //]]></script>
相关推荐
dxmanageer是一个非常优秀的菜单软件,但 里面的系统菜单是英文的,比方‘Add or Remove Buttons’就是英文的,这个可能在我们应用的时候会有些小小的瑕疵,本例子就把‘Add or Remove Buttons’修改成了‘删除或...
Control Panel - Add/Remove Programs
超強 軟體安裝 移除程式,它可以讓你 重覆 註冊 試用軟件 無 數次 !!
一款很好用的卸载程序,很多顽固程序手动无法卸载的均可使用此程序卸载.
Fragment后退栈和add,remove,replace的基本使用.
vue-cli3增删改,不需要后端接口,纯前端逻辑,复制粘贴就能用,主要提供学习,绝对适合新手非常适合新手学习非常适合新手学习
注入语句笔记
因此,Struts 2其中的一个重要的功能(Feature)就是“First-class AJAX support - Add interactivity and flexibility with AJAX tags that look and feel just like standard Struts tags(大意:一流的AJAX支持...
Ajax-Magento-ajax-add-to-cart.zip,[模块magento 1]magento ajax添加到购物车-ajoter vos produits au panier en ajax/感谢ajax将您的产品添加到购物车,ajax代表异步javascript和xml。它是多种web技术的集合,包括...
ORACLE 19C RAC remove add node
using System; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; using Microsoft.Win32; namespace MRU { public partial class FormMRU : Form { public FormMRU() { #...
Foundations of Ajax is written to give you, the developer, all the tools you need to add Ajax techniques to your existing or future applications. Our motto while writing this book was, “Everything ...
If you want to learn some basic programming concepts, have experience but need help updating your skills, or you’re coming from another language, Beginning JavaScript with DOM Scripting and Ajax can...
安装reveal-add-remove.js 待定用法待定贡献请保持仅限于错误报告、功能请求和拉取请求。 如果您要报告错误,请确保包含有关您使用的浏览器和操作系统的信息以及重现问题的必要步骤。 如果您有个人支持问题,请使用 ...
convolution using overlap add method
For those developing add-ins in C and C++ so little changed between Excel 97 and Excel 2003 (version 11) that the entire first edition applied almost equally to versions 8, 9, 10 and 11. Excel 2007 ...
If you want to learn some basic programming concepts, have experience but need help updating your skills, or you’re coming from another language, Beginning JavaScript with DOM Scripting and Ajax can...
蓝驿轨迹-ajax+xml实现省市区无刷新联动源码 帮助: ...<script language="javascript" src="js/PCA.js"></script>... <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" /> </system.web>
creating powerful and reliable add-ins for Excel. With years of use, many people build up the experience and understanding needed to create custom functions for Excel in C and C++. However, given the ...
Uninstall Tool is a quick, powerful and reliable alternative to standard Windows Add/Remove program. It's fast, secure and convenient way to remove unneeded applications and to improve your computer ...