Author Topic: Sort/Order of 'Related products'-problem on VM 2.0.10 update  (Read 10646 times)

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Sort/Order of 'Related products'-problem on VM 2.0.10 update
« on: October 01, 2012, 10:02:38 am »
Hi, I need help to solve the following problem:

fresh install J 2.5.7 & VM 2.0.8c: Sorting of 'Related products' works
fresh install J 2.5.7 & VM 2.0.10: Sorting of 'Related products' works
fresh install J 2.5.7 & VM 2.0.8c and then update to VM 2.0.10:
Sorting of 'Related products' does not work (random order on refresh frontend).
Deleting and re-adding of related products, reset tables-tool & update to VM 2.0.11d: no effect

How (and where) is this order saved/stored
and did it change between these versions?
Any idea, how I can update a 2.0.8 Site and make it work again?
Thanks for hints and help!

For future-wishlist: Sorting of 'Related products' per drag'n'drop (like product-images) ;)


EDIT: found 2 related posts:
http://forum.virtuemart.net/index.php?topic=107961.msg361035#msg361035
http://forum.virtuemart.net/index.php?topic=106570.msg361339#msg361339
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #1 on: October 02, 2012, 18:10:36 pm »
Hi, here is the difference I found in the database:

Table = suffix_virtuemart_product_customfields and Table-Structure:
VM 2.0.8c: Field=custom_param, Type=text, NULL=yes
VM 2.0.10: Field=custom_param, Type=varchar, NULL=no

if changed back in the VM 2.0.10-Table to the VM 2.0.8-setting,
you get the wanted order in BE and reverse(!) order in FE, hm...
(oh well, at least it can be sorted somehow that way... ;)

I don't know, if it is a good idea to change back the structure
because there must have been reasons for the new settings.

I hope this helps to find a stable solution,
please post any tipp what else can be tested,
meanwhile I'll try to learn more about database fields...
 
Just for info, this is what I tested:
VM 2.0.8c: wanted order in BE and wanted order in FE.
VM 2.0.10: wanted order in BE and different but stable order in FE, if 2-4 Related Products.
VM 2.0.10: wanted order in BE and random order in FE, if 5 or more Related Products.
=> so it's no update problem (this strange behavior misled me to say so, sorry)
and here's the tested order for 5 or more Related Products added to "Drill":
1 Hand Shovel, 2 Ladder, 3 Nice Saw, 4 Hammer, 5 Chain Saw, 6 Circular Saw
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #2 on: October 10, 2012, 10:53:02 am »
hi,
on a new VM 2.0.12 installation
still sorting bug when many related products
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

myopicseer

  • Beginner
  • *
  • Posts: 25
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #3 on: November 13, 2012, 14:32:44 pm »
I would think that can be modified within default_relatedproducts.php (administrator/components/com_virtuemart/models), which appears to be the method that queries the DB and forms the array that is sent to the caller, which is ultimately in default_relatedproducts.php (components/com_virtuemart/views/productdetails ... which can be used within an html folder of your default site template as an override).

