Magento Checkout 成功页面产品价格和 SKU 检索

发布于 2024-09-27 12:09:32 字数 134 浏览 2 评论 0原文

我想将佣金连接添加到我的客户站点,因为他们询问每个产品的 SKU 和价格。在确认页面/成功页面之后,我们只需要传递这些值。但在这里我如何获得所有产品详细信息。包括sku,价格我需要通过。有没有办法分别获取每个产品的详细信息。

谢谢 苏雷什

I want to add Commission junction to my client site, in that they asked for each product sku's and price. After the confirmation page/ success page only we need to pass thes values. But here how i can get all the product details. Including sku, price i need to pass. Is there any way to get each product details separately.

Thanks
Suresh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枕花眠 2024-10-04 12:09:32

是的,你是对的@leek

,但是如果你想使用 CJ 添加高级设置,那么请遵循此方法。

<!-- Start of CJ Integration Part -->
<?php
    $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
    $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getSingleton('sales/order'); 
    $order->load($lastOrderId);
    $_totalData =$order->getData(); 
    $_sub = $_totalData['subtotal'];//USD ==> global_currency_code,base_currency_code order_currency_code
    // Incase if it is simple do this ==> https://www.emjcd.com/u?AMOUNT= $_sub; 
    //print_r($order); print_r($_totalData);

    $_order   = $this->getOrder();
    $allitems = $order->getAllItems();
    $index    = 1;
    $cjData   = "";//Needed format ==> &ITEM1=3214sku&AMT1=13.49&QTY1=1&ITEM2=6577sku&AMT2=7.99&QTY2=2&
    foreach($allitems as $item)
    {
      $cjData.="&ITEM".$index."=".$item->getSku()."&AMT".$index."=".$item->getPrice()."&QTY".$index."=".$item->getQtyToShip();
      $index++;
    }
?>
<div style="display:none;">
    <img src="https://www.emjcd.com/u?CID=id&OID=<?php echo $this->getOrderId(); ?>&TYPE=type<?php echo $cjData; ?>&CURRENCY=USD&METHOD=IMG" height="1" width="20"> 
</div>
<!-- End of CJ Integration Part -->

它工作得很好。

Yeah you are right @leek

But if you want to add advanced setup with CJ then follow this method.

<!-- Start of CJ Integration Part -->
<?php
    $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
    $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getSingleton('sales/order'); 
    $order->load($lastOrderId);
    $_totalData =$order->getData(); 
    $_sub = $_totalData['subtotal'];//USD ==> global_currency_code,base_currency_code order_currency_code
    // Incase if it is simple do this ==> https://www.emjcd.com/u?AMOUNT= $_sub; 
    //print_r($order); print_r($_totalData);

    $_order   = $this->getOrder();
    $allitems = $order->getAllItems();
    $index    = 1;
    $cjData   = "";//Needed format ==> &ITEM1=3214sku&AMT1=13.49&QTY1=1&ITEM2=6577sku&AMT2=7.99&QTY2=2&
    foreach($allitems as $item)
    {
      $cjData.="&ITEM".$index."=".$item->getSku()."&AMT".$index."=".$item->getPrice()."&QTY".$index."=".$item->getQtyToShip();
      $index++;
    }
?>
<div style="display:none;">
    <img src="https://www.emjcd.com/u?CID=id&OID=<?php echo $this->getOrderId(); ?>&TYPE=type<?php echo $cjData; ?>&CURRENCY=USD&METHOD=IMG" height="1" width="20"> 
</div>
<!-- End of CJ Integration Part -->

Its worked perfectly.

并安 2024-10-04 12:09:32

留意这样的事件

<config>
    <global>
        <events>
            <sales_order_place_after>
                <observers>
                    <yourmodule_order_place_after>
                        <class>yourmodule/observer</class>
                        <method>onSalesOrderPlaceAfter</method>
                    </yourmodule_order_place_after>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

接下来,您需要一些东西来处理事件。

app/code/local/Yourcompany/Yourmodule/Model/Observer.php

<?php

class Yourcompany_Yourmodule_Model_Observer {

    public function onSalesOrderPlaceAfter($observer) {
        $order = $observer->getOrder();
        /* @var $item Mage_Sales_Model_Order_Item */
        foreach ($order->getItemsCollection() as $item) {
            // Do something with $item here...
            $name = $item->getName();
            $price = $item->getPrice();
            $sku = $item->getSku();
        }
    }

}

