我在将产品添加到我的愿望清单上有问题。当我尝试这样做时,我会收到此PHP错误:

Fatal error: Call to a member function getProduct() on a non-object in /usr/www/users/glnvgv/g4n.eu/e-watches/app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php on line 117

我的Magento安装几乎是新鲜的。我知道,它与URL有点连接,因为错误在这样的URL中:

/index.php/wishlist/index/index/wishlist_id/2/

查看URL中的双索引. 。这不是奇怪吗?并且产品将成功添加到愿望清单(当我从商店打开另一个URL时我收到消息),但我不知道此错误来自哪里。

问候

有帮助吗?

解决方案

我暂时实施了此解决方案:

复制 app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.phpapp/code/local/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php 并替换功能 getTemplate() 使用此代码的第104-123行:

 /**
 * Retrieve block template
 *
 * @return string
 */
public function getTemplate()
{
    $template = parent::getTemplate();
    if ($template) {
        return $template;
    }

    $item = $this->getItem();

    // If $item is it not instance of Mage_Wishlist_Block_Customer_Wishlist_Item_Options
    if ($item instanceof Mage_Wishlist_Block_Customer_Wishlist_Item_Options){
        $data = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());

        if (empty($data['template'])) {
            $data = $this->getOptionsRenderCfg('default');
        }
    }else{
          $data = $this->getOptionsRenderCfg('default');
    }

    return empty($data['template']) ? '' : $data['template'];
}

使替代的最佳方法是制造一个新的模块,并表明我们覆盖了块示例:

其他提示

有关更多详细信息,请参阅@Jruzafa答案。这只是为了提供有关我们如何以“最佳方式”实现这一目标的更多细节,正如他在答案中提到的那样。

这就是您需要在您的 config.xml 文件

文件 : app\code\local\Example\Mymodule\etc\config.xml

<config>
    <global>
        <blocks>
            <wishlist>
                <rewrite>
                    <customer_wishlist_item_options>Example_Mymodule_Block_Customer_Wishlist_Item_Options</customer_wishlist_item_options>
                </rewrite>
            </wishlist>
        </blocks>
    </global>
</config>

现在定义您的 Options.php 像这样。

文件: app\code\local\Example\Mymodule\Block\Customer\Wishlist\Item\Options.php

<?php
class Example_Mymodule_Block_Customer_Wishlist_Item_Options
    extends Mage_Wishlist_Block_Customer_Wishlist_Item_Options
{
    public function getTemplate()
    {
        $template = Mage_Wishlist_Block_Abstract::getTemplate();
        if ($template) {
            return $template;
        }

        $item = $this->getItem();

        // If $item is it not instance of Mage_Wishlist_Block_Customer_Wishlist_Item_Options
        if ($item instanceof Mage_Wishlist_Block_Customer_Wishlist_Item_Options){
            $data = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());

            if (empty($data['template'])) {
                $data = $this->getOptionsRenderCfg('default');
            }
        } else {
              $data = $this->getOptionsRenderCfg('default');
        }

        return empty($data['template']) ? '' : $data['template'];
    }
}

这种方法的一个很小的变化是:

$template = Mage_Wishlist_Block_Abstract::getTemplate();

如您所见,它取代了 parent::getTemplate(); 。这是因为 parent::getTemplate() 将会通知 Mage_Wishlist_Block_Customer_Wishlist_Item_Options::getTemplate() 因此,您将再次获得同样的错误。为了避免我们直接使用真实的父母。

许可以下: CC-BY-SA归因
scroll top