Magento – Get SKU for Item with Custom Options

itemsorderssku

I'm adding some tracking code on my order confirmation page. But I'd like it to change what it reports for items with custom options.

Below is what my PHP code looks like now to get the variables (i stripped out the javascript echoes for simplicity). And this works.

But I've got a bunch of items on the site that have custom options, so they're reporting (for example) as three separate skus 12345-red, 12345-green, 12345-blue.

And we'd prefer to strip off the custom option info, and just have the single parent sku of 12345.

$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());

$items = $order->getAllItems();

foreach($items as $item) {
    $_sku = $item->getSku();
    $_itemprice = $item->getPrice();
    $_itemqty = $item->getQtyOrdered();
}

What call do I make instead of $item->getSku(); to get the sku without the custom-options info attached to it?

Best Answer

Try $item->getProduct()->getSku() :)

Cheers

Related Topic