我知道success.phtml是我应该放置我想要执行的代码的文件,但我收到了CJ这个不是html的文件,它是一个php类。
问题很简单:我想知道如何在收到订单后将此文件整合到success.phtml中。?
谢谢
class CommissionJunction extends Mage_Core_Helper_Data
{
/**
* Get SKU, quantity, price and discount amount for each product in a given order
* @param object $order
* @return array
*/
private function _getOrderProductsList($order) {
$orderItems = $order->getAllItems();
$purchasedSkus = array();
$count_orderItems = count($orderItems);
for($i = 0; $i < $count_orderItems; $i++) {
$purchasedSkus[$i] = array(
'ITEM' => $orderItems[$i]['sku'],
'QTY' => number_format($orderItems[$i]['qty_ordered'],0), // no decimals
'AMT' => number_format($orderItems[$i]['price'],2) // 2 decimal places
'DCNT' => number_format(abs($orderItems[$i]['discount_amount']),2) */
);
}
return $purchasedSkus;
}
/**
* Get the Universal Data (JSON) Object for Commission Junction.
* This object contains the order details passed on to Commission Junction for reporting purposes
* on the Checkout Success / Order Confirmation page.
* Notes:
* - CID, TYPE AND CURRENCY are hard coded
* @param string $orderId
* @return JSON object Universal Data Object for Commission Junction $json_masterTmsUdp
*/
public function getCommissionJunctionUdo($orderId) {
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$udo = array();
$udo['CID'] = 'XXXX';
$udo['TYPE'] = 'XXXX';
$udo['CURRENCY'] = 'USD';
$udo['OID'] = $orderId;
$udo['DISCOUNT'] = number_format(abs($order->discount_amount),2);
$order_coupon_code = $order->coupon_code;
if(!is_null($order_coupon_code) && !empty($order_coupon_code)) {
$udo['COUPON'] = $order_coupon_code;
}
$udo['PRODUCTLIST'] = self::_getOrderProductsList($order);
if(Mage::getModel('core/cookie')->get('aff_commissionjunction') == 'cjafflx') {
$udo['FIRECJ'] = "TRUE";
}
else {
$udo['FIRECJ'] = "FALSE";
}
$masterTmsUdo['CJ'] = $udo;
$json_masterTmsUdo = json_encode($masterTmsUdo);
return $json_masterTmsUdo;
}
}
JS文件模板
<script> var MasterTmsUdo = { 'CJ' : { 'CID': '123', 'TYPE': '123', 'DISCOUNT' : '5.00', 'OID': 'SAMPLE_OID', 'CURRENCY' : 'USD', 'COUPON' : 'SAVE20', 'FIRECJ' : 'xxxx', PRODUCTLIST : [ { 'ITEM' : 'ABC', 'AMT' : '1.00', 'QTY' : '3' }, { 'ITEM' : 'ABC', 'AMT' : '5.00', 'QTY' : '1' } ] } }; </script>
答案 0 :(得分:1)
这似乎是解决这个问题的一种不好的方法,但从我可以推断的,他们希望你在success.phtml
的顶部做这样的事情:
<?php require_once "path/to/commissionjunction.php" ?>
<script>var MasterTmsUdo = <?php echo CommissionJunction::getCommissionJunctionUdo($this->getOrderId()); ?></script>
<强>更新强>
我刚才意识到这是一个帮手类。假设模块已正确配置config.xml并在Helper
目录中包含该文件,这应该可行 - 没有像require_once
那样的原始示例。
<script>var MasterTmsUdo = <?php echo Mage::helper('commissionjunction')->getCommissionJunctionUdo($this->getOrderId()); ?></script>