【问题标题】:Magento checkout success page: If an item in the order is not returnable, display messageMagento结帐成功页面:如果订单中的商品不可退货,则显示消息
【发布时间】:2013-12-27 22:19:57
【问题描述】:

我销售承重设备和内衣,我们不希望对这两种产品进行退货(出于健康和安全问题)。我们在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-&gt;isReturnable()): ?&gt; 时,它什么也不返回,而当我尝试
($items-&gt;isReturnable()): ?&gt; 时,它什么也不返回。 (应该是不可返回的,并且是可返回的,只是为了测试代码)。

感谢任何帮助。

【问题讨论】:

    标签: php magento orders


    【解决方案1】:

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

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

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

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

    [更新]

    $items-&gt;isReturnable(); 代码永远不会返回任何内容,因为您试图获取项目集合中项目的属性,它只适用于项目对象,这应该是

    $item-&gt;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; ?>
    

    【讨论】:

    • 我已经过度挖掘核心文件(没有编辑它们),但没有从我发布的代码中返回任何有效代码。
    【解决方案2】:

    我最终做了什么:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 2017-04-12
      相关资源
      最近更新 更多