查看数据库表“sales_flat_order_item”或执行 var_dump($item->debug ()) 查看可用的值类型。由于它是一个平坦的桌子,查找有关产品的更多信息的唯一方法如下:

$product = Mage:getModel('catalog/product')->load($item->getProductId());
$product->getDescription();

Watch for an event like this:

<config>
    <global>
        <events>
            <sales_order_place_after>
                <observers>
                    <yourmodule_order_place_after>
                        <class>yourmodule/observer</class>
                        <method>onSalesOrderPlaceAfter</method>
                    </yourmodule_order_place_after>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

Next, you need something to handle the event.

app/code/local/Yourcompany/Yourmodule/Model/Observer.php

<?php

class Yourcompany_Yourmodule_Model_Observer {

    public function onSalesOrderPlaceAfter($observer) {
        $order = $observer->getOrder();
        /* @var $item Mage_Sales_Model_Order_Item */
        foreach ($order->getItemsCollection() as $item) {
            // Do something with $item here...
            $name = $item->getName();
            $price = $item->getPrice();
            $sku = $item->getSku();
        }
    }

}

See the database table "sales_flat_order_item" or do a var_dump($item->debug()) to see what sort of values are available. As it's a flat table the only way to find more information about a product is like this:

$product = Mage:getModel('catalog/product')->load($item->getProductId());
$product->getDescription();
画尸师 2024-10-04 12:09:32

注意:这不是最好的方法!您应该为此创建一个新的块/模板并通过其他方式传递数据。您也不应该在视图/模板中实例化数据库连接。

话虽如此,这就是我在学习如何覆盖模块/模板/等之前很久就在 Magento 商店上实现 Commission Junction 的方法。

app\design\frontend\enterprise\default\template\checkout\success.phtml

<?php
$orderId       = $this->getOrderId();
$order         = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$orderTotal    = $order->subtotal;
$orderEntityId = $order->entity_id;

$db = Mage::getModel('Core/Mysql4_Config')->getReadConnection();

// Retrieve ordered products
$sql = sprintf("
    SELECT *
    FROM `sales_flat_order_item`
    WHERE (order_id = %d);",
        $orderEntityId
);
$orderedProducts = $db->fetchAll($sql);

// Loop through each product in order
foreach ($orderedProducts as $orderedProduct) {
    $productId = (int) $orderedProduct['product_id'];
    $quantity  = (int) $orderedProduct['qty_ordered'];
}
?>

<!-- Commission Junction -->    
<img src="https://www.emjcd.com/u?AMOUNT=<?php echo $orderTotal; ?>&CID=<INSERT_CID_HERE>&OID=<?php echo $orderId; ?>&TYPE=339032&CURRENCY=USD&METHOD=IMG" height="1" width="20">    
<!-- Commission Junction -->

Note: This is NOT the best method! You should be creating a new block/template for this and pass the data via another means. You should also not ever instantiate a Db connection in the view/template.

With that said - here is how I implemented Commission Junction on a Magento store long before I learned how to override modules/templates/etc.

app\design\frontend\enterprise\default\template\checkout\success.phtml

<?php
$orderId       = $this->getOrderId();
$order         = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$orderTotal    = $order->subtotal;
$orderEntityId = $order->entity_id;

$db = Mage::getModel('Core/Mysql4_Config')->getReadConnection();

// Retrieve ordered products
$sql = sprintf("
    SELECT *
    FROM `sales_flat_order_item`
    WHERE (order_id = %d);",
        $orderEntityId
);
$orderedProducts = $db->fetchAll($sql);

// Loop through each product in order
foreach ($orderedProducts as $orderedProduct) {
    $productId = (int) $orderedProduct['product_id'];
    $quantity  = (int) $orderedProduct['qty_ordered'];
}
?>

<!-- Commission Junction -->    
<img src="https://www.emjcd.com/u?AMOUNT=<?php echo $orderTotal; ?>&CID=<INSERT_CID_HERE>&OID=<?php echo $orderId; ?>&TYPE=339032&CURRENCY=USD&METHOD=IMG" height="1" width="20">    
<!-- Commission Junction -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文