Author Topic: Sort by Category is Useless - Bug?  (Read 8605 times)

duncan12

  • Jr. Member
  • **
  • Posts: 76
Sort by Category is Useless - Bug?
« on: October 09, 2015, 23:41:23 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9648
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Sort by Category is Useless - Bug?
« Reply #1 on: October 09, 2015, 23:53:18 pm »
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()

Code: [Select]
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

Code: [Select]
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Mx150

  • Beginner
  • *
  • Posts: 7
Re: Sort by Category is Useless - Bug?
« Reply #2 on: October 14, 2015, 18:58:25 pm »
GREAT  :o  GJC Web Design perfekt!

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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Sort by Category is Useless - Bug?
« Reply #3 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 should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

wicko

  • Jr. Member
  • **
  • Posts: 73
    • Graphic and web design
Re: Sort by Category is Useless - Bug?
« Reply #4 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 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. 

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.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9648
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Sort by Category is Useless - Bug?
« Reply #5 on: December 04, 2015, 17:28:08 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

wicko

  • Jr. Member
  • **
  • Posts: 73
    • Graphic and web design
Re: Sort by Category is Useless - Bug?
« Reply #6 on: December 04, 2015, 17:51:23 pm »
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.

raydekker

  • Beginner
  • *
  • Posts: 24
  • A beginner
Re: Sort by Category is Useless - Bug?
« Reply #7 on: February 23, 2016, 05:02:01 am »
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:
Code: [Select]
echo $category->images[0]->displayMediaThumb("",false); with:
Code: [Select]
$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):
Code: [Select]
$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

  • Jr. Member
  • **
  • Posts: 73
    • Graphic and web design
Re: Sort by Category is Useless - Bug?
« Reply #8 on: April 06, 2016, 15:11:41 pm »
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.

Rune Rasmussen

  • Jr. Member
  • **
  • Posts: 161
  • Is the stable release stable?
    • SYNTAX ERROR
  • VirtueMart Version: Latest ;)
Re: Sort by Category is Useless - Bug?
« Reply #9 on: May 30, 2016, 16:30:23 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 - http://www.syntaxerror.no
Norske nettløsninger og integrasjoner, CONSIGNOR EDI, Mamut ordreimport og produkteksport, kortbetaling og faktura m.m.

Norsk Joomla! - Norwegian Translation Team - http://www.norskjoomla.no

doc_denis

  • Beginner
  • *
  • Posts: 34
Re: Sort by Category is Useless - Bug?
« Reply #10 on: June 04, 2016, 10:33:41 am »
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

  • Jr. Member
  • **
  • Posts: 293
Re: Sort by Category is Useless - Bug?
« Reply #11 on: June 23, 2016, 16:49:24 pm »
Maybe in 3.0.18? ;)

panoss

  • Jr. Member
  • **
  • Posts: 97
  • A beginner
Re: Sort by Category is Useless - Bug?
« Reply #12 on: January 21, 2017, 14:13:35 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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9648
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Sort by Category is Useless - Bug?
« Reply #13 on: January 21, 2017, 22:47:11 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

panoss

  • Jr. Member
  • **
  • Posts: 97
  • A beginner
Re: Sort by Category is Useless - Bug?
« Reply #14 on: January 22, 2017, 10:03:53 am »
Thanks it works fine!
Virtuemart 3.2.4 on Joomla! 3.8.0