0

I am trying to get a list of all the shipping methods a customer (by ID) has chosen for each order.

So if a customer has made 3 orders, I want to return:

  1)  Check / Money
  2)  Credit card
  3)  Check / Money

(For example)

I am getting lost in the resource models and collections...
I tried this:

$orderCollection = Mage::getResourceModel('sales/order_collection')
        ->addFieldToSelect('*')
        ->addFieldToFilter('customer_id', $customer->getId())
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->setOrder('created_at', 'desc');

    foreach ($orderCollection as $_order){
        $shipping_method = $_order->getShippingMethod(); 
    }

But its not working

1

You need to do it in below way:

$orderCollection = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customer->getId())
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
->setOrder('created_at', 'desc');

foreach ($orderCollection as $_order){
    $shipping_method[] =  $_order->getShippingMethod();
}
$unique_shipping_method = array_unique($shipping_method);
echo "<pre>";
print_r($unique_shipping_method);

And then you can iterate array $unique_shipping_method using foreach loop.

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.