2

在 Magento 1.5 上,我注意到电子商务跟踪不适用于许多网站。我查看了下面的 /core/Mage/GoogleAnalytics/Block/Ga.php 代码:

protected function _getOrdersTrackingCode()
{
    $orderIds = $this->getOrderIds();
    if (empty($orderIds) || !is_array($orderIds)) {
        return;
    }
    $collection = Mage::getResourceModel('sales/order_collection')
        ->addFieldToFilter('entity_id', array('in' => $orderIds))
    ;
    $result = array();
    foreach ($collection as $order) {
        if ($order->getIsVirtual()) {
            $address = $order->getBillingAddress();
        } else {
            $address = $order->getShippingAddress();
        }
        $result[] = sprintf("_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);",
            $order->getIncrementId(), Mage::app()->getStore()->getFrontendName(), $order->getBaseGrandTotal(),
            $order->getBaseTaxAmount(), $order->getBaseShippingAmount(),
            $this->jsQuoteEscape($address->getCity()),
            $this->jsQuoteEscape($address->getRegion()),
            $this->jsQuoteEscape($address->getCountry())
        );
        foreach ($order->getAllVisibleItems() as $item) {
            $result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
                $order->getIncrementId(),
                $this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()),
                null, // there is no "category" defined for the order item
                $item->getBasePrice(), $item->getQtyOrdered()
            );
        }
        $result[] = "_gaq.push(['_trackTrans']);";
    }
    return implode("\n", $result);
}

此代码测试成功页面上是否有 orderId,如果有,则继续读取交易信息。我注意到的是:

  $orderIds = $this->getOrderIds();

无论如何都不会返回数据。我不知道如何进行。

4

0 回答 0