Hello all!
I am using VM 2.9.8 (hopefully soon version 3 ;)) and would be very happy about you helping me with a difficult task.
I created a form having one text field.
The user submits a certain string, which is stored as a user state variable, using the function 'getUserStateFromRequest()'.
During shopping he can submit a new, different string at any time.
First:
Whenever the user adds a product to the cart, the string currently stored in the session shall be "attached" to the ordered product.
Is it possible to create a VM plugin for that? How should this be implemented?
Second:
In the cart overview the added products shall be grouped by the "attached" strings.
Can this be achieved by simply changing the cart template? What needs to be changed?
I am grateful for any helpful answer!
Best regards,
Gerald
QuoteSecond:
In the cart overview the added products shall be grouped by the "attached" strings.
Can this be achieved by simply changing the cart template? What needs to be changed?
if you have the "attached" in each of the cart object products then the products are an array which is looped - so look into array sorting before the loop
Hi!
Thank you for your quick reply.
Your advice sounds good - I will give it a try.
So the main question seems to be, how to "attach" the string to the product on adding it to the cart.
Especially: What, if the user adds a product two or more times to the cart, some times with different "attached" string?
Kind regards,
Gerald
Hi all!
Anyone any idea?
Best regards,
Gerald
basically this needs coding - if you haven't the skills then you need to employ someone who has...
Hello!
I know that this needs coding and I am prepared to code that.
But I don't know where to hook in.
This is the help I am looking for.
Can you give me some advice on this?
Best regards,
Gerald
Sorry - no idea - without me trying I don't know - without my time paid I won't try.. catch 22
OK, thank you.
Anyone else?
Gerald
Noone? ???
Maybe http://extensions.virtuemart.net/support
Hello all!
Thank you for your hints by now.
Here is my current state:
I got into creating an own product plugin (http://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins (http://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins)).
On displaying a product I "catch" the string stored as session variable and set it as value of the input box of the plugin.
Adding the product to cart, the according string is stored with the cart product und the cart list shows also the stored string.
Even adding same product with same string cumulates the amount of added products which have a certain string.
What I still need to achieve:
Group the products in the cart by the strings stored with the added products.
i.e. this ...
(http://op.gb-s.at/forums/sample001.jpg)
... should become this ...
(http://op.gb-s.at/forums/sample002.jpg)
I already tried to go for "GJC Web Design"'s hint to sort the products array before listing the cart content.
But the data of the custom fields are stored this way in the product object:
["customProductData"]=> array(1) {
[29]=> array(1) {
[144]=> array(1) {
["comment"]=> string(19) "8019-08-009/E68-64H"
}
}
}
How can I sort the products array by these strings being stored that complicatedly?
Isn't there any easier way to group my cart products?
Any helpful answer is very appreciated - thank you very much in advance!
Kind regards,
Gerald
As you see no easy way --
you will have to in this case loop thru the multi-dimensional array (i.e. basically disassemble it), filter it and put it back in the order you want etc
then display it
Hello!
Thank you for your answer.
Can I do that in the cart template?
The thing is, I am not THAT php programmer...
Sorting multidimensional arrays I haven't done yet.
Do you have any useful hint for me, how to do that?
Kind regards,
Gerald
Here is the solution:
The products data is stored in following style:
Array
(
[0] => Object
(
["field1"] => 10
["field2"] => 11
["field3"] => 12
["field4"] => Array
(
[29] => Array
(
[144] => Array
(
["sortelement"] => "Sortable String 3"
)
)
)
["field5"] => 13
["field6"] => 14
)
[1] => Object
(
["field1"] => 15
["field2"] => 16
["field3"] => 17
["field4"] => Array
(
[29] => Array
(
[145] => Array
(
["sortelement"] => "Sortable String 1"
)
)
)
["field5"] => 18
["field6"] => 19
)
[2] => Object
(
["field1"] => 20
["field2"] => 21
["field3"] => 22
["field4"] => Array
(
[29] => Array
(
[146] => Array
(
["sortelement"] => "Sortable String 2"
)
)
)
["field5"] => 23
["field6"] => 24
)
)
To sort by the "sortelement", I use following code:
$sortArray = array();
foreach($arrayToSort as $key => $tmp) {
$tmp = $tmp->field4[29];
$tmp = reset($tmp);
$tmp = $tmp["sortelement"];
$sortArray[$key] = $tmp;
}
array_multisort($sortArray, SORT_ASC, SORT_STRING, $arrayToSort);
This way my cart products are sorted by the values stored in the custom field (Plugin).
Best regards,
Gerald
Well done..... marked solved.