4

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

  • double index isn't strange as it denotes indexController and indexAction respectively. I have the same problem and i'm figuring out – Shathish Dec 19 '13 at 6:57
  • Please consider looking at /app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php on line 117. I'm currently working with EE, Could you post the whole function this line belongs to ? – dagfr Dec 19 '13 at 15:57
11

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:

  • 2
    Same problem for me here - this fix worked great, thanks. – BrynJ Apr 23 '14 at 12:36
  • This will definitely remove above issue. But in "best way" approach, we need to have a small change in above answer. To see that, please refer this answer – Rajeev K Tomy May 5 '16 at 11:26
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.