Google联盟与Magento 1.7的整合

时间:2012-09-19 18:41:26

标签: magento pixel affiliate

所以也许你们可以在这里帮助我,我试图整合谷歌跟踪像素为他们的谷歌联盟计划。我在这里使用以下代码http://www.studio1909.com/2009/10/16/google-affiliate-network-conversion-tracking-pixel-magento-ecommerce/但是,在谷歌来回使用之后,对于可配置产品的上述链接代码打印数据的方式并不那么激动。

<!--Start Google Affiliate Integration-->

<?php 
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);

$order = Mage::getModel('sales/order')->load($lastOrderId);
foreach ($order->getAllItems() as $item) {
        $productArray[] = array(
                "product_sku" => $item->getSku(),
                "product_magento_id" => $item->getProductId(),
                "product_name" => $item->getName(),
                "product_qty" => $item->getQtyOrdered(),
                "product_price" => $item->getPrice(),
                "product_discount_amount" => $item->getDiscountAmount(),
                "product_row_price" => $item->getPrice() - $item->getDiscountAmount(),
                 );

        };
?>

<?php
$_totalData = $order->getData();

$_subtotal = $_totalData['subtotal'];

$_orderID = $_totalData['increment_id'];

?>

<img src="https://clickserve.cc-dt.com/link/
order?vid=KVENDORID&oid=<?php echo "$_orderID"; ?>&amt=<?php echo "$_subtotal"?>&prdsku=<?php foreach ($productArray as $key) {echo $key['product_sku']."^";}; 
?>&prdnm=<?php foreach ($productArray as $key) {echo $key['product_name']."^";};    
?>&prdqn=<?php foreach ($productArray as $key) {echo $key['product_qty']."^";};    
?>&prdpr=<?php foreach ($productArray as $key) {echo $key['product_price']."^";};
?>&prcatid=<?php foreach ($productArray as $key) {echo "your-product^";};
?>" width=1 height=1>

<!--End Google Affiliate Integration-->

这是最终结果

<!--Start Google Affiliate Integration-->

<img src="https://gan.doubleclick.net/gan_conversion?advid=MYID&event_type=transaction&oid=10000XXXX&amt=19.0000&fxsrc=USD&prdsku=DVT2756CH CHAR M^DVT2756CH CHAR M^&prdnm=DaVinci 1952 In Charcoal T-Shirt^DaVinci 1952 In Charcoal T-Shirt^&prdqn=1.0000^1.0000^&prdpr=19.0000^0.0000^&prcatid=4425^4427^" width=1 height=1>

<!--End Google Affiliate Integration--> 

所以问题是有一种方法可以编辑上面的代码,所以它只是在没有简单产品的情况下回应主要的可配置产品。

谢谢!

1 个答案:

答案 0 :(得分:0)

查看此内容的一个好地方是显示订单商品的模板: app/design/frontend/base/default/template/sales/order/items.phtml

并且循环的代码是:

<?php $_items = $_order->getItemsCollection(); ?>
<?php $_index = 0; ?>
    <?php $_count = $_items->count(); ?>
<?php foreach ($_items as $_item): ?>
<?php if ($_item->getParentItem()) continue; ?>

因此,这可能是获得所需资源的好方法。