3

I'm facing problem, need to show product ids separated with # on Magento success page

like:

shop_product_ids =‘#234#w475xk#5402#’;

How to handle it on Magento 1.9 success page. Can anybody let me know how to make this loop and properly format ids separated with #

5

Go to the success page template app/design/frontend/base/default/template/checkout/success.phtml (for base theme)

Aafter <?php if ($this->getOrderId()):?> add:

    <?php
    $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
    $items = $order->getAllVisibleItems(); // use getAllItems for ALL items, including simple products from configurable
    $productsIds = array();
    /** @var Mage_Sales_Model_Order_Item $item */
    foreach ($items as $item) {
        $productsIds[] = $item->getProductId(); // for SKU: $item->getProduct()->getSku();
    }
    $productsIdsString = implode('#', $productsIds);
    $productsIdsString = 'shop_product_ids = \'#' . $productsIdsString . '#;';

    echo '<h1>' . $productsIdsString . '</h1>'; // or do something else
    ?>

Items during checkout:

checkout

Result in debug:

debug

Result on success page:

success page

  • goos answer Siarhey Uchukhlebau,can u tell me what debugger you have use – Amit Bera Apr 3 '16 at 5:25
  • 2
    @AmitBera xDebug with phpStorm – Siarhey Uchukhlebau Apr 3 '16 at 8:56
  • very good explaination @SiarheyUchukhlebau – Baby in Magento Apr 11 '16 at 9:43

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.