如何在Drupal Commerce中以编程方式获取送货地址-我应该使用哪种包装纸?


12

我需要以编程方式获取Drupal商业中的送货地址(准确地说是送货国家)。我有$order对象。我如何获得送货地址?

编辑-好的,我做到了

 $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
 $shipping =  $order_wrapper->commerce_customer_shipping->value();

现在我需要重新包装,但我不知道类型

$shipping_wrapper = entity_metadata_wrapper(?, $order);

我应该放什么而不是问号?

Answers:


7

好吧,我这样做

function commerce_shipping_biagetti_service_rate_order($shipping_service, $order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $shipping = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();
  //$shipping is an array containing all shipping data

1
您是否设法在自定义模块中获取了$ order对象?如果可以,你能告诉我如何吗?
Ashkar A.Rahman 2014年


1

有两种查找客户/用户送货地址的方法-

function get_user_shipping_address(){

global $user; 
$default_pid =commerce_addressbook_get_default_profile_id($user->uid,'shipping');

获取个人资料ID后,您可以加载个人资料并获取客户名称和地址

$profile_load = commerce_customer_profile_load($default_pid);
$first_line = $profile_load->commerce_customer_address['und'][0]['name_line'];
$landmark = $profile_load->commerce_customer_address['und'][0]['sub_premise'];
$postal_code = $profile_load->commerce_customer_address['und'][0]['postal_code'];
$state = $profile_load->commerce_customer_address['und'][0]['locality'];
$add[] = $first_line . ' ' . $landmark . ' ' . $postal_code . ' ' . $state;
return $add;
}

第二种方式,如果您有$ order

function get_default_address_of_customer_by_order_id($order) {
  $order1 = commerce_order_load($order);
  $shipping_id = $order1->commerce_customer_shipping['und'][0]['profile_id'];
  $address = commerce_customer_profile_load($shipping_id);
  $first_line = $address->commerce_customer_address['und'][0]['name_line'];
  $landmark = $address->commerce_customer_address['und'][0]['sub_premise'];
  $postal_code = $address->commerce_customer_address['und'][0]['postal_code'];
  $state = $address->commerce_customer_address['und'][0]['locality'];
  $add[] = $first_line . ' ' . $landmark . ' ' . $postal_code . ' ' . $state;
  return $add;
 }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.