Question

i have a problem with adding products to my wishlist. When i try to do it i get this php error:

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

My Magento installation is near-fresh. I know, that it's connected with url a little bit, because error is in url like this:

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

Look at double index in the url. Isn't it strange? And product is added to wishlist successfully (i got message when i open another url from my shop), but i don't know where this error comes from.

Greetings

Was it helpful?

Solution

I have temporarily implemented this solution:

Copy app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php to app/code/local/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php and replace function getTemplate() line 104 - 123 with this code:

 /**
 * 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'];
}

The best way to make the override would be making a new module and indicating that we override the block example:

OTHER TIPS

Please refer @jruzafa answer for more details. This is just to provide more details on how we can achieve this in "best way" as he mentioned in his answer.

This is how you need to rewrite this block in your config.xml file

File : 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>

Now Define your Options.php like this.

File: 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'];
    }
}

A small change in this approach is this line :

$template = Mage_Wishlist_Block_Abstract::getTemplate();

As you can see it replaces parent::getTemplate(); . This is because parent::getTemplate() will call Mage_Wishlist_Block_Customer_Wishlist_Item_Options::getTemplate() and hence you will again get same error. In order to avoid that we are using the real parent class directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top