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

My solution: custom fields in alphabetical order

Started by clanessa, December 20, 2012, 18:50:20 PM

Previous topic - Next topic

clanessa

Hi everyone!

Maybe I've found a temporary solution to order (front-end side) the custom fields of child products.
I run virtuemart 2.0.14 under joomla 2.5.8

All the changes I've done in php code are in file /my_site/plugins/vmcustom/stockable/stockable.php
I've "simply" re-ordered the data while loading the select lists.


EDIT stockable.php

before line 567
--------------------------------------------
foreach ($options as $key => $val) {
--------------------------------------------

insert following code
--------------------
sort($options);
-----------------------

substitute lines 743-753
--------------------
// Repopulate the following selects
jQuery.each(stockable_'.$js_suffix.', function(child_id, child_attrib) {
if (isChildValid_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex)) {
  populateNextSelect_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex+1);
}
});
--------------------

with following code:
--------------------
// Repopulate the following selects
var myArray = new Array();

            jQuery.each(stockable_'.$js_suffix.', function(child_id, child_attrib) {

               if (isChildValid_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex)) {               
myArray.push(child_attrib);
               }

            });



myArray.sort(function( a, b )
{
if ( a["selectoptions"+ (currentIndex+1)][1] == b["selectoptions"+ (currentIndex+1)][1]) return 0;
return a["selectoptions"+ (currentIndex+1)][1]< b["selectoptions"+ (currentIndex+1)][1] ? -1 : 1;
});

for(k=0;k<myArray.length;k++){
populateNextSelect_'.$js_suffix.'(stockableBlockIndex, myArray[k], currentIndex+1);
}


--------------------


Hope this help!

Vanessa

Milbo

Interesting, we can add this as configurable feature to the stockable plugin. Is not a solutoin for the dynamic ones. But nice. I forward this to openglobal.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

maxispin

I am not if this is the same thing, but I would like to have options to change the order of selectoptions. E.g.,

I am using custom field 'plugins'

Selectoption2 DESC
Sectoption1 ASC
Selectoption3 DESC

Or

Selectoption1 ASC
Selectoption2 DESC
Selectoption3 DESC


At stockable.php ver 2.0.24 AIO there is a lot of grayed out code, but unfortunately I am still lacking coding skills so my code reading ability is quite limited. Clanessa's line numbers doesn't match any longer.
VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9

kovacshazi

Quote from: clanessa on December 20, 2012, 18:50:20 PM
Hi everyone!

Maybe I've found a temporary solution to order (front-end side) the custom fields of child products.
I run virtuemart 2.0.14 under joomla 2.5.8

All the changes I've done in php code are in file /my_site/plugins/vmcustom/stockable/stockable.php
I've "simply" re-ordered the data while loading the select lists.


EDIT stockable.php

before line 567
--------------------------------------------
foreach ($options as $key => $val) {
--------------------------------------------

insert following code
--------------------
sort($options);
-----------------------

substitute lines 743-753
--------------------
// Repopulate the following selects
jQuery.each(stockable_'.$js_suffix.', function(child_id, child_attrib) {
if (isChildValid_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex)) {
  populateNextSelect_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex+1);
}
});
--------------------

with following code:
--------------------
// Repopulate the following selects
var myArray = new Array();

            jQuery.each(stockable_'.$js_suffix.', function(child_id, child_attrib) {

               if (isChildValid_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex)) {               
myArray.push(child_attrib);
               }

            });



myArray.sort(function( a, b )
{
if ( a["selectoptions"+ (currentIndex+1)][1] == b["selectoptions"+ (currentIndex+1)][1]) return 0;
return a["selectoptions"+ (currentIndex+1)][1]< b["selectoptions"+ (currentIndex+1)][1] ? -1 : 1;
});

for(k=0;k<myArray.length;k++){
populateNextSelect_'.$js_suffix.'(stockableBlockIndex, myArray[k], currentIndex+1);
}


--------------------


Hope this help!

Vanessa
This code is working on Product name. This great! Can you modify this code work on in_stock value?