News:

Support the VirtueMart project and become a member

Main Menu

How to get the product attributes in the order

Started by m.davide82, March 11, 2019, 18:23:55 PM

Previous topic - Next topic

m.davide82

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!

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

m.davide82

Yes, I know.

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


Thanks.

Studio 42

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

m.davide82

I need to have the value of each custom field.

Thanks.

Studio 42

#5
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 ;)

m.davide82

Hi,

thank you very much.

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


Thanks.

Studio 42

Ooups
Try to change json_encode with json_decode a little mistake

m.davide82