0

i have a check in my checkout to see if a product has the attribute direct delivery set to yes and if so it should display a message. However if there is more than one product in the basket with the attribute set to yes it displays the message more than once. How can i stop the message form displaying more than once?

This is the IF statement i have.

<?php $quote = Mage::getSingleton('checkout/session')->getQuote();
        $cartItems = $quote->getAllVisibleItems();
        foreach ($cartItems as $item)
        {
            $productId = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($productId);
                   if($product->getData('direct_delivery_product')==1){?>

             <div class="direct_message">
             <?php echo 'You have direct delivery products in your shopping cart. This means it may take longer than the standard 2-5 working days to deliver.';?></div>

                <?php unset($_shippingRateGroups["freeshipping"]);

             }

                }
?>
1

Use this:

<?php $quote = Mage::getSingleton('checkout/session')->getQuote();
        $cartItems = $quote->getAllVisibleItems();
        foreach ($cartItems as $item)
        {
            $productId = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($productId);
                   if($product->getData('direct_delivery_product')==1){?>

             <div class="direct_message">
             <?php echo 'You have direct delivery products in your shopping cart. This means it may take longer than the standard 2-5 working days to deliver.';?></div>

                <?php unset($_shippingRateGroups["freeshipping"]);
                break;

             }

                }
?>

Have added a break.

| improve this answer | |
  • thank you. i knew it was something simple. I tried to put a break in put i had it in the wrong place. Thank you – Adam Allen Sep 3 '14 at 8:29
  • Please select this as the correct answer. – Paras Sood Sep 3 '14 at 8:36
  • i tried but it has a timer on it so i had to wait for that to expire. Thank you again – Adam Allen Sep 3 '14 at 8:41
  • oh ok..cheers :) – Paras Sood Sep 3 '14 at 8:42

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.