VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: MKI-Miro on January 27, 2018, 18:22:01 PM

Title: Select product detail in menu
Post by: MKI-Miro on January 27, 2018, 18:22:01 PM
Hi

When I want to create link to product detail in Joomla Menu I dont see all product (only first X products).

Joomla 3.8.3
Virtuemart 3.2.8

Is it bug ?

Kind Regards
Cibuľa Miroslav
Title: Re: Select product detail in menu
Post by: Studio 42 on January 28, 2018, 15:57:47 PM
When I want to create link to product detail should only display 1 product.
What are the X products ?
Title: Re: Select product detail in menu
Post by: MKI-Miro on January 28, 2018, 16:02:24 PM
menu-> edit menu item (product deail layout)-> here is dropdown "Select product" and here i dont see all products
Title: Re: Select product detail in menu
Post by: Studio 42 on January 28, 2018, 16:17:20 PM
This is simple, enable VM debug and you see why :
Message
Quote1 vmdebug 2 Languages, default shoplanguage (VmConfig::$jDefLang): fr_fr fr-FR Selected VM language (VmConfig::$vmlang): fr_fr fr-FR SEF: fr
2 vmdebug vmTime: time to load config: 0.00191092491149902
3 vmdebug getVendorId manager
4 vmdebug Active vendor 0 1
5 vmdebug Set 476 to 1
6 vmdebug My Memory Limit in Bytes 536870912
7 vmdebug vmTime: sortSearchQuery products: : 0.031574010848999
8 vmdebug Better not to display more than 700 products

SO currently it's not possible, because virtuemart do not use a modal with search but try to display all products from Db and this is not possible(imagine you have 100000 products).
You need to check with Max if he want to rewrite this and use a modal or an ajax search, so you can filter and display some products from db only

Note that it's another problem with current solution. If a day you have more then 700 product and had 700 before, you can loose the curent value in some case.
Max and dev team, can you fix this ?
Title: Re: Select product detail in menu
Post by: Milbo on January 30, 2018, 23:45:36 PM
yeh, someone need to enhance the field "product" in /administrator/components/com_virtuemart/fields. Of course that would be nice.
Title: Re: Select product detail in menu
Post by: Studio 42 on January 31, 2018, 03:07:13 AM
Can you not use related product search as field and use ajax ?
Title: Re: Select product detail in menu
Post by: Milbo on January 31, 2018, 10:27:20 AM
It can be used as pattern. It can be even used for the ajax call, maybe. But someone needs to write the js for it. this is the first request for this feature. The reason is simple, the feature was never meant for big shops. The idea of this feature is only usefull for shops with less than 10 products, actually mainly for shops with one product. They dont want a product listing.

MKI-Miro use a profiler, joomla debug or vmdebug vmtime to measure the loading/rendering of your page. There are tests, which show that a lot time is spent for the joomla menu. So adding a lot products per menuitem will slow down your store. So to have an ajax for the product field would be nice, but more interesting for other uses of the product field.
Title: Re: Select product detail in menu
Post by: MKI-Miro on January 31, 2018, 11:11:34 AM
I have few categories where only product exists so thats why I really need it. Currently I solved it be replacing ID in db.
Title: Re: Select product detail in menu
Post by: Studio 42 on January 31, 2018, 11:53:58 AM
Quote from: MKI-Miro on January 31, 2018, 11:11:34 AM
I have few categories where only product exists so thats why I really need it. Currently I solved it be replacing ID in db.
You can redirect on couting product.
If count product ==1 then redirect.
This trick was used in Virtuemart 1 in the core
Title: Re: Select product detail in menu
Post by: Studio 42 on January 31, 2018, 16:27:39 PM
I quick checked in the field, why using model here?
This dont need so many complexity.
in file JOOMLAROOT/administrator/components/com_virtuemart/fields/product.php

