0

我出售承重设备和内衣,我们不希望这两种产品退货(出于健康和安全问题)。我们已经设置好catalog\product\view.phtml检查 isReturnable,如果不是,它会显示一条错误消息。
这只会影响项目详细信息视图。
我还想在单页成功页面上显示此信息。

到目前为止,我尝试使用的功能是:

<?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; ?>

当我尝试(!$items->isReturnable()): ?>时它什么也不返回,而当我尝试时
($items->isReturnable()): ?>它什么也不返回。(应该是不可返回的,并且是可返回的,只是为了测试代码)。

任何帮助表示赞赏。

4

2 回答 2

1

所以你需要覆盖root\app\design\frontend\base\default\template\checkout\success.phtml

模板文件并直接使用上面的代码。

或者

您还可以在类中创建一个函数,例如 isReturnable($orderId) Mage_Checkout_Block_Onepage_Success

但不要修改您需要在本地模块中覆盖的核心块。

[更新]

$items->isReturnable();当您尝试获取项目集合上项目的属性时,代码永远不会返回任何内容,它只会与项目对象一起使用,这应该是

$item->getIsReturnable();

所以你的代码应该看起来像

<?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; ?>
于 2013-12-28T06:58:41.993 回答
0

我最终做了什么:

<?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; ?>
于 2013-12-31T01:35:37.667 回答