0

I have a list_search.phtml when searching It goes to list_search.phtml and I wrote some functionality for that which is fine, I included this in catalogsearch.xml:

 <reference name="content">
 <block type="catalog/product_list" name="search_result_list" template="catalog/product/list_search.phtml">
 </reference>

the location of list_search.phtml:

app\design\frontend\enterprise\default\template\catalog\product\list_search.phtml

I want to search iphone-4 and then see all related products for that so I included this one too:

<block type="enterprise_targetrule/catalog_product_list_related" name="catalog.product.related" as="relatedProducts" template="targetrule/catalog/product/list/related.phtml">
                <action method="setColumnCount"><columns>3</columns></action>
                <block type="enterprise_targetrule/catalog_product_item" name="catalog.product.related.item" template="targetrule/catalog/product/list/related/item.phtml" />
            </block>

and in list_search I am calling the block:

<?php  $itemBlock = $this->getChildHtml('relatedProducts');?>

fortunately I made sure and now I have this block which I wanted:

\app\design\frontend\enterprise\default\template\targetrule\catalog\product\list\related.phtml

and I have problem here that

Fatal error: Call to a member function getData() on a non-object in /var/www/app/code/core/Enterprise/TargetRule/Block/Catalog/Product/List/Abstract.php on line 148

the collection which I have in list_search is $this->getLoadedProductCollection(); and it is different than the collection of related products so it cause me problem do you know how I can solve this problem?

the line is this:

$behavior = $this->getProduct()->getData($this->_getPositionBehaviorField());

the problem is that $this->getProduct is NULL

I guess the solution should be to set the collection on this line: $this->getChildHtml('relatedProducts'); something like

$this->getChildHtml('relatedProducts')->setData('collection',$collection) I dont know how to do that!

I have read links to help me but I don't know what to do in my case link1 link2

Thank you

1

The reason for your error is that the file mentioned is only designed to work on a single product page where there is one product in the registry that it can work with.

What you will need to do is work with the block to get the current item in the collection and not simply the getProduct call as this will not work.

0

I ran into a very similar problem - trying to get the related products HTML via an API request. The API would pull per sku, so only one product per request.

I was erroring out on the same line as Nickool:

## app/code/core/Enterprise/TargetRule/Block/Catalog/Product/List/Abstract.php
## Line 148

$behavior = $this->getProduct()->getData($this->_getPositionBehaviorField());

In this class,

$this->getProduct()

calls this method:

## app/code/core/Enterprise/TargetRule/Block/Catalog/Product/List/Abstract.php
## Line 63

public function getProduct()
{
    return Mage::registry('product');
}

which pulls the product from the registry - not from the $this object. That's what tripped me up...

So, prior to calling line 148 that is erroring out, the product who's related products are desired needs to be set to the Magento registry.

Mage::register( 'product', $product );

NOTE: Changing the product in the registry could potentially affect other elements of the page rendering. The implications of this potential side effect could vary from page to page, use case to use case. But to be safe, it might be worth the extra effort to implement something like this:

/* store currently registered product */
$currentProductRegistry = Mage::registry('product');

...

/**
  * Obtain other products related products
  *   Example from original post
  */
$itemBlock = $this->getChildHtml('relatedProducts');

I know this is an old post, but tripped me up so much I wanted to share with others who might make this simple mistake as well.

...

/* reset registry */
if( $currentProductRegistry ) {
    Mage::register('product', $currentProductRegistry);
} else {
    Mage::unregister('product');
}

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.