1

How to get Orderd Product name,sku,qty etc in order collection Magento

<?php
class MPS_Ordermail_Model_Observer{ 
    public function Test($event){
        //do something
        Mage::log("Testing success...........",null,'custom.log');
        $ordershippeddays = 7; // number of days you want
        $fromDate = gmdate("Y-m-d H:i:s", gmmktime(0, 0, 0, gmdate("m"), gmdate("d") - $ordershippeddays, gmdate("Y")));
        $toDate = gmdate("Y-m-d H:i:s", gmmktime(23, 59, 59, gmdate("m"), gmdate("d"), gmdate("Y")));

         $ordercollection = Mage::getResourceModel('sales/order_item_collection')
        ->addAttributeToSelect('order_id')
        ->addAttributeToSelect('created_at')
        ->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate))
        ->load();

        count($ordercollection);


        foreach ($ordercollection as $orderkey => $ordervalue) {
        $eid = $ordervalue->getOrderId();   
        $order = Mage::getModel("sales/order")->load($eid);
        Mage::log("Testing success...........");
        Mage::log($customerorderid = $order->getIncrementId());
        Mage::log($customeremailid = $order->getCustomerEmail());
        Mage::log($customername   = $order->getCustomerFirstname());
        Mage::log($order->getPayment()->getMethodInstance()->getTitle());
        Mage::log($order->getStatusLabel());
        $billingAddress = $order->getBillingAddress();
        $shipping_address = $order->getShippingAddress();
        Mage::log($billingAddress->getStreetFull());
        Mage::log($billingAddress->getRegion());
        Mage::log($billingAddress->getCountry());
        Mage::log($billingAddress->getPostcode());
        Mage::log($billingAddress->getTelephone());
        Mage::log($shipping_address->getStreetFull());
        Mage::log($shipping_address->getRegion());
        Mage::log($shipping_address->getCountry());
        Mage::log($shipping_address->getPostcode());
        Mage::log($shipping_address->getTelephone());
        Mage::log($orderTotalValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = ''));

        }





    } 
}

1 Answer 1

2

Inside foreach ($ordercollection as $orderkey => $ordervalue) { add this

foreach ($ordervalue->getAllVisibleItems() as $item) {
    $sku = $item->getSku();
    $name = $item->getName();
    $qty = $item->getOrderedQty();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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