VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: m.davide82 on March 11, 2019, 18:23:55 PM

Title: How to get the product attributes in the order
Post by: m.davide82 on March 11, 2019, 18:23:55 PM
Hello,

How can I get the product attributes in my order?
I need to send an API call, but using this: $product->product_attribute

I have this result: { "36": {"38474": {   "custom_qvariant": "cappuccinocaffe ol\u00e8"    }      }      }


How can I have this data?


Thanks a lot in advance!
Title: Re: How to get the product attributes in the order
Post by: GJC Web Design on March 11, 2019, 22:45:45 PM
http://php.net/manual/en/function.json-decode.php

then u have an array
Title: Re: How to get the product attributes in the order
Post by: m.davide82 on March 12, 2019, 17:52:52 PM
Yes, I know.

But I'm asking because I'm not able to have the right result  ;)


Thanks.
Title: Re: How to get the product attributes in the order
Post by: Studio 42 on March 14, 2019, 00:05:27 AM
What you need exactly ?
Because if you need Html display, you need to get the product and use VirtueMartCustomFieldRenderer function or copy the code you need
Title: Re: How to get the product attributes in the order
Post by: m.davide82 on March 20, 2019, 17:19:48 PM
I need to have the value of each custom field.

Thanks.
Title: Re: How to get the product attributes in the order
Post by: Studio 42 on March 20, 2019, 17:33:14 PM
the code should be
if(!empty($product->product_attribute)) {
$json = json_encode($product->product_attribute);
$allValues = array();
foreach ($json as fields) {
   foreach ($fields as $field) {     foreach ($field as $k => $v) {
        $allValues[]= $k.':'.$v;    }
  }
}
$allCustomfieldsValues = implode (',',$allValues);
}



I dont tested it, so you can have some syntax errors ;)
Title: Re: How to get the product attributes in the order
Post by: m.davide82 on March 20, 2019, 22:32:27 PM
Hi,

thank you very much.

I corrected the syntax, but the value is empty :'(


Thanks.
Title: Re: How to get the product attributes in the order
Post by: Studio 42 on March 22, 2019, 19:51:45 PM
Ooups
Try to change json_encode with json_decode a little mistake
Title: Re: How to get the product attributes in the order
Post by: m.davide82 on March 26, 2019, 17:09:30 PM
It's not working...  :(