Product price for a successful Magento Checkout page and SKU refund

I want to add a connection with the Commission to my client site in which they ask each product and price. After the confirmation page / success page, we need to pass the values. But here is how I can get all the product details. Including sku, the price I need to go through. Is there a way to get information about each product separately.

Thanks Suresh

+5
source share
3 answers

Yeah you're right @leek

But if you want to add advanced customization using 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 --> 

It worked perfectly.

+7
source

Watch the 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.

Application / 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 run var_dump($item->debug()) to see what values ​​are available. Since this is a flat table, the only way to find more product information is as follows:

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

Note: This is NOT the best method! You must create a new block / template for this and transfer the data using other means. You should also not create instances of the Db connection in the view / template.

With that said, this is how I implemented Commission Junction in the Magento store long before I learned how to redefine modules / templates, etc.

application \ design \ interface \ enterprises \ 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 --> 
0
source

Source: https://habr.com/ru/post/907218/


All Articles