0

I would like to add the custom attribute i created (delivery) to show on the shipping method section of the checkout page.

I have the following code working but when more than one item is being purchased it just lists all the delivery times next to each other. like 3 days 5 days 1 week

<?php $cartItems = Mage::getSingleton('checkout/session')
          ->getQuote()
          ->getAllItems();
    foreach ($cartItems as $item) {
        $ean = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getAttributeText('delivery');
        echo $ean; 
    }?>

I would then want to pull the product name so What im looking for is

Product Name:Delivery Time or if multiple items Product Name:Delivery Time Product Name:Delivery Time

1 Answer 1

1

Couldn't you just do:

<?php $cartItems = Mage::getSingleton('checkout/session')
      ->getQuote()
      ->getAllItems();
foreach ($cartItems as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
    $ean = $product->getAttributeText('delivery');
    $name =  $product->getName();
    echo $name . ':' . $ean; 
}?>
3
  • Thank you! it works.. Quick question, it currently lists items as NAME:DELIVERY NAME: DELIVERY. is it possible to add a line break in the code so its in list style?
    – Michael
    Aug 17, 2015 at 7:27
  • This is probably not the best style, (bypassing magento theme formatters), but since it's so simple, I would just output html directly in that foreach. i.e. echo '<div class="myclass">' . $name . ':' . $ean .'</div>'; or echo $name . ':' . $ean . '<br>';
    – baku
    Aug 17, 2015 at 14:20
  • how use i this code to add extra field in check out page ..?@baku Apr 15, 2020 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.