单击“添加到购物车”按钮后无法创建日志文件

时间:2014-09-21 05:42:16

标签: magento

点击“添加到购物车”按钮后,我需要创建一个日志文件。但是当我点击“添加到购物车”按钮时,我的代码没有创建日志文件,请帮忙。谢谢

2 个答案:

答案 0 :(得分:0)

config.xml
    <?xml version="1.0"?>
    <config>
      <modules>
        <Featured_Attribute>
          <version>0.1.0</version>
        </Featured_Attribute>
      </modules>
      <global>      

        <helpers>
          <attribute>
            <class>Featured_Attribute_Helper</class>
          </attribute>
        </helpers>
        <blocks>
          <attribute>
            <class>Featured_Attribute_Block</class>
          </attribute>
        </blocks>
        <models>
          <attribute>
            <class>Featured_Attribute_Model</class>
            <resourceModel>attribute_mysql4</resourceModel>
          </attribute>
          <attribute_mysql4>
            <class>Featured_Attribute_Model_Mysql4</class>
          </attribute_mysql4>
            <catalog_resource>
                  <rewrite>
                      <product_collection>Featured_Attribute_Model_Resource_Product_Collection</product_collection>
                  </rewrite>
            </catalog_resource>
        </models>



            <events>
                <add_to_cart_after>
                    <observers>
                            <add_to_cart_after>
                                    <class>attribute/observer</class>
                                    <method>hookToAddToCartAfter</method>
                            </add_to_cart_after>
                    </observers>
                </add_to_cart_after>
            </events>
            <template>
                <email>
                    <custom_order_tpl module="Featured_Attribute">
                        <label>Status Mail Invoice</label>
                        <file>sendemail_processing.html</file>
                        <type>html</type>
                    </custom_order_tpl>
                </email>
            </template>



            <resources>
          <attribute_setup>
            <setup>
              <module>Featured_Attribute</module>
                      <class>Mage_Catalog_Model_Resource_Setup</class>
            </setup>
            <connection>
              <use>core_setup</use>
            </connection>
          </attribute_setup>
          <attribute_write>
            <connection>
              <use>core_write</use>
            </connection>
          </attribute_write>
          <attribute_read>
            <connection>
              <use>core_read</use>
            </connection>
          </attribute_read>
        </resources>
      </global>
      <admin>
        <routers>
          <attribute>
            <use>admin</use>
            <args>
              <module>Featured_Attribute</module>
              <frontName>attribute</frontName>
            </args>
          </attribute>
        </routers>
      </admin>

      <!-- This is for frontend process -->
      <frontend>
            <routers>
                <attribute>
                    <use>standard</use>
                    <args>
                        <module>Featured_Attribute</module>
                        <frontName>attributefront</frontName>
                    </args>
                </attribute>
            </routers>
            <layout>
                <updates>
                    <attribute>
                        <file>attributefront.xml</file>
                    </attribute>
                </updates>
            </layout>
        </frontend>
    </config>

    Observer.php
    <?php
    class Featured_Attribute_Model_Observer
    {
        public function hookToAddToCartAfter($observer) 
        {
                //Hooking to our own event
            //$request = $observer->getEvent()->getRequest()->getParams();
                // do something with product
            Mage::log("Product is added to cart.");
        }
    }

答案 1 :(得分:0)

没有名为&#34; add_to_cart_after&#34;在标准magento。而不是这个,你需要使用&#34; checkout_cart_product_add_after&#34;或者&#34; checkout_cart_add_product_complete&#34;。以下是配置的新部分:

<events>
    <checkout_cart_product_add_after>
        <observers>
            <add_to_cart_after>
                <class>attribute/observer</class>
                <method>hookToAddToCartAfter</method>
            </add_to_cart_after>
        </observers>
     </checkout_cart_product_add_after>
</events>

另外你应该知道Mage :: log(&#34;产品被添加到购物车。&#34;);仅在启用了开发人员模式时才有效。另一方面,你需要使用

Mage::log("Product is added to cart.", null, 'system.log', true);