2

我试图弄清楚以下函数正在检查什么:

  <?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>

 <?php echo $this->__('<strong><a href="%s" onclick="this.target=\'_blank\'">Click here to print</a></strong> an invoice or a copy of your order confirmation.', $this->getPrintUrl()) ?>

success.phtmlMagento 的文件中,“单击此处打印”链接不再显示在感谢页面上。这个功能在哪里?

4

1 回答 1

4

更新:在做了更多研究后,我大大修改了这个答案。


作为记录,它看起来像是getCanPrintOrderMagento 获取对象数据的神奇方法之一。你可以用 设置它的值setCanPrintOrder,如果你之前没有调用过,getCanPrintOrder只会返回null。你也可以通过调用来设置它setData('can_print_order')

看起来它被设置的唯一位置是在方法中的 Onepage 结帐成功块Mage_Checkout_Block_Onepage_Success_prepareLastOrder

protected function _prepareLastOrder()
{
    $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    if ($orderId) {
        $order = Mage::getModel('sales/order')->load($orderId);
        if ($order->getId()) {
            $isVisible = !in_array($order->getState(),
                Mage::getSingleton('sales/order_config')->getInvisibleOnFrontStates());
            $this->addData(array(
                'is_order_visible' => $isVisible,
                'view_order_id' => $this->getUrl('sales/order/view/', array('order_id' => $orderId)),
                'print_url' => $this->getUrl('sales/order/print', array('order_id'=> $orderId)),
                'can_print_order' => $isVisible,
                'can_view_order'  => Mage::getSingleton('customer/session')->isLoggedIn() && $isVisible,
                'order_id'  => $order->getIncrementId(),
            ));
        }
    }
}

_beforeToHtml方法调用哪个,在呈现该页面时将调用该方法。

将字符串拉得更远一点,我们看到can_print_order是由$isVisible变量确定的,并且是由这一行设置的:

$isVisible = !in_array($order->getState(),
    Mage::getSingleton('sales/order_config')->getInvisibleOnFrontStates());

它正在检查订单状态是否是前面可见的状态之一。这些最终设置在config.xml核心 Magento 销售模块的文件中。

<config>
    <global>
        <sales>
            <order>
                <states>
                    <new translate="label">
                        <label>New</label>
                        <statuses>
                            <pending default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </new>
                    ...
                </states>
            </order>
        </sales>
    </global>
</config>

默认情况下,所有状态都是 visible_on_front ,因此除非您更改了它们,或者某些东西覆盖了它们,否则这不应该是您的问题。我会通过转储getCanPrintOrdersuccess.phtml 中的值来仔细检查这一点。

一个 hacky 解决方法是覆盖模板文件并添加

$this->setCanPrintOrder(true);
$this->setCanViewOrder(true);

高于 if 条件的任何位置。或者只是完全删除检查。

于 2013-04-23T20:46:00.670 回答