Magento结账成功观察员无法正常工作

时间:2014-02-04 20:24:50

标签: php xml magento

首先,抱歉这篇长篇文章。我似乎无法通过这个工作。

我正在尝试使用查看成功事件的观察者来显示跟踪代码。我启用了系统和异常日志,但没有看到任何错误。我的配置中可能有大小写/语法错误。这是我的第一个模块,斜线是向后的,因为我从桌面复制并粘贴。 Here is a zip of the files (only 6)以下是代码:

\应用\等\模块\ Capps_Cact.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Capps_Cact>
            <active>true</active>
            <codePool>local</codePool>
        </Capps_Cact>
    </modules>
</config>

应用\代码\本地\卡普斯\ C振动部\等\ config.xml中

<?xml version="1.0"?>
<config>
    <modules>
        <Capps_Cact>
            <version>1.0.0</version>
        </Capps_Cact>
    </modules>
    <frontend>
       <layout>
            <updates>
                <Capps>
                    <file>cact.xml</file>
                </Capps>
            </updates>
        </layout>
    </frontend>
    <global>
        <blocks>
            <cappscact>
                <class>Capps_Cact_Block</class>
            </cappscact>
        </blocks>
        <models>
            <cappscact>
                <class>Capps_Cact_Model</class>
            </cappscact>
        </models>
    </global>   
    <events>
            <checkout_onepage_controller_success_action>
                <observers>
                    <Capps_Cact_order_success>
                        <class>capps_cact/observer</class>
                        <method>setCappsCactOnOrderSuccessPageView</method>
                    </Capps_Cact_order_success>
                </observers>
            </checkout_onepage_controller_success_action>
            <checkout_multishipping_controller_success_action>
                <observers>
                    <Capps_Cact_order_success>
                        <class>capps_cact/observer</class>
                        <method>setCappsCactOnOrderSuccessPageView</method>
                    </Capps_Cact_order_success>
                </observers>
            </checkout_multishipping_controller_success_action>
    </events>   
</config>

应用\代码\本地\卡普斯\ C振动部\模型\ observer.php

<?php
class Capps_Cact_Model_Observer
{

    /**
     * Add order information into CC block to render on checkout success pages
     *
     * @param Varien_Event_Observer $observer
     */
    public function setCappsCactOnOrderSuccessPageView(Varien_Event_Observer $observer)
    {
        $orderIds = $observer->getEvent()->getOrderIds();
        if (empty($orderIds) || !is_array($orderIds)) {
            return;
        }
        $block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('capps_cact');
        if ($block) {
            $block->setOrderIds($orderIds);
        }
    }
}

应用\代码\本地\卡普斯\ C振动部\块\ Track.php

<?php

class Capps_Cact_Block_Track extends Mage_Core_Block_Template 
{
     /**
     * Render information about specified orders and their items for Channel Advisor
     *
     * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
     * @return string
     */
    protected function _getCATrackingCode()
    {
    $orderIds = $this->getOrderIds();
    if (empty($orderIds) || !is_array($orderIds)) {
            echo ('It worked its');
            return;
        } else {
            echo ('did that work');
            $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
            $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
            echo ('<script type="text/javascript"> 
            ');
            echo ('var _caq = _caq || [];
            ');
            echo ('var products = []; 
            ');
            $Id = '';
            $Qty = '';
            $Price = '';
            $items = $order->getAllItems();
            foreach($items as $item){
                echo ('products.push({Sku: \'');
                echo $Id .= $item->getSku();
                echo ("', ");
                echo ('UnitPrice: \'');
                echo $Price .= $item->getPrice();
                echo ("', ");
                echo ('Quantity: \'');
                echo $Qty .= $item->getQtyOrdered();
                echo ('\'});
                ');
                $Id = '';
                $Qty = '';
                $Price = '';
                } 
            $separateones = substr($separateones, 0,-1);
            echo ('_caq.push(["Order", {OrderId: \'');
            echo $order->getIncrementId();
            echo ('\', Revenue: \'');
            echo $order->getSubtotal();
            echo ('\', CurrencyCode: \'USD\', Products: products}]);
            ');
            echo ('</script>');
        }
    }
}

应用\设计\前端\基\默认\布局\ cact.xml

<?xml version="1.0"?>
<layout version="1.0.0">

<!--
Default layout, loads most of the pages
-->

    <default>
        <!-- Mage_GoogleAnalytics -->
        <reference name="after_body_start">
            <block type="cappscact/track" name="capps_cact" as="capps_cact" template="Capps/Cact.phtml" />
        </reference>
    </default>
</layout>

应用\设计\前端\基\默认\模板\卡普斯\ Cact.phtml

<!-- Begin Channel Advisor Tracking Code -->
    <?php echo $this->_getCATrackingCode(); ?>
<!-- End Channel Advisor Tracking Code -->

1 个答案:

答案 0 :(得分:3)

我发现<events>config.xml节点的主要问题并不正确。请在<events>节点内移动<frontend>节点。清除后。

我不确定,但我认为这是

protected function _getCATrackingCode()

无效。

您无法调用受保护的模板文件方法。公开。