0

So I'm trying to show some html code on my order confirmation page IF the products in the cart belong to a certain category. To clarify there are only two different categories and the user can only chose one of them, so all the products in the cart will be part of the same category.

I have tried this:

<?php
   $categoryId = 426;
$quote = Mage::getSingleton('checkout/session')->getQuote();
?>
     <?php if($quote->hasCategoryId($categoryId)): ?>
          <p>show text blah blah </p>
     <?php endif; ?>

But the text doesn't show even though all the products in the cart are from this category. Any ideas how to do this or what I did wrong?

1
  • add your magento version tag
    – Priyank
    Apr 5, 2017 at 15:47

1 Answer 1

-1

I got it working with this, in case it helps anybody else:

  <?php
    $allowcheckout=true;
    $cart = Mage::getModel('checkout/cart')->getQuote();
    foreach ($cart->getAllItems() as $item) {
    $categorytId = $item->getCategoryId();
    $category = Mage::getModel('catalog/product')->load($categoryId);
                     if($category->getAllowcheckout()==426){
                     $allowcheckout=true;
                     break;
                    }
                   }
        ?>
  <?php if($allowcheckout): ?>
       <p>test</p>
    <?php endif; ?>
1
  • You should click the accepted answer button on your answer since it solved your problem. That will cause the question to show up as resolved. Apr 19, 2017 at 17:22

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.