magento 添加事件

首先是配置文件config.xml里的配置

<checkout_cart_save_after> /*事件名字*/
                <observers>
                    <deal> /*模块名字*/
                        <class>deal/observer_cart</class> /*文件地址deal/Model/Observer/Cart.php*/
                        <method>findRequiredOptions</method> /*方法名字*/
                    </deal>
                </observers>
</checkout_cart_save_after>

最外面一层是events.

 public function findRequiredOptions(Varien_Event_Observer $observer)
    {
        $cart = $observer->getEvent()->getCart();
        $productIds = $cart->getProductIds();
        foreach($productIds as $id)
        {
            $product = Mage::getModel('catalog/product')->load($id);
            try {
                $product->getTypeInstance(true)->checkProductBuyState($product);
            } catch (Mage_Core_Exception $e) {
                Mage::getSingleton('core/session')->addNotice($product->getName().Mage::helper('sales')->__(' do not have all the required options.'));
            }
        }


    }

这个是为cart添加事件,

资料:http://blog.chinaunix.net/uid-26559452-id-3093204.html

posted @ 2014-07-07 17:10  舟了个舟  阅读(342)  评论(0编辑  收藏  举报