Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

extending / overriding product search

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 12-18-2015, 01:20 PM
 
codegrunt codegrunt is offline
 

Member
  
Join Date: Dec 2015
Posts: 10
 

Default extending / overriding product search

Howdy. I am currently looking at extending / replacing the customer product search function on the front end. I believe this starts here:

classes/XLite/Controller/Customer/Search.php

Code:
protected function doActionSearch() { [...] \XLite\Core\Session::getInstance()->{$this->getAdvancedPanelCellName()} = array_intersect(array_keys($productsSearch), array_values($advancedParams)); \XLite\Core\Session::getInstance()->{$sessionCell} = $productsSearch; $this->setReturnURL($this->buildURL('search', '', array('mode' => 'search'))); }

with the bulk of the control logic actually happening in the view:

classes/XLite/View/ItemsList/Product/Customer\Search.php

Code:
protected function getData(\XLite\Core\CommonCell $cnd, $countOnly = false) { return \XLite\Core\Database::getRepo('\XLite\Model\Product')->search( $this->prepareCnd($cnd), $countOnly ); }

The template that gets loaded appears to be:

skins/default/en/product/search/body.tpl

Which has a direct call to the class that does the actual search:

Code:
<widget class="\XLite\View\ItemsList\Product\Customer\Search" />

Based on that, is the only way to change the core search functionality to override the above template? I may be doing it incorrectly but so far I have not been able to get any obvious behavioural changes by extending "classes/XLite/View/ItemsList/Product/Customer/Search.php" in my testing module.
__________________
multiple versions (4 and 5)
Reply With Quote
  #2  
Old 12-21-2015, 12:54 PM
 
codegrunt codegrunt is offline
 

Member
  
Join Date: Dec 2015
Posts: 10
 

Default Re: extending / overriding product search

Hoping a bump spikes someone's interest. . .

=)

I am feeling pretty stumped here as I can't seem to sort out how to get my module's search view to load.

If I want to override this view:

Code:
classes/XLite/View/ItemsList/Product/Customer/Search.php

and have a dev called "MyDev" and a module called "MyModule", where should the overridden class go?

I have tried placing it here:

Code:
classes/XLite/Module/MyDev/MyModule/View/ItemsList/Product/Customer/Search.php

But it does not get loaded.

Any help appreciated. I've looked through the docs but did not see any examples specific to search results that seemed to apply.

Do you have to create a "A[object name].php" stub at every branch of the tree for lower level files to be loaded?
__________________
multiple versions (4 and 5)
Reply With Quote
  #3  
Old 12-22-2015, 10:12 AM
 
codegrunt codegrunt is offline
 

Member
  
Join Date: Dec 2015
Posts: 10
 

Default Re: extending / overriding product search

In case this helps anyone else, if you want to see what files are actually being loaded during execution (so as to find what file you need to replicate or change), you can do this by temporarily adding some code to the autoloader class (starts at line 101):

includes/autoloader.php

Code:
public static function __lc_autoload($class) { $class = ltrim($class, '\\'); list($prefix) = explode('\\', $class, 2); // Workaround for Doctrine 2 proxies if ( ($prefix === LC_NAMESPACE || $prefix === LC_NAMESPACE . 'Abstract') && false === strpos($class, \Doctrine\Common\Persistence\Proxy::MARKER) ) { // start temp logging of file loading if($fp=fopen(__DIR__.'/../debug.log','a')) { fputs($fp,'['.date('YmdHis').']'.static::$lcAutoloadDir . str_replace('\\', LC_DS, $class) . '.php'."\n"); fclose($fp); } // end logging include_once (static::$lcAutoloadDir . str_replace('\\', LC_DS, $class) . '.php'); } }
__________________
multiple versions (4 and 5)
Reply With Quote
  #4  
Old 12-23-2015, 01:47 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: extending / overriding product search

It depends on the desired changes.

\XLite\Controller\Customer\Search is the class that implements the logic to change search filters and pass the data to the widget class.

\XLite\View\ItemsList\Product\Customer\Search is the widget class that contains/calls all the logic to retrieve the list of products to be shown on the page.

Quote:
Originally Posted by codegrunt
is the only way to change the core search functionality to override the above template?

No, most likely you don't have to edit the template.

Quote:
Originally Posted by codegrunt
I may be doing it incorrectly but so far I have not been able to get any obvious behavioural changes by extending "classes/XLite/View/ItemsList/Product/Customer/Search.php" in my testing module.

How did you extend it? Did you use the "implements \XLite\Base\IDecorator" construction?
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #5  
Old 12-23-2015, 10:39 AM
 
codegrunt codegrunt is offline
 

Member
  
Join Date: Dec 2015
Posts: 10
 

Default Re: extending / overriding product search

Thanks for the response Alex.

I did use the Decorator interface but I initially was extending the abstract class "ACustomer.php" instead of "Search.php". If I extend the Search.php view my class seems to take precedence. However, if I extend the abstract class ACustomer.php view, my class does not appear to take precedence.

Code:
namespace XLite\Module\MyDev\MyModule\View\ItemsList\Product\Customer; class Search extends \XLite\View\ItemsList\Product\Customer\ACustomer implements \XLite\Base\IDecorator { protected function getData(\XLite\Core\CommonCell $cnd, $countOnly = false) { return false; } }

What I expect from the above is that all searches will return no results due to me overriding the getData() call. The behaviour is that it has no effect (searches work normally). If I change the extends directive to instead use Search.php, it does what I expect and returns no data.

Why does the ACustomer version get ignored?
__________________
multiple versions (4 and 5)
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:13 AM.

   

 
X-Cart forums © 2001-2020