News:

Looking for documentation? Take a look on our wiki

Main Menu

showing all products in sidebar even when searching for products

Started by welrachid, September 17, 2018, 11:06:46 AM

Previous topic - Next topic

welrachid

J!3.8.12
VM: 3.2.14
Hi guys..
First of all, i dont know if this is a bug or a feature of virtuemart.

My problem is this:
Im using a layout of mod_virtuemart_category (template override) to show all categories and their products in a sidebar. This works great, gives good overview of page and everything. Today i wanted to add search functionality because sometimes it can be nice to actually search for something. The problem is however that the search functionality sets some INTERNAL fields in the VM objects that means that my product $ids in sidebar is collapsed to only show products that is fits the search keywords.

Im using this code in mod_virtuemart_category

foreach ($categories as $category) {
$active_menu = '';
$caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
// $nemprint_products = $productModel->getProductsInCategory ($category->virtuemart_category_id); // my first try that actually works WITHOUT search functionality
// $nemprint_products = $productModel->getProductListing(TRUE, FALSE,TRUE, TRUE,FALSE, TRUE, $category->virtuemart_category_id, FALSE, 0); // when studying getProuctsInCategory I Found This Function
$nemprint_products = $productModel->sortSearchListQuery (FALSE,  $category->virtuemart_category_id, FALSE, FALSE); // // when studying getSearchListQuery i found this function
// var_dump($nemprint_products);
$cattext = $category->category_name;
//if ($active_category_id == $category->virtuemart_category_id) $active_menu = 'class="active"';
if (in_array( $category->virtuemart_category_id, $parentCategories)) $active_menu = 'active';
}


So the question is... am i doing something wrong?
Should i code my own module to make sure that i have a "clean" search query

Thanks
Wel
Best regards,
Wel

Milbo

just one parameter in sortSerachListQuery is a problem

Quote from: welrachid on September 17, 2018, 11:06:46 AM
foreach ($categories as $category) {
$active_menu = '';
$caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
$nemprint_products = $productModel->sortSearchListQuery (FALSE,  $category->virtuemart_category_id, FALSE, FALSE); // // when studying getSearchListQuery i found this function

[/quote]

Just use for this $category->virtuemart_category_id just 0.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

Hi Milbo
Thanks for your time. That doesnt make sense, but i tried it anyway. all categories are empty.
see result here: https://prnt.sc/kw8zi0

What i want to achive is this: https://prnt.sc/kw907j

This is only possible if i iterate over all categories and then fetch products from within each category. Thats why i dont think $category->virtuemart_category_id = 0 makes sense in this case.
It seems like there is some internal thing going on that sets some filters up that i cannot bypass in any of the calls i make.. ??
Best regards,
Wel

Milbo

Quote from: welrachid on September 19, 2018, 16:06:44 PM
Thats why i dont think $category->virtuemart_category_id = 0 makes sense in this case.
It seems like there is some internal thing going on that sets some filters up that i cannot bypass in any of the calls i make.. ??

category id = 0 means "all" categories. 0 is the root.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

Hi Milbo.
Thanks for your time. I gave up.

For everyone else that might have the same problem as me. I just made my own calls to the db. This might be more expensive, but i've already spent too much time with this small issue.


foreach ($categories as $category) {
$active_menu = '';
$caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
// $nemprint_products = $productModel->getProductsInCategory ($category->virtuemart_category_id);

$wsy_query = $wsy_db->getQuery(true);
$wsy_query->select($wsy_db->quoteName(array('virtuemart_product_id')));
$wsy_query->from($wsy_db->quoteName('#__virtuemart_product_categories'));
$wsy_query->where($wsy_db->quoteName('virtuemart_category_id') . '='. $wsy_db->quote($category->virtuemart_category_id));
$wsy_query->order('ordering ASC');
$wsy_db->setQuery($wsy_query);
$nemprint_product_ids = $wsy_db->loadObjectList();
$nemprint_products = array();
foreach($nemprint_product_ids as $nemprint_product_id){
$nemprint_products[] = $productModel->getProduct ($nemprint_product_id->virtuemart_product_id, TRUE, TRUE, TRUE, 1,0);
}
$cattext = $category->category_name;
//if ($active_category_id == $category->virtuemart_category_id) $active_menu = 'class="active"';
if (in_array( $category->virtuemart_category_id, $parentCategories)) $active_menu = 'active';
}



/Wel
Best regards,
Wel