Author Topic: How to get the product attributes in the order  (Read 778 times)

m.davide82

  • Jr. Member
  • **
  • Posts: 137
How to get the product attributes in the order
« 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!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9223
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: How to get the product attributes in the order
« Reply #1 on: March 11, 2019, 22:45:45 pm »
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

m.davide82

  • Jr. Member
  • **
  • Posts: 137
Re: How to get the product attributes in the order
« Reply #2 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.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4067
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to get the product attributes in the order
« Reply #3 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

m.davide82

  • Jr. Member
  • **
  • Posts: 137
Re: How to get the product attributes in the order
« Reply #4 on: March 20, 2019, 17:19:48 pm »
I need to have the value of each custom field.

Thanks.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4067
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to get the product attributes in the order
« Reply #5 on: March 20, 2019, 17:33:14 pm »
the code should be
Code: [Select]
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

  • Jr. Member
  • **
  • Posts: 137
Re: How to get the product attributes in the order
« Reply #6 on: March 20, 2019, 22:32:27 pm »
Hi,

thank you very much.

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


Thanks.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4067
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to get the product attributes in the order
« Reply #7 on: March 22, 2019, 19:51:45 pm »
Ooups
Try to change json_encode with json_decode a little mistake

m.davide82

  • Jr. Member
  • **
  • Posts: 137
Re: How to get the product attributes in the order
« Reply #8 on: March 26, 2019, 17:09:30 pm »
It's not working...  :(