You would need to determine which id field in the db sorts the order of the related products in the backend, and ensure that that id is used to sort the products in the frontend.  I would guess that the frontend related items are being sorted by their actual product id, and not by a related product id.  The solution to this is to edit default_relatedproducts.php, above.  (I don't have the time to investigate it further, but I would look at the database and determine the name of the field that gives the unique id for related products/custom fields....

myopicseer

  • Beginner
  • *
  • Posts: 25
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #4 on: November 13, 2012, 14:37:10 pm »
BTW, look for this method " public function getProductCustomsFieldRelatedProducts ($product) { "  in the default_relatedproducts.php.  That is where the data is queried from the DB and assembled into an array, it seems to me.

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #5 on: November 13, 2012, 21:01:46 pm »
thank you very very much for looking into this,

maybe you already found the problem, because if I search for "relate", there is no

"administrator/components/com_virtuemart/models/default_relatedproducts.php"

only
"components/com_virtuemart/views/productdetails/default_relatedproducts.php"
and
"components/com_virtuemart/views/productdetails/default_relatedcategories.php"

I downloaded and searched here too:
com_virtuemart.2.0.0_extract_first
com_virtuemart.2.0.4_extract_first
com_virtuemart.2.0.6_extract_first
com_virtuemart.2.0.8c_extract_first
com_virtuemart.2.0.12_extract_first

Could you please attach that file here and tell me the vm-version
or point me to the right file, if I got something wrong?
Maybe it was added and quickly got lost somewhere on the way,
so only regular updater still have it...
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #6 on: November 28, 2012, 11:21:37 am »
found function getProductCustomsFieldRelatedProducts
in administrator/components/com_virtuemart/models/customfields.php
line 780 for VM 2.0.8c and line 787 for VM 2.0.14 (so NO file is missing)

If customfields.php in VM 2.0.14 is replaced with customfields.php from VM 2.0.8c (where FE+BE is ok)
still random order in FE, so problem seems not to be in this file?

BE is ok, though last added product goes first now - no drag'n'drop, so a lot of planing+saving

no changes in components/com_virtuemart/views/productdetails/default_relatedproducts.php

setting for testing: Configuration-> Product Order Settings-> Default product sort order-> Ordering
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

Joseph Kwan

  • Advanced
  • Full Member
  • *****
  • Posts: 2344
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #7 on: November 28, 2012, 22:03:32 pm »
Look like there is no specified order for related product. This will be a new feature, not a bug fix.
Joomla/VM Upgrade Services. Problems with your migration? We can help.
Custom extensions to VM. Performance Tuning. Template modifications and advices.
Pay service to make VM work according to your needs. Your Joomla/VM solutions are just a PM away.

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #8 on: November 29, 2012, 00:17:11 am »
Thank you very much for looking at this,

the order for related products worked fine for me from vm2.0.2 to 2.0.8c:
same order in frontend as in backend,
sorted by field virtuemart_custom_id in table _virtuemart_product_customfields

and in function getProductCustomsFieldRelatedProducts
in administrator/components/com_virtuemart/models/customfields.php (line 787)
there is:   $query .= ' and is_cart_attribute = 0 order by virtuemart_custom_id'; (line 793)

and I don't see why it is random now,
sorting is important for most shops, real or virtual, in my honest opinion

so if it is not a bug, it is at least an issue, I'd say?
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

Joseph Kwan

  • Advanced
  • Full Member
  • *****
  • Posts: 2344
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #9 on: November 29, 2012, 07:03:21 am »
I don't see the point of argument over whether this is a bug or a feature.
From a brief review of the code, I don't see any hint that assigns an order for the list of related products. So this feature seems not in the design. In that case, a random order is understandable.
Joomla/VM Upgrade Services. Problems with your migration? We can help.
Custom extensions to VM. Performance Tuning. Template modifications and advices.
Pay service to make VM work according to your needs. Your Joomla/VM solutions are just a PM away.

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #10 on: November 30, 2012, 00:40:29 am »
[SOLVED] this works for me (VM 2.0.14):

if you need same order in FrontEnd as in Backend for Related Products,
add Related Products in Backend (in reversed order, VM puts newest first now!)

and in administrator/components/com_virtuemart/models/customfields.php
in function getProductCustomsFieldRelatedProducts:

replace   (line 793 for VM 2.0.14):
   $query .= ' and is_cart_attribute = 0 order by virtuemart_custom_id';
with:
   $query .= ' and is_cart_attribute = 0 order by virtuemart_customfield_id';
   
   
order by virtuemart_custom_id does not make sense,
unless you want kind of random order,
because there the id of the product is stored,
to which the Related Products are added,
so if you add 5 Related Products to product "1"
you get 5 times "1" in that column.
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10073
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED]Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #11 on: December 17, 2012, 23:20:54 pm »
[SOLVED] this works for me (VM 2.0.14):

and in administrator/components/com_virtuemart/models/customfields.php
in function getProductCustomsFieldRelatedProducts:

replace   (line 793 for VM 2.0.14):
   $query .= ' and is_cart_attribute = 0 order by virtuemart_custom_id';
with:
   $query .= ' and is_cart_attribute = 0 order by virtuemart_customfield_id';

perfect, thank you very much. Added. btw, the whole function is deleted in vm2.1
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #12 on: November 02, 2013, 16:39:19 pm »
new bug (VM 2.0.24 J2.5.14):
add some products to Related Products in BE,
when saving the ordering changes.

this ordering is shown in FE ok,
but now you can't control it BE


I tried

replace   (line 795 for VM 2.0.14):
   $query .= ' and is_cart_attribute = 0 order by ordering';
with:
   $query .= ' and is_cart_attribute = 0 order by virtuemart_customfield_id';
   
in administrator/components/com_virtuemart/models/customfields.php
function getProductCustomsFieldRelatedProducts

but this only changes FE ordering - please help,
regards
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #13 on: November 03, 2013, 17:38:09 pm »
when adding products to "Related Products",
new rows are created in table "_virtuemart_product_customfields",
but their values in colum 'ordering' are all "0".

if I change numbers there, "Related Products" get sorted by these numbers BE+FE,
so it would work, but value in colum 'ordering' is resetted to '0' on 'save' each time,
that's why ordering is random right now
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
« Reply #14 on: November 04, 2013, 14:34:33 pm »
this works for me (and fixes sorting of custom fields too!!!)
(aslong as no value is stored in 'ordering', but maybe this fix can be left as proposed, as the virtuemart_customfield_id number is in wanted order anyway?):


in administrator/components/com_virtuemart/models/customfields.php

replace (BE-order: line 415 / VM 2.0.24):
      Where `virtuemart_product_id` =' . $virtuemart_product_id . ' order by field.`ordering` ASC';
with:
      Where `virtuemart_product_id` =' . $virtuemart_product_id . ' order by field.`virtuemart_customfield_id` ASC';

replace (FE-order: line 795 / VM 2.0.24):
      $query .= ' and is_cart_attribute = 0 order by ordering';
with:
      $query .= ' and is_cart_attribute = 0 order by virtuemart_customfield_id';
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO