View Single Post
Old 08-18-2022, 04:07 AM
xcartdev2 xcartdev2 is offline

Advanced Member
Join Date: Nov 2011
Posts: 43

Default Front end (Customer) product search logic and search results - worse than X-Cart 4?

Just having a tinker with X-Cart 5.4 code. As far as I see in the code for customer searches:
  • to start with the page loads with only an item count.
  • then there is another 'getData' function call to get a list of products without any of their associated details from other tables (like title and description)
  • then this is looped through to get things like name and brief description only within the displayed product list
I have a client where the search results are re-ordered so products where the search substring in in the Title are returned before products where the substring is in the description/SKU.

I've hacked it like this:
PHP Code:
protected function getData(\XLite\Core\CommonCell $cnd$countOnly false)

$orig_countOnly $countOnly;
$countOnly false;
$return1 = \XLite\Core\Database::getRepo('\XLite\Model\Product')->search(
// find products with search string in title
$return2 = array();
$cnd->byTitle "Y";

$return2 = \XLite\Core\Database::getRepo('\XLite\Model\Product')->search(

$return2 as $i => $i_value) {
                foreach (
$return1 as $t => $t_value) {
                    if (
$t_value->product_id == $i_value->product_id) { 

$return array_merge($return2$return1);

        if (
$orig_countOnly=="1") { // count only
$return count($return);


But that's two calls to the database instead of one.

In X-Cart 4 the basic query called everything and then you could manipulate or get data from the array very easily. So if I wanted to have a page title that said:

Search for 'apple': cheapest product is Apple Ipod, costs $800

That was pretty easy. In X-Cart 5 it looks like a lot of coding will be needed or have I missed something?
Verion 4.7.12
Reply With Quote