Customfield nested input parameters are not recorded in orderline

Started by welrachid, January 09, 2015, 12:05:21 PM

Previous topic - Next topic

welrachid

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.
Best regards,
Wel

welrachid

Im still new in this. Is this not relevant at all? or mabye its not an error at all?
Best regards,
Wel

balai

This will possibly work

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

welrachid

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????
Best regards,
Wel

welrachid

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
Best regards,
Wel

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

UWiX

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.

-- Beam me up Scotty! This isn't the mens room!
-- Using VirtueMart 3.x

welrachid

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.
Best regards,
Wel

Milbo

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'];
  }
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

UWiX

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.
-- Beam me up Scotty! This isn't the mens room!
-- Using VirtueMart 3.x

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

UWiX

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)!
-- Beam me up Scotty! This isn't the mens room!
-- Using VirtueMart 3.x