コード例 #1
0
/**
 * Generate a new commerce product object
 * @return integer, $new_product->product_id;
 */
function _save_product($param_array = NULL)
{
    $output = NULL;
    if (!$param_array) {
        drupal_set_message(t('Please check your parameter'));
        return $output;
    }
    if (!is_array($param_array)) {
        drupal_set_message(t('your parameter is not array'));
        return $output;
    }
    global $user;
    $new_product = commerce_product_new($param_array['product_type']);
    // product type
    $new_product->sku = $param_array['time_key'] . '-' . $user->uid;
    $new_product->title = $param_array['title'];
    $new_product->language = LANGUAGE_NONE;
    $new_product->uid = $user->uid;
    $new_product->status = 1;
    // $new_product->created = time ();
    // $new_product->changed = time ();
    $new_product->commerce_price[LANGUAGE_NONE][0] = array('amount' => $param_array['amount'] * 100, 'currency_code' => "CNY");
    $product->field_product_brand[LANGUAGE_NONE][0]['target_id'] = $param_array['brand_tid'];
    // $product->field_product_description[LANGUAGE_NONE][0]['value'] = 22;
    commerce_product_save($new_product);
    // $output = $new_product->product_id;
    $output = $new_product;
    return $output;
}
コード例 #2
0
ファイル: 1c_exchange.php プロジェクト: maks757/drupal-1c
     $form_state['values'] = '';
     $form = array();
     $form['#parents'] = array();
     $new_product = commerce_product_new('product');
     $new_product->status = 1;
     $new_product->uid = 1;
     $new_product->sku = $item->Ид;
     $new_product->title = $item->Наименование;
     $new_product->type = 'product';
     $new_product->created = $new_product->changed = time();
     $new_product->language = LANGUAGE_NONE;
     $new_product->commerce_price['und'][0]['amount'] = $item->Цены->Цена->ЦенаЗаЕдиницу * 100;
     $new_product->commerce_price['und'][0]['currency_code'] = 'RUB';
     $new_product->commerce_price['und'][0]['data']['component'] = array();
     field_attach_submit('product', $new_product, $form, $form_state);
     commerce_product_save($new_product);
     $node = new stdClass();
     $node->type = 'product';
     node_object_prepare($node);
     $node->title = $item->Наименование;
     $node->language = LANGUAGE_NONE;
     $node->field_id['und'][0]['value'] = $item->Ид;
     $node->field_id['und'][0]['safe_value'] = $item->Ид;
     $node->field_id['und'][0]['format'] = NULL;
     $node->body[$node->language][0]['value'] = 'описание товара';
     $node->body[$node->language][0]['summary'] = 'описание товара';
     $node->body[$node->language][0]['format'] = 'filtered_html';
     $node->field_product['und'][0]['product_id'] = $new_product->product_id;
     $node->uid = 1;
     node_save($node);
 }
コード例 #3
0
ファイル: FeatureContext.php プロジェクト: achton/rooms
 /**
  * Asserts that a given commerce_product type is editable.
  *
  * @Then /^I should be able to edit (?:a|an) "([^"]*)" product$/
  */
 public function assertEditProductOfType($type)
 {
     $product = commerce_product_new($type);
     $random = new Random();
     $product->title = $random->name();
     $product->sku = $random->name();
     commerce_product_save($product);
     $this->products[] = $product;
     // Set internal browser on the node edit page.
     $this->getSession()->visit($this->locatePath('/admin/commerce/products/' . $product->product_id . '/edit'));
 }