VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sohopros on May 12, 2022, 20:29:53 PM

Title: VirtueMart is not Filtering Products Correctly
Post by: sohopros on May 12, 2022, 20:29:53 PM
Joomla! v3.10.9
VirtueMart v4.0.0

When we log into our site Administrator area for Virtuemart Products, we see the correct number of products. When we interact with the filter system, we can only see a small number of unpublished products. After this, we cannot view any published products. This makes it impossible to edit the products on our site. Clearing our session cookie and logging in again is the only way to see any products (the ones on the first page).

Is this a known issue? is there a fix?
thank you,
Title: Re: VirtueMart is not Filtering Products Correctly
Post by: GJC Web Design on May 17, 2022, 07:33:14 AM
Hi Issac,

have u tried http://dev.virtuemart.net/attachments/download/1314/com_virtuemart.4.0.2.10661.zip ?

Regards
Title: Re: VirtueMart is not Filtering Products Correctly
Post by: sohopros on May 18, 2022, 18:08:42 PM
Yes. We updated to VM 4.0.2 but still have the same problem
Title: Re: VirtueMart is not Filtering Products Correctly
Post by: sandomatyas on May 20, 2022, 10:47:18 AM
same issue in 4.0.2
It might related to the category filter.
In VirtueMartModelProduct.sortSearchListQuery() there is a code part:
if (!empty($virtuemart_category_id )) {
$joinCategory = TRUE;

When I dump $virtuemart_category_id it's
Array
(
    [0] => 0
)

So it might get's the first level categories because my query is like this:

SELECT SQL_CALC_FOUND_ROWS  p.`virtuemart_product_id`, l.product_name, l.slug, l.product_s_desc
FROM `#__virtuemart_products` as p   
LEFT JOIN `#__virtuemart_products_en_gb` as l ON l.`virtuemart_product_id` = p.`virtuemart_product_id`
LEFT JOIN `#__virtuemart_product_categories` as pc ON p.`virtuemart_product_id` = `pc`.`virtuemart_product_id` 
LEFT JOIN `#__virtuemart_categories_en_gb` as cl ON cl.`virtuemart_category_id` = `pc`.`virtuemart_category_id`
LEFT JOIN `#__virtuemart_product_manufacturers` ON p.`virtuemart_product_id` = `#__virtuemart_product_manufacturers`.`virtuemart_product_id` 
LEFT JOIN `#__virtuemart_manufacturers_en_gb` as m ON m.`virtuemart_manufacturer_id` = `#__virtuemart_product_manufacturers`.`virtuemart_manufacturer_id`
WHERE ((l.`product_name` LIKE "%foo%" OR `p`.product_sku LIKE "%foo%" OR l.`slug` LIKE "%foo%" OR l.`product_s_desc` LIKE "%foo%" OR `l`.`metadesc` LIKE "%foo%" OR `p`.product_mpn LIKE "%foo%" OR `category_name` LIKE "%foo%" OR `category_description` LIKE "%foo%" OR `mf_name` LIKE "%foo%")
AND  `pc`.`virtuemart_category_id` IN (402,379,228,224,297,261,251,338,218,385,274,291,330,221,256,369,300,329,239,287,214,312,216,326,242,317,408,324,226,237,259,232,212,306,266,276,347,230,0) )
group by p.`virtuemart_product_id`
group by p.`virtuemart_product_id`
ORDER BY p.`created_on` DESC, p.`virtuemart_product_id` DESC


I put a simple $virtuemart_category_id = array_filter($virtuemart_category_id); before if (!empty($virtuemart_category_id )) { and it solved the problem temporarly
Title: Re: VirtueMart is not Filtering Products Correctly
Post by: GJC Web Design on May 24, 2022, 12:24:47 PM
this was an unintended consequence of the setting "Show products of subcategories"

This is only intended to be used on the Frontend and only recently has there been a non hidden config for this which I guess is why it has only been found.

the fix is done for the next release but in the meantime u can patch with administrator\components\com_virtuemart\models\product.php ~ line 559

new code should be

if(VmConfig::get('show_subcat_products',false) and $isSite){
$catmodel = VmModel::getModel ('category');
$cats = '';
foreach($virtuemart_category_id as $catId){
$childcats = $catmodel->getChildCategoryList(1, $catId,null, null, true);
foreach($childcats as $k=>$childcat){
if(!empty($childcat->virtuemart_category_id)){
$cats .= $childcat->virtuemart_category_id .',';
}
}
$cats .= $catId;
}
$cats = trim($cats,',');
} else {
$cats = implode(',', $virtuemart_category_id);
}


and $isSite has been added