【问题标题】:Display Shopping Cart items in phtml Contactform (Magento)在 phtml Contactform (Magento) 中显示购物车项目
【发布时间】:2015-10-23 10:20:50
【问题描述】:

您好,我刚登录是为了问这个问题。我尝试使用该论坛中给定的答案来解决该问题,但有些东西不起作用。 我只想将购物车中的商品添加到 magento kontactform 中的文本字段中。我使用 form.phtml

我尝试显示侧边栏购物车:

  <label for="comment">Artikel</label>
            <div class="input-box">
                <textarea name="comment" id="comment" title="Artikel" class="required-entry input-text" cols="5" rows="3">

                <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkout/cart/sidebar/default.phtml')->toHtml(); ?>
                </textarea>
            </div>
        </li>
        <li class="wide">
            <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
            <div class="input-box">
                <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"></textarea>

但我收到此错误:

致命错误:在 a 上调​​用成员函数 getProduct() 非对象在 /www/htdocs/xxxxx/magento/app/design/frontend/base/default/template/checkout/cart/sidebar/default.phtml 上线 29

第 29 行是:

$isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();

所以有人可以帮助我,对不起我残酷的英语:-)

【问题讨论】:

  • 使用这个代码 getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/sidebar.phtml')->toHtml( ); ?>
  • 另外你需要注释 if condition "getIsNeedToDisplaySideBar()):?>"
  • 嗨,谢谢你,但它仍然不起作用,我是一个 php 新手,所以也许我做错了什么。我添加代码code getIsNeedToDisplaySideBar()):?> getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout /‌​cart/sidebar.phtml')->toHtml(); ?> code
  • 但我总是得到一个空白框。我尝试使用和不使用“标签

标签: magento php


【解决方案1】:

实际上,您正在使用 core/template 块,这就是您收到错误的原因,因此请使用 checkout/cart_sidebar 块。请用以下代码替换您的代码。

你的代码

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkout/cart/sidebar/default.phtml')->toHtml(); ?>

替换为

<?php echo $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/minicart/items.phtml')->toHtml(); ?>

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2019-09-18
    相关资源
    最近更新 更多