如何在Magento中以编程方式获取为项目订单选择的自定义选项的SKU

问题描述:

我有一个带有多个自定义选项的产品,客户可以选择.例如:

I have a product with multiple custom option customers can choose. For examples:

产品:10朵花的花篮(SKU 100) 自定义选项:

Product: Flower Basket of 10 flowers (SKU 100) Custom options:

  • 红玫瑰数量:从0下降到10(每个SKU为200)

  • Red roses qty: Drop down with 0 to 10 (each with SKU 200)

紫色玫瑰数量:从0降到10(每个SKU为300)

Purple Roses qty: Drop down with 0 to 10 (each with SKU 300)

粉色郁金香数量:从0降到10(每个SKU为400)

Pink Tulips qty: Drop down with 0 to 10 (each with SKU 400)

这样,客户可以构建自己的购物篮.但是,现在我必须将订单导出到仓库系统,并且需要列出带有值(qty)的自定义选项的SKU.虽然我可以从Order Item获取标签和值.没有SKU.

This way customer can build their own basket. However, now I have to export my orders for warehouse system and I need to list Custom Option's SKU with value(qty). While I can get the label and value from Order Item. There is no SKU.

我正在得到这样的物品:

I am getting my items like so:

$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 ?!?! 
            }
        }

  }

}

有什么想法如何为每个自定义选项获取SKU?

Any ideas how to get the SKU for every Custom Option selected?

尝试加载产品并获取选项集合.

Try loading the product and getting an option collection.

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