private function _getProducts() {
if (!class_exists('VmModel'))
require(VMPATH_ADMIN . DS . 'helpers' . DS . 'vmmodel.php');
$productModel = VmModel::getModel('Product');
$productModel->_noLimit = true;
if(vmAccess::manager('managevendors')){
$productModel->virtuemart_vendor_id = 0;
}
$products = $productModel->getProductListing(false, false, false, false, true,false);
$productModel->_noLimit = false;
$i = 0;
$list = array();
foreach ($products as $product) {
$list[$i]['value'] = $product->virtuemart_product_id;
$list[$i]['text'] = $product->product_name. " (". $product->product_sku.")";
$i++;
}
return $list;
}

replace with
private function _getProducts() {
$db = JFactory::getDbo();
        $query = 'select p.virtuemart_product_id AS value,IFNULL(l.product_name, fb.product_name) AS text from #__virtuemart_products as p
LEFT JOIN #__virtuemart_products_'.VMLANG.' as l ON l.virtuemart_product_id = p.virtuemart_product_id';
$query .= ' LEFT JOIN #__virtuemart_products_en_gb as fb ON fb.virtuemart_product_id = p.virtuemart_product_id AND l.virtuemart_product_id is NULL';
$query .= ' order by text ASC LIMIT 0,10000';
        $db->setQuery($query);
        $result = $db->loadObjectList();
return $result;
}


Note that i dont implemented correctly the fallback here, but this queries run in 0.05 secondes in a good shared server with 3245 results(and display fast)
Title: Re: Select product detail in menu
Post by: MKI-Miro on January 31, 2018, 16:35:04 PM
I have to do it or virtuemart dev team will implement it?
Title: Re: Select product detail in menu
Post by: Studio 42 on January 31, 2018, 16:51:25 PM
I hope Team change it,
But you can try this code, simply do a backup before of this file.
Title: Re: Select product detail in menu
Post by: Milbo on February 01, 2018, 11:45:06 AM
lol...
man, the point is not the model. the point is that you MUST use a limit. You just set a limit of 10 000. I could also just do that in the model. I can also just simple set a simple boolean, which disables the hardcoded limit.

There is a reason for the hardcoded limit.
Title: Re: Select product detail in menu
Post by: Studio 42 on February 01, 2018, 13:32:16 PM
Max the problem is that you load many datas to get the product name and id only, so you cannot load this in 0.05 secondes, try to load 5000 products and check how much time the current Vm core solution need.
I had exactly same problem for a customer to load 1200 categories to get the tree, you need more then 8 secondes first time, so i had to write a new category module.
I constantly change my own code, to get better result in my extensions myself, it's not to blame the team.
Title: Re: Select product detail in menu
Post by: Milbo on February 05, 2018, 10:36:01 AM
No, the problem is to write a dropdown with so many entries. the next shop has 50k products. It does not work that way.
Title: Re: Select product detail in menu
Post by: MKI-Miro on February 05, 2018, 17:55:18 PM
What about just to make input field for product id? simple and quick to do
Title: Re: Select product detail in menu
Post by: Studio 42 on February 05, 2018, 18:23:13 PM
Quote from: MKI-Miro on February 05, 2018, 17:55:18 PM
What about just to make input field for product id? simple and quick to do
In this case users cry because they have to go in Vm list to find the ID.
Title: Re: Select product detail in menu
Post by: Milbo on February 06, 2018, 17:01:01 PM
Actually, Miro. there is a lot better solution for your problem. I think.

We could add a feature, which directly displays the productdetail, if only one product was found. That is also handy for the search. We can add a hidden config, so people can disable it.
Title: Re: Select product detail in menu
Post by: MKI-Miro on February 06, 2018, 17:09:02 PM
yes thats also solution :)
Title: Re: Select product detail in menu
Post by: Studio 42 on February 06, 2018, 17:40:34 PM
Quote from: Milbo on February 06, 2018, 17:01:01 PM
Actually, Miro. there is a lot better solution for your problem. I think.

We could add a feature, which directly displays the productdetail, if only one product was found. That is also handy for the search. We can add a hidden config, so people can disable it.
A simple count  product = 1 > Joomla redirect to this product works.
Title: Re: Select product detail in menu
Post by: Milbo on February 09, 2018, 10:03:39 AM
Exactly and it makes a lot more sense for anyone.