VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: welrachid on January 09, 2015, 12:05:21 PM

Title: Customfield nested input parameters are not recorded in orderline
Post by: welrachid on January 09, 2015, 12:05:21 PM
This used to be OK:
<input type='text' name='customPlugin[". $params->virtuemart_customfield_id ."][". $this->_name ."][". $k ."]' value='' />

Because of Vm3 i know have rewritten it to this which should be OK.

<input type='text' name='customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][". $params->virtuemart_customfield_id ."][". $this->_name ."][". $k ."]' />

The problem however is that it WONT save the array correctly. [". $this->_name ."][". $k ."] is a nested array with multiple things in it.

so now i have to save it like this:
<input type='text' name='customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][". $params->virtuemart_customfield_id ."][". $k ."]' />
to get the $k key and value pairs.

Is this intentionally? I can probably make it work in my customfield, but is it intentionally to work like this? Because this means i cannot have nested arrays as input fields

Looking forward to hear your answer.
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: welrachid on January 13, 2015, 18:30:19 PM
Im still new in this. Is this not relevant at all? or mabye its not an error at all?
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: balai on January 14, 2015, 12:28:09 PM
This will possibly work

<input type='text' name='customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][". $params->virtuemart_customfield_id ."][". $k ."][". $this->_name ."]' />
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: welrachid on January 14, 2015, 14:31:32 PM
Thank you for your reply.
I cannot make it work

<input    type="hidden" value="1"   name="customProductData[<?php echo $product_id;?>][<?php echo $params->virtuemart_custom_id; ?>][<?php echo $params->virtuemart_customfield_id; ?>][a][a]" />
<input    type="hidden" value="2"   name="customProductData[<?php echo $product_id;?>][<?php echo $params->virtuemart_custom_id; ?>][<?php echo $params->virtuemart_customfield_id; ?>][a]" />


When i look on the data that is posted i see this

customProductData[1][27][125][a][a]:1
customProductData[1][27][125][a]:2

but my method:

   function plgVmOnViewCartVM3(&$product, &$productCustom, &$html) {
      if (empty($productCustom->custom_element) or $productCustom->custom_element != $this->_name) return false;
      if(empty($product->customProductData[$productCustom->virtuemart_custom_id][$productCustom->virtuemart_customfield_id])) return false;
      $myparams = array();
      foreach( $product->customProductData[$productCustom->virtuemart_custom_id] as $k =>$item ) {
         if($productCustom->virtuemart_customfield_id == $k) {
            foreach ($item as $Fkey => $Fval){
               $html .= "<br>".var_export($item,true);
            }
         }
      }
      return true;
   }

will only display this:
array ( 'a' => '',)

Which means somthing is wrong.
When i use
<input    type="hidden" value="1"   name="customProductData[<?php echo $product_id;?>][<?php echo $params->virtuemart_custom_id; ?>][<?php echo $params->virtuemart_customfield_id; ?>][a]" />
<input    type="hidden" value="2"   name="customProductData[<?php echo $product_id;?>][<?php echo $params->virtuemart_custom_id; ?>][<?php echo $params->virtuemart_customfield_id; ?>]" />

i have no problem whatsover. i get
array ( 'a' => '1', 'b' => '2',)
which is what i expect.

Im not sure, but i think its a bug. I cannot find anywhere in doc that states i cannot do this????
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: welrachid on January 28, 2015, 11:13:11 AM
Any of the core developers can give a hint if im wrong or not? so that i can mark this issue as solved og that you have acknowledged it
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: Milbo on January 28, 2015, 13:08:12 PM
http://docs.virtuemart.net/tutorials/development/175-code-adjustments-for-virtuemart-3.html

and http://reinhold.kainhofer.com/software/tutorial-vm2-plugin-vm3.html
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: UWiX on February 07, 2015, 21:10:00 PM
I think I recognize this problem. Writting a customfield plugin at this moment which makes use of checkboxes. When using the correct VM3 syntax for the checkbox fields:
customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][".$params->virtuemart_customfield_id."][comment]

