How to get SKU custom options selected for ordering goods programmatically in Magento

I have a product with several user options that customers can select. Examples:

Product: Flower basket of 10 colors (SKU 100) Custom options:

  • Qty red roses: reset from 0 to 10 (each with SKU 200)

  • Qty purple roses: reset from 0 to 10 (each with SKU 300)

  • Qty pink tulips: drop from 0 to 10 (each with SKU 400)

Thus, the customer can build their own basket. However, now I have to export my orders to the warehouse system, and I need to specify the Custom Option SKU with the value (qty). Although I can get the label and value from the Order Item. No SKU.

I get my stuff like this:

$orders = Mage::getModel('sales/order')->getCollection() ->addAttributeToFilter('status', array('eq' => 'processing')); foreach ($orders as $order) { foreach ($order->getAllItems() as $order_item) { $optionsArr = $order_item->getProductOptions(); if (count($optionsArr['options']) > 0) { foreach ($optionsArr['options'] as $option) { $optionTitle = $option['label']; $optionId = $option['option_id']; $optionValue = $option['value']; // no SKU ?!?! } } } } 

Any ideas on how to get an SKU for each custom option selected?

+4
source share
2 answers

Try downloading the product and get a collection of options.

 foreach($order->getAllItems() as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); $options = $product->getProductOptionsCollection(); foreach($options as $option) { echo $option->getSku(); } } 
+4
source

Can you try this way.

 foreach($order->getAllItems() as $_item) { $customOptions = $_item->getProductOptions(); foreach ($customOptions['options'] as $_eachOption) { $objModel = Mage::getModel('catalog/product_option_value')->load($_eachOption['option_value']); print_r($objModel->getData()); } } 
0
source

All Articles