News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Sort by Category is Useless - Bug?

Started by duncan12, October 09, 2015, 23:41:23 PM

Previous topic - Next topic

duncan12

Why is there no checkbox in the menu settings for Category Layout to show products from subcategories?

I have a menu link to a VirtueMart category layout. I have no products in this category. But there are subcategories and I have products in there. But the page shows no products.

By the way, in the VirtueMart back end under Configuration => Product Order Settings, there is an option to sort by Category Name. But, it doesn't do anything as far as I can tell because the Category Layout view does not even show products from multiple categories.

GJC Web Design

Correct - afaik the std. VM doesn't show products from subcats in a cat view

I always use this hack in models/product.php ~ line 330 in the function sortSearchListQuery()

if ($virtuemart_category_id > 0) {
/*GJC add subcat products*/

//$joinCategory = TRUE;
//$where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
$catmodel = VmModel::getModel ('category');
$childcats = $catmodel->getChildCategoryList(1, $virtuemart_category_id,null, null, true);
$cats = $virtuemart_category_id;
foreach($childcats as $childcat){
$cats .= ','.$childcat->virtuemart_category_id;
}
$joinCategory = TRUE;
$where[] = ' `pc`.`virtuemart_category_id` IN ('.$cats.') ';
/*GJC add subcat products*/

} else if ($isSite) {
if (!VmConfig::get('show_uncat_parent_products',TRUE)) {
$joinCategory = TRUE;
$where[] = ' ((p.`product_parent_id` = "0" AND `pc`.`virtuemart_category_id` > "0") OR p.`product_parent_id` > "0") ';
}
if (!VmConfig::get('show_uncat_child_products',TRUE)) {
$joinCategory = TRUE;
$where[] = ' ((p.`product_parent_id` > "0" AND `pc`.`virtuemart_category_id` > "0") OR p.`product_parent_id` = "0") ';
}
}


There's probably better ways -- Max once mentioned a vmsearch plugin called at line 632

if ($this->searchplugin !== 0) {
JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('plgVmBeforeProductSearch', array(&$select, &$joinedTables, &$where, &$groupBy, &$orderBy,&$joinLang));
}


will try one day if I ever find time
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Mx150

GREAT  :o  GJC Web Design perfekt!

Exactly what i need... big thanks to duncan12 aswell for sending me the Link to the post.

Milbo

Added to the model, but without option, just with if(true), so easier to change it, option will come.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

wicko

Adding the code by GJC Web Design is great and shows the products in the first level subcategory. But if you have for instance a group category in your store then a sub group within that then the products will not be viewed in the first level store category. 

Quote from: Milbo on October 14, 2015, 22:53:27 PM
Added to the model, but without option, just with if(true), so easier to change it, option will come.


When you look into this option for future releases I guess you might want the option of how many subcategory levels you look into.
Designing and maintaining Joomla websites since 2007

GJC Web Design

what you would need to do is then run the function $catmodel->getChildCategoryList again within the loop for each returned child cat

could be very heavy on queries
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

wicko

Yes you are right. If too many loops are created then it will only slow things down. Which I guess is why I think you would need to set a level of how far you want to go.
Designing and maintaining Joomla websites since 2007

raydekker

#7
Thank you so much GJC Webdesign!! Works as a charm!
Just spend 5 hours modifying php's etc.
What I found a great addition to this is a random image for each category!
It uses an image from a product in the category (and subcategory thanks to GJC) as a category image...
So I just use CSVI Pro to import my products + category tree + product images and voila, done!

copy components/com_virtuemart/sublayouts/categories.php to templates/[yourtemplate]/html/com_virtuemart/sublayouts/categories.php
edit the file and replace:echo $category->images[0]->displayMediaThumb("",false); with:
$productModel = VmModel::getModel('product');
$prod_in_category = $productModel->getProductListing(false, 1, false, true, true, true, $category->virtuemart_category_id);
$sel = array_rand($prod_in_category);
$productModel->addImages($prod_in_category[0],1);
if(!empty($prod_in_category[0]->images[0])){
    echo $prod_in_category[0]->images[0]->displayMediaThumb("",false);
} else {
    echo $category->images[0]->displayMediaThumb("",false);
}


Or with the following to just display a product image (not random = less memory usage):

$productModel = VmModel::getModel('product');
$prod_in_category = $productModel->getProductListing(false, 1, false, true, true, true, $category->virtuemart_category_id);
$productModel->addImages($prod_in_category[0],1);
if(!empty($prod_in_category[0]->images[0])){
    echo $prod_in_category[0]->images[0]->displayMediaThumb("",false);
} else {
    echo $category->images[0]->displayMediaThumb("",false);
}



wicko

My products are not showing in parent category any more. Has this been replaced in VM update? I have this as template override but are not working anymore.
Designing and maintaining Joomla websites since 2007

Rune Rasmussen

Quote from: wicko on December 04, 2015, 16:54:31 PM
Adding the code by GJC Web Design is great and shows the products in the first level subcategory.
But only for the first sub category, not from several second level categories ...

T.ex. if having the following structure, it will only display products from "Black" if you are viewing "Coffee":
Coffee (first level)
- Black (second level)
- Espresso (second level)
- Various (second level)

Right? So I prefer the old solution over at http://forum.virtuemart.net/index.php?topic=97874.msg346289#msg346289

And yes @wicko, core hacks are removed on updates as the file is replaced with the original from latest pack. :)
Rune Rasmussen - https://www.syntaxerror.no/

Norwegian Translation Team

doc_denis

hello, this is exactly what I wanted to do.
Thank you for sharing GJC Web Design !

@milbo, I think this should be native with a button in admin (view product of subcategories on category : yes / no)
VM chosen himself as the first category is a category by default, and it is disadvantageous when exporting to Google Shopping or market place.
Since we can not define the default category of a product, this solution is a good alternative, leaving the product in subcategory

the seo url change (its really different)  ...my french example  ;) :
before : /wine/mychampagnebootle.html
after : /wine/champagne/mychampagnebottle.html
and the product mychampagnebottle.html is visible on /wine.html   good !

thank you for everything
Denis, French user.

sandomatyas


panoss

#12
Quote from: Milbo on October 14, 2015, 22:53:27 PM
Added to the model, but without option, just with if(true), so easier to change it, option will come.

I have VM 3.0.18.
I want products from children categories of the current category, to be shown.
e.g: current category bikes, with sub categories road bikes and mountain bikes:
bikes
--road bikes (with products: rb1, rb2)
--mountain bikes (with products: mb1, mb2)

I want this as result:
rb1 rb2 mb1 mb2
Is there some option I should check?
Virtuemart 3.2.4 on Joomla! 3.8.0

GJC Web Design

it isn't a config option .. you need to change the true to a false in

if(true){
            $where[] = ' `pc`.`virtuemart_category_id` = ' . $virtuemart_category_id;
         } else {

line 369 ->  administrator\components\com_virtuemart\models\product.php
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

panoss

Virtuemart 3.2.4 on Joomla! 3.8.0