It only shows one selected checkbox option (the last selected one). The $select['comment']  value is set to array( "comment" => "checkbox-selection-value").
When I use the following syntax:
customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][".$params->virtuemart_customfield_id."][comment][] the $select['comment'] returns array("comment" => array(0 => "checkbox-selection-value1", 1=>"checkbox-selection-value2", ....)) in the PlgVmPrepareCartProduct function.

But in the PlgVmViewCartVM3 function the value of $product->customProductData[...] it only returns array( "comment" => 0 ). And that's also the way it's stored in database. So the array with multiple choices cannot be saved. Using VM2 it works like it should though.

Are these problems related? Looks like it to me and the documentation links are not clear about this for me. Any help is very welcome for this "issue'- so thank you in advance.

Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: welrachid on February 12, 2015, 13:41:07 PM
Hi.

This is exactly what im trying to point out.

The documentation and the migration guide are not helpful here because i have not been able to read that "this" part have been changed.

Milbo, i dnt think those links are clear about this.

Anyway.. perhaps some other people will find this thread, and realize why their code is not working.

Quote from: UWiX on February 07, 2015, 21:10:00 PM
I think I recognize this problem. Writting a customfield plugin at this moment which makes use of checkboxes. When using the correct VM3 syntax for the checkbox fields:
customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][".$params->virtuemart_customfield_id."][comment]

It only shows one selected checkbox option (the last selected one). The $select['comment']  value is set to array( "comment" => "checkbox-selection-value").
When I use the following syntax:
customProductData[".$product->virtuemart_product_id."][".$params->virtuemart_custom_id."][".$params->virtuemart_customfield_id."][comment][] the $select['comment'] returns array("comment" => array(0 => "checkbox-selection-value1", 1=>"checkbox-selection-value2", ....)) in the PlgVmPrepareCartProduct function.

But in the PlgVmViewCartVM3 function the value of $product->customProductData[...] it only returns array( "comment" => 0 ). And that's also the way it's stored in database. So the array with multiple choices cannot be saved. Using VM2 it works like it should though.

Are these problems related? Looks like it to me and the documentation links are not clear about this for me. Any help is very welcome for this "issue'- so thank you in advance.
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: Milbo on February 13, 2015, 10:47:16 AM
use in FE

$name = 'customProductData['.$viewData[1]->virtuemart_product_id.']['.$viewData[0]->virtuemart_custom_id.']['.$viewData[0]->virtuemart_customfield_id.'][comment]';

of course if you want to use an array of comments

$name = 'customProductData['.$viewData[1]->virtuemart_product_id.']['.$viewData[0]->virtuemart_custom_id.']['.$viewData[0]->virtuemart_customfield_id.'][comment][]';


in your cart/order view use

foreach( $product->customProductData[$productCustom->virtuemart_custom_id] as $k =>$item ) {
  if($productCustom->virtuemart_customfield_id == $k) {
   echo $item['comment'];
  }
}
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: UWiX on February 24, 2015, 20:19:29 PM
I've tried everything youve set (and more) but still the plgVmViewCartVM3 function returns an array like this:

array("comment" => array(0 => "checkbox-selection-value1"))

And nothing more - even when I've selected multiple checkboxes using your suggestion:

$name = 'customProductData['.$viewData[1]->virtuemart_product_id.']['.$viewData[0]->virtuemart_custom_id.']['.$viewData[0]->virtuemart_customfield_id.'][comment][]';

Seems like it is "shortened" when it's passing the plgVmViewCartVM3 function  :(

A solution, but not a very pretty one is that I've now used some jQuery to pass each selected checkbox option to a hidden input field with the 'customProductData[...]' name and split that value into an array in the plgVmPrepareCartProduct function for further handling of the input.
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: Milbo on February 25, 2015, 10:08:39 AM
The code above is from my commercial plugin and works.
Title: Re: Customfield nested input parameters are not recorded in orderline
Post by: UWiX on February 26, 2015, 09:27:42 AM
I'll have to start over to test it in a simple way. If it works for you I must be doin' something wrong over here....

Thank you for your input (and patience)!