VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on September 23, 2017, 12:54:56 PM

Title: Which category is the main category?
Post by: sandomatyas on September 23, 2017, 12:54:56 PM
When I get a product object from VirtueMartModelProduct class it has categoryItem array with all of it's categories but I also get a $product->category_name and virtuemart_category_id as 'main' category. I tried to figure out which category is this but as far as I can see it's the first element of categoryItem array and if I check getProductCategoryIds method there isn't any order by part in the query.
So when I assign multiple categories to the product which will be used in the canonical url, etc?
Title: Re: Which category is the main category?
Post by: sandomatyas on January 12, 2018, 17:03:26 PM
something maybe? :)
Title: Re: Which category is the main category?
Post by: jjk on January 13, 2018, 11:17:30 AM
Quote from: sandomatyas on September 23, 2017, 12:54:56 PM
So when I assign multiple categories to the product which will be used in the canonical url, etc?
Always the first category in the 'Product Categories' list of the 'Product Edit' form. If you pick several categories, the ordering of the categories in the 'Product Categories' form field is determined by the ordering in your 'Product Categories' List.
Title: Re: Which category is the main category?
Post by: sandomatyas on January 17, 2018, 11:33:00 AM
Quote from: jjk on January 13, 2018, 11:17:30 AM
Quote from: sandomatyas on September 23, 2017, 12:54:56 PM
So when I assign multiple categories to the product which will be used in the canonical url, etc?
Always the first category in the 'Product Categories' list of the 'Product Edit' form. If you pick several categories, the ordering of the categories in the 'Product Categories' form field is determined by the ordering in your 'Product Categories' List.

I'm not sure.
If you check getProductCategoryIds method the query is:
$q = 'SELECT * FROM `#__virtuemart_product_categories`  WHERE `virtuemart_product_id` = ' . (int)$id;
There is no ORDER BY part, even #__virtuemart_product_categories table has ordering field
Also jQuery chosen plugin, which is used for select categories for the product, doesn't allow drag&drop sorting (select2 does: http://select2.github.io/select2/) so selecting a new 'main category' could be quite uncomfortable process.
Title: Re: Which category is the main category?
Post by: aftertaf on January 17, 2018, 22:53:41 PM
yet the order is kept and modifiable by removing and re-adding categories.

Not trying to be mysterious or unhelpful, just a passing comment I suppose ;)