[英]Magento checkout success observer not working correctly
首先,抱歉这篇长篇文章。 我似乎无法通过这个工作。
我正在尝试使用观察成功事件的观察者来显示跟踪代码。 我启用了系统和异常日志,但没有看到任何错误。 我的配置中可能有大小写/语法错误。 这是我的第一个模块,斜线是向后的,因为我从桌面复制并粘贴。 这是文件的zip(只有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>');
}
}
}
应用程序\\设计\\前台\\基地\\ DEFAULT \\布局\\ 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>
应用程序\\设计\\前台\\基地\\ DEFAULT \\模板\\卡普斯\\ Cact.phtml
<!-- Begin Channel Advisor Tracking Code -->
<?php echo $this->_getCATrackingCode(); ?>
<!-- End Channel Advisor Tracking Code -->
我在config.xml
看到<events>
节点的主要问题并不正确。 请在<frontend>
节点内移动<events>
<frontend>
节点。 清除后。
我不确定,但我想这个
protected function _getCATrackingCode()
不管用。
您无法调用受保护的模板文件方法。 把它公之于众。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.