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(
$this->prepareCnd($cnd),
$countOnly
);
// find products with search string in title
$return2 = array();
$cnd->byTitle = "Y";
$return2 = \XLite\Core\Database::getRepo('\XLite\Model\Product')->search(
$this->prepareCnd($cnd),
$countOnly
);
foreach($return2 as $i => $i_value) {
foreach ($return1 as $t => $t_value) {
if ($t_value->product_id == $i_value->product_id) {
unset($return1[$t]);
}
}
}
$return = array_merge($return2, $return1);
if ($orig_countOnly=="1") { // count only
$return = count($return);
}
return $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?