VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: CE WebDesign München on October 01, 2012, 10:02:38 AM

Title: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on October 10, 2012, 10:53:02 AM
hi,
on a new VM 2.0.12 installation
still sorting bug when many related products
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: myopicseer 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....
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: myopicseer 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.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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...
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: Joseph Kwan 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.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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?
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: Joseph Kwan 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.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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.
Title: Re: [SOLVED]Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: Milbo on December 17, 2012, 23:20:54 PM
Quote from: gogo123 on November 30, 2012, 00:40:29 AM
[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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München 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';
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: Milbo on November 04, 2013, 14:42:29 PM
This is not a solution. It is just luck that the virtuemart_customfield_id is usually  always later created.
I added now the ordering field for reload, so it should keep the ordering, if you store the product later.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on November 04, 2013, 15:08:01 PM
yes, no good solution, but more than luck,
since all users 'till now have sorted these fields with the virtuemart_customfield_id
and odering is 0 everywhere, so maybe change should be done to new version VM 2.1?
at least for me it will take a long time sorting and saving an order, which is already there...
oh well, guess it has to be now or in some month anyway...
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: Milbo on November 05, 2013, 10:43:23 AM
Quote from: Milbo on November 04, 2013, 14:42:29 PM
I added now the ordering field for reload, so it should keep the ordering, if you store the product later.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on November 05, 2013, 15:59:34 PM
hi and thanks for posting again,
and sorry for still not getting it...
it reloads ordering field? wouldn't that be zero again?
anyway, if it means, I don't have to sort again, it would be wonderful,
so i'm happily awaiting next version (maybe a testversion like 2.0.25 or even 2.1.0beta?)
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on November 16, 2013, 20:29:35 PM
vm 2.0.24a does not fix sorting of customfields and related products.
is this the version, where 'the ordering field for reload' is added?
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on November 19, 2013, 21:37:37 PM
new ordering of customfields works perfect (vm2.0.24b - old ordering remains, thanks!)  :)

new ordering of related products works (vm2.0.24b - old ordering remains, thanks!),
but has 2 issues:

when adding some related products to a new product, on save ordering is reverse.

when adding some related products to existing ones, on save, they get value 0 (or start from 0?),
so the new ones show randomly around 'the first related product of the already existing related products'.
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on November 25, 2013, 11:06:33 AM
vm2.0.24c - ordering of related products not working:
numbers get writen to db ordering fields, but in random order
(not reverse - that was wrong interpretation from my testing in last post)
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on December 14, 2013, 17:17:43 PM
hi,

I just gave it another try and tested the new vm-version, so just for info:

manual sorting of "Related Products" is not working on a fresh installation of j2.5.16 and vm2.0.26

but I can't find the bug,
kind regards
Title: Re: Sort/Order of 'Related products'-problem on VM 2.0.10 update
Post by: CE WebDesign München on October 25, 2014, 16:44:26 PM
Hello,

I'm still having this issue and just stumbled upon someone having it too, http://forum.virtuemart.net/index.php?topic=125693.0 (http://forum.virtuemart.net/index.php?topic=125693.0)
so I'm wondering if sorting of related products per ordering is working for anybody
and we're just missing something?

Best regards