N
N
noteblock2016-10-20 19:28:06
Drupal
noteblock, 2016-10-20 19:28:06

Checkout complete: Can order fields be updated?

Task: update the custom field of the buyer profile after placing an order. The value is taken from the session → rules is not an option.
I do it like this:

// save delivery data in order
    $url= 'http://api.boxberry.de/json.php?token=XXX&method=PointsDescription&code='.$_SESSION['bxbr_code'];
    $bxbr_info = '';
    $handle = fopen($url, "rb");
    $contents = stream_get_contents($handle);
    fclose($handle);
    $data = json_decode($contents, true);
    if (count($data) <= 0 or @$data['err']) {
      // если произошла ошибка и ответ не был получен:
      echo $data['err'];
    } else {
    	$bxbr_info .= '«'.$data['Name'].'» (код - '.$_SESSION['bxbr_code'].'): '.$data['Country'].', '.$data['Area'].', '.$data['Address'].', '.$data['Phone'];
    }
    $profile_id = $wrapper->commerce_customer_billing->profile_id->value();
  $profile = commerce_customer_profile_load($profile_id);
  if ($profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile)) {
    $profile_wrapper->field_delivery->set($bxbr_info);
    $profile_wrapper->save();
  }

This code works on checkout/%/review and doesn't work on checkout/%/
complete Are there solutions?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question