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?
$item->getProduct()->getSku()
? Or maybepreg_replace('/-.*$/', '', $item->getSku());
if $item->getParentItem()
- but I'm not quite sure. Still working it out.$item->getProduct()->getSku()
snippet doesn't work either?$item->getProduct()->getSku();
&$item->getSku();
were showing the same thing. But we can chalk that up to user error (i.e. I didn't clear the cache when testing earlier.) Write that up into an actual answer, and I'll accept it.