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

Which category is the main category?

Started by sandomatyas, September 23, 2017, 12:54:56 PM

Previous topic - Next topic

sandomatyas

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?


jjk

#2
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.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

sandomatyas

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.

aftertaf

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 ;)