Author Topic: Which category is the main category?  (Read 572 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 191
Which category is the main category?
« 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?

sandomatyas

  • Jr. Member
  • **
  • Posts: 191
Re: Which category is the main category?
« Reply #1 on: January 12, 2018, 17:03:26 pm »
something maybe? :)

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3298
  • using Matomo instead of Google Analytics
Re: Which category is the main category?
« Reply #2 on: January 13, 2018, 11:17:30 am »
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

  • Jr. Member
  • **
  • Posts: 191
Re: Which category is the main category?
« Reply #3 on: January 17, 2018, 11:33:00 am »
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:
Code: [Select]
$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

  • Jr. Member
  • **
  • Posts: 198
    • sO couture
  • VirtueMart Version: 3.2.14
Re: Which category is the main category?
« Reply #4 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 ;)
Webmaster for my wife (link in my profile ;)
Extensions / plugins : POSForWebshops, TemplatecreatorCK ,MaximenuCK, and PageBuilderCK, VM BatchEdit Pro, VM CustomFilters Pro, Awocoupon Pro, slogin, supersaas,  among other things...
Joomla! 3.8.6//VM 3.2.14//PHP7.0.18 & mariadb 10.1.22 on Debian
big up to notepad++!!!!