结帐后在Drupal Commerce中获取订单项

时间:2014-04-05 21:58:30

标签: php drupal

我正在编写一些代码来在结帐后访问订单项信息,特别是在hook_commerce_checkout_complete()

当我在Devel(/ devel / php)中运行以下代码时,它工作得很好,将订单中的所有订单项加载到$products数组中。但是在钩子内部,它会在第一次尝试访问行项目数据时抛出错误。

  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $products = array();

  foreach ($wrapper->commerce_line_items as $delta => $line_item_wrapper) {
     $product = array();
     $product['quantity'] = number_format($line_item_wrapper->quantity->value());
     $product['sku'] = $line_item_wrapper->line_item_label->value();
     $product['path'] = $line_item_wrapper->commerce_display_path->value();
     $product['price'] = "$".number_format($line_item_wrapper->commerce_unit_price->amount->value() / 100, 2);
     $product['title'] = $line_item_wrapper->commerce_product->title->value();
     $product['image'] = $line_item_wrapper->commerce_product->field_image->value();
     array_push($products, $product);
  }

我尝试使用commerce_order_load($order->order_id)加载订单,但返回的对象与$ order param没有区别。此外,钩子内部的顺序的包装器对象没有我使用Devel获得的包装器对象那么大。

更多信息:我在Commerce Kickstart 2.0上。此外,对于缓存,我们使用的是Varnish。我得到的确切错误是: 请参阅accuair_checkout_commerce_checkout_complete()

0 /srv/bindings/41e74e13d874402496da2dafa0aea98b/code/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc(392):EntityStructureWrapper-> getPropertyInfo('commerce_produc ...')

1 /srv/bindings/41e74e13d874402496da2dafa0aea98b/code/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc(413):EntityStructureWrapper-> get('commerce_produc ...')

2 /srv/bindings/41e74e13d874402496da2dafa0aea98b/code/sites/all/modules/accuair_checkout/accuair_checkout.module(35):EntityStructureWrapper-> __ get('commerce_produc ...')

编辑:我已尝试按$ order订单项数组中的ID加载订单项。以下代码不会产生任何有用的结果(上面我想要的信息)。

  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_lead_time = 0;
  $products = array();
  foreach ($order->commerce_line_items as $delta => $line_item) {
     $line_item = commerce_line_item_load($line_item[0]['line_item_id']);
     $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
     // no data here

0 个答案:

没有答案