Программное создание заказа Drupal Commerce 1.x
26 ноября 2018
$uid = 1; $product_id = 1; // Создаём заказ $order = commerce_order_new($uid, 'pending'); commerce_order_save($order); // Создаём line item $product = commerce_product_load($product_id); $line_item = commerce_product_line_item_new($product, 1, $order->order_id); commerce_line_item_save($line_item); // Прикрепляем line item к заказу $order->commerce_line_items['und'][] = (array)$line_item; // Создаем платежный профиль $profile = new stdClass(); $profile->type = 'billing'; $profile->uid = '1'; $profile->status = '1'; $profile->field_zakaz_name['und'][0]['value'] = 'Имя'; $profile->field_zakaz_phone['und'][0]['value'] = '8(999) 999-99-99'; $profile->field_email['und'][0]['value'] = 'mail@mail.ru'; commerce_customer_profile_save($profile); $order->commerce_customer_billing['und'][0]['profile_id'] = $profile->profile_id; commerce_order_save($order);