Magento checkout success page: If an item in the order is not returnable, display message

StackOverflow https://stackoverflow.com/questions/20808567

  •  22-09-2022
  •  | 
  •  

Question

I sell load bearing equipment and underwear, both of these we don't want returns on (for health & safety issues). We have set up in catalog\product\view.phtml to check for isReturnable and if it isn't, it displays an error message.
This only affects the item detail view.
I would also like to display this information on the onepage sucess page.

So far the function i'm trying to use is:

<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
foreach($items as $item){
$isReturnable = $item->getData('isReturnable');
} 
?>
<?php if (!$items->isReturnable()): ?>
<div class="shipping-message"><?php echo $this->__('Return exceptions apply to an item
in your order.'); ?> <a href="/return-exceptions/">Click here for details</a></div>
<?php endif; ?>

When I try (!$items->isReturnable()): ?> it returns nothing, and when I try
($items->isReturnable()): ?> it returns nothing. (Should be not returnable, and returnable, just to test out the code).

Any help is appreciated.

Was it helpful?

Solution

So you need to override the root\app\design\frontend\base\default\template\checkout\success.phtml

template file and use the above code directly for the same.

OR

You can also create a function e.g. isReturnable($orderId) in class Mage_Checkout_Block_Onepage_Success

but don't modify the core block you need to override in your local module.

[UPDATE]

$items->isReturnable(); code never return anything as you are try to get the property of an item on item collection, It will only worked with item object and this should be

$item->getIsReturnable();

So your code should be looks like

<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
$isReturnable = false;
foreach($items as $item){
    $isReturnable = ($isReturnable)? $isReturnable : $item->getIsReturnable();
} 
?>

<?php if($isReturnable): ?>
    <div class="shipping-message"><?php echo $this->__('Return exceptions apply to an item
    in your order.'); ?> <a href="/return-exceptions/">Click here for details</a></div>
<?php endif; ?>

OTHER TIPS

What I ended up doing:

<?php endif; ?>
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
$hasUnreturnable = false;
foreach($items as $item){
if (!$item->getProduct()->isReturnable()) {
$hasUnreturnable = true;
break;};
} ?>
<?php if ($hasUnreturnable): ?>
<p><div class="shipping-message"><?php echo $this->__('Return exceptions apply to an item in your order.'); ?> <a href="/return-exceptions/">Click here for details</a></div></p>
<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top