Submitted by selinav on
Bonjour,
J'essaie de récupérer une valeur de mon objet $order mais je ne sais pas comment faire quand les valeurs sont imbriquées.
Je voudrais récupérer l'élément
[products][1][date][node_checkout_nid]
Si je fais : print $order[products][1][data][node_checkout_nid];
j'obtiens le message Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\
Pourriez-vous m'expliquer les subtilités pour récupérer les valeurs d'objets imbriqués.
Dois je récupérer tableau par tableau?
Voici mon code quand je fais un print_r($order)
stdClass Object
(
[order_id] => 11
[uid] => 1
[order_status] => pending
[order_total] => 14.95999856
[product_count] => 2
[primary_email] => sophie@otutu.com
[delivery_first_name] => mon prenom
[delivery_last_name] => mon nom
[delivery_phone] => 0123456789
[delivery_company] => ma societe
[delivery_street1] => 14 rue brison
[delivery_street2] =>
[delivery_city] => roanne
[delivery_zone] => 0
[delivery_postal_code] => 42300
[delivery_country] => 250
[billing_first_name] => mon prenom
[billing_last_name] => mon nom
[billing_phone] => 0123456789
[billing_company] => ma societe
[billing_street1] => 14 rue brison
[billing_street2] =>
[billing_city] => roanne
[billing_zone] => 0
[billing_postal_code] => 42300
[billing_country] => 250
[payment_method] => check
[data] => Array
(
[taxes] => Array
(
[1] => stdClass Object
(
[id] => 1
[name] => TVA 19.6%
[rate] => 0.196
[shippable] => 0
[taxed_product_types] => Array
(
[product] => product
)
[taxed_line_items] => Array
(
[shipping] => shipping
)
[weight] => 0
)
)
)
[created] => 1257870979
[modified] => 1257870986
[host] => 127.0.0.1
[products] => Array
(
[0] => stdClass Object
(
[order_product_id] => 27
[order_id] => 11
[nid] => 239
[title] => Bon d'achat Cad'Oh ! ® - valeur 10€
[manufacturer] =>
[model] => BON-10
[qty] => 1
[cost] => 0.00000
[price] => 10.00000
[weight] => 0
[data] => Array
(
[shippable] => 1
[module] => uc_product
)
[order_uid] => 1
)
[1] => stdClass Object
(
[order_product_id] => 28
[order_id] => 11
[nid] => 237
[title] => Carte de fidélité CityFly ®
[manufacturer] =>
[model] => CITYFLY
[qty] => 1
[cost] => 0.00000
[price] => 2.50836
[weight] => 0
[data] => Array
(
[nid] => 237
[node_checkout_nid] => 297
[shippable] => 1
[module] => uc_product
)
[order_uid] => 1
)
)
[quote] => Array
(
[method] => flatrate_1
[accessorials] => 0
[rate] => 0.00000
[quote_form] =>
)
[extra_fields] => Array
(
)
[line_items] => Array
(
[0] => Array
(
[line_item_id] => subtotal
[type] => subtotal
[title] => Sous-total
[amount] => 14.95999856
[weight] => 0
[data] =>
)
[1] => Array
(
[line_item_id] => 10
[type] => shipping
[title] => Franco retrait aux Vitrines
[amount] => 0.00000
[weight] => 1
[data] =>
)
[2] => Array
(
[line_item_id] => tax_subtotal
[type] => tax_subtotal
[title] => Subtotal excluding TVA
[amount] => 12.50836
[weight] => 7
[data] =>
)
[3] => Array
(
[line_item_id] => 11
[type] => tax
[title] => TVA 19.6%
[amount] => 2.45164
[weight] => 9
[data] => Array
(
[tax_id] => 1
[tax_rate] => 0.196
[taxable_amount] => 12.50836
[tax_jurisdiction] => TVA 19.6%
)
)
)
)
D'avance merci
n'oublies pas que pour
Permalien Soumis par khtuluu le 12 Novembre, 2009 - 13:58
n'oublies pas que pour accéder aux propriétés d'un objet ce n'est pas la même chose qu'un tableau
ton $order est un objet donc déjà tu dois sûrement faire $order->products
ensuite products est bien un tableau donc $order->products[0]
a partir de la je te conseils de couper ta récupération ca évite une ligne horrible a lire ^^
$taVar = $order->products[0] ; <-- la turécupère un objet
$taValFinal = $taVar->date['node_checkout_nid']; <-- date est bien un tableau
noramlement ça devrait être bon avec ça.
merci khtuluu, je viens de
Permalien Soumis par selinav le 12 Novembre, 2009 - 14:57
merci khtuluu,
je viens de comprendre, effectivement je confondais les objets et les tableaux.
<?php
foreach ($order->products as $product) {
... $i=0;
foreach ($product->data as $data){
if($i==1){
$texte="ID Carte CityFly : ".$data;
$path="node/".$data;
print l($texte, $path, array('html' => TRUE));
}
$i++;
}
}
?>