2

I've created a module to track orders, But the order details such as ( Product Name, Image, Size, Color, Quantity) are not displaying in the result page.

I'm getting the shipping address and Price of the product

Code

<?php $order = Mage::registry('current_order');?>
<?php
    $OrderNumber = $order->getIncrementId();
        $getOrder = Mage::getModel('sales/order')->load($OrderNumber);
        $getOrder->getAllVisibleItems();
        $orderItems = $getOrder->getItemsCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('product_type', array('eq'=>'simple'))
        ->load();

    ?>
    <?php
        $order = new Mage_Sales_Model_Order();
        $order_id = $OrderNumber;
        $order->loadByIncrementId($order_id);
        $payment_method = $order->getPayment()->getMethodInstance()->getTitle();
        $formattedPriceSubtotal = Mage::helper('core')->currency($order->getSubtotal(), true, false);
        $formattedPriceShipping = Mage::helper('core')->currency($order->getShippingAmount(), true, false);
        $formattedPriceDiscount = Mage::helper('core')->currency($order->getDiscountAmount(), true, false);
        $formattedPriceTax = Mage::helper('core')->currency($order->getTaxAmount(), true, false);
        $formattedPriceGrandtotal = Mage::helper('core')->currency($order->getGrandTotal(), true, false);
        $_shippingAddress = $order->getShippingAddress();

        foreach($orderItems as $sItem) {
            if($sItem->getProductType() == "simple")
            {
                $orderIdArray[$orderCount] = $this->escapeHtml($this->getIncrementId());
               // code for size and color
                $Get_product= Mage::getSingleton('catalog/product')->load($sItem->getProductId());
                $productSize = $Get_product->getResource()->getAttribute('size')->getFrontend()->getValue($Get_product);
                $productColor =  $Get_product->getResource()->getAttribute('color')->getFrontend()->getValue($Get_product);
                $pItemId = $sItem->getParentItemId();

                $item = Mage::getModel('sales/order_item')->load("$pItemId");

                $qty = intval($item->getQtyOrdered());


    //get Active Product Data
    $nProduct = Mage::getModel('catalog/product')->load($sItem->getProductId());
    $nSku = $nProduct->getSku();


    $obj = Mage::getModel('catalog/product');
    $Parent_product = Mage::getModel('catalog/product')->loadByAttribute('sku','product-sku');
    $formattedPrice = Mage::helper('core')->currency($Parent_product->getPrice(), true, false);
?>
5

$OrderNumber give order increment id not order id that

Use loadByIncrementId() instead of load().

 $getOrder = Mage::getModel('sales/order')->loadByIncrementId($OrderNumber);

You done lot of code,Several time load product model/order object,you need to optimized:

<?php
        $OrderNumber = $order->getIncrementId();
        $getOrder = Mage::getModel('sales/order')->loadByIncrementId($OrderNumber);
        $orderItems= $getOrder->getAllVisibleItems();


        $payment_method = $getOrder->getPayment()->getMethodInstance()->getTitle();
        $formattedPriceSubtotal = Mage::helper('core')->currency($getOrder->getSubtotal(), true, false);
        $formattedPriceShipping = Mage::helper('core')->currency($getOrder->getShippingAmount(), true, false);
        $formattedPriceDiscount = Mage::helper('core')->currency($getOrder->getDiscountAmount(), true, false);
        $formattedPriceTax = Mage::helper('core')->currency($getOrder->getTaxAmount(), true, false);
        $formattedPriceGrandtotal = Mage::helper('core')->currency($getOrder->getGrandTotal(), true, false);
        $_shippingAddress = $order->getShippingAddress();

        foreach($orderItems as $sItem) {
                $Get_product= Mage::getModel('catalog/product')->load($sItem->getProductId());
                $productSize = $Get_product->getResource()->getAttribute('size')->getFrontend()->getValue($Get_product);
                $productColor =  $Get_product->getResource()->getAttribute('color')->getFrontend()->getValue($Get_product);
                $qty = intval($sItem->getQtyOrdered()); // order qty 
                $formattedPrice = Mage::helper('core')->currency($Get_product->getPrice(), true, false);


        }
?>
  • After adding this I'm getting Fatal error: Call to a member function getPrice() on a non-object – Shyam Prakash Apr 25 '16 at 9:56
  • change $Parent_product = Mage::getModel('catalog/product')->loadByAttribute('sku','product-sku'); to $Parent_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$nSku )\; – Amit Bera Apr 25 '16 at 10:11
2

Use below code:

<?php $order = Mage::registry('current_order');?>
<?php
    $OrderNumber = $order->getIncrementId();
        $getOrder = Mage::getModel('sales/order')->loadByIncrementId($OrderNumber)
        $getOrder->getAllVisibleItems();
        $orderItems = $getOrder->getItemsCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('product_type', array('eq'=>'simple'))
        ->load();


        //$order = new Mage_Sales_Model_Order();
        //$order_id = $OrderNumber;
        //$order->loadByIncrementId($order_id);
        $payment_method = $order->getPayment()->getMethodInstance()->getTitle();
        $formattedPriceSubtotal = Mage::helper('core')->currency($order->getSubtotal(), true, false);
        $formattedPriceShipping = Mage::helper('core')->currency($order->getShippingAmount(), true, false);
        $formattedPriceDiscount = Mage::helper('core')->currency($order->getDiscountAmount(), true, false);
        $formattedPriceTax = Mage::helper('core')->currency($order->getTaxAmount(), true, false);
        $formattedPriceGrandtotal = Mage::helper('core')->currency($order->getGrandTotal(), true, false);
        $_shippingAddress = $order->getShippingAddress();

        foreach($orderItems as $sItem) {
            if($sItem->getProductType() == "simple")
            {
                $orderIdArray[$orderCount] = $this->escapeHtml($this->getIncrementId());
               // code for size and color
                $Get_product= Mage::Model('catalog/product')->load($sItem->getProductId());
                $productSize = $Get_product->getResource()->getAttribute('size')->getFrontend()->getValue($Get_product);
                $productColor =  $Get_product->getResource()->getAttribute('color')->getFrontend()->getValue($Get_product);
                $pItemId = $sItem->getParentItemId();

                $item = Mage::getModel('sales/order_item')->load("$pItemId");

                $qty = intval($item->getQtyOrdered());


    //get Active Product Data
    $nProduct = Mage::getModel('catalog/product')->load($sItem->getProductId());
    $nSku = $nProduct->getSku();


    $obj = Mage::getModel('catalog/product');
    $Parent_product = Mage::getModel('catalog/product')->loadByAttribute('sku','product-sku');
    $formattedPrice = Mage::helper('core')->currency($Parent_product->getPrice(), true, false);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.