0

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?

4
  • $item->getProduct()->getSku()? Or maybe preg_replace('/-.*$/', '', $item->getSku());
    – Adi
    Aug 3 '15 at 16:23
  • Unfortunately, the custom options aren't something I can find/replace out. Too many different options. (I wasn't involved in the product setup.) I think I need to do something along the lines of if $item->getParentItem() - but I'm not quite sure. Still working it out.
    – SamC
    Aug 3 '15 at 16:32
  • The $item->getProduct()->getSku() snippet doesn't work either?
    – Adi
    Aug 3 '15 at 16:33
  • ... Actually, that does seem to work. It looked like $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.
    – SamC
    Aug 3 '15 at 17:58
0

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

Cheers

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.