আপনি কমার্স ড্রাশ নামে একটি নতুন মডিউল পরীক্ষা করার চেষ্টা করতে পারেন যার নিম্নলিখিত বাক্য গঠন রয়েছে:
drush commerce-order-add 1
drush --user=admin commerce-order-add MY_SKU123
ম্যানুয়াল সমাধান
বাণিজ্য ক্ষেত্রে ক্রমক্রমে অর্ডার তৈরির জন্য, আপনি নিম্নলিখিত কোডটি ব্যবহার করতে পারেন (এটি ড্রাশের সাথেও কাজ করে, যেমন drush -vd -u "$1" scr order_code-7.php
)। অনুগ্রহ করে নোট করুন যে commerce_payment_example
মডিউল প্রয়োজনীয়।
<?php
if (!function_exists('drush_print')) {
function drush_print ($text) {
print $text . "\n";
}
}
$is_cli = php_sapi_name() === 'cli';
global $user;
// Add the product to the cart
$product_id = 5;
$quantity = 1;
if ($is_cli) {
drush_print('Creating new order for ' . $quantity . ' item(s) of product ' . $product_id . '...');
}
// Create the new order in checkout; you might also check first to
// see if your user already has an order to use instead of a new one.
$order = commerce_order_new($user->uid, 'checkout_checkout');
// Save the order to get its ID.
commerce_order_save($order);
if ($is_cli) {
drush_print('Order created. Commerce order id is now ' . $order->order_id);
drush_print('Searching product ' . $product_id . ' in a Commerce system...');
}
// Load whatever product represents the item the customer will be
// paying for and create a line item for it.
$product = commerce_product_load((int)$product_id);
if((empty($product->product_id)) || (!$product->status)){
if ($is_cli) {
drush_print(' Cannot match given product id with a Commerce product id.');
}
drupal_set_message(t('Invalid product id'));
drupal_goto(); // frontpage
return FALSE;
}
if ($is_cli) {
drush_print(' Found a Commerce product ' . $product->product_id . '.');
}
// Create new line item based on selected product
$line_item = commerce_product_line_item_new($product, 1, $order->order_id);
if ($is_cli) {
drush_print(' Added product to the cart.');
}
// Save the line item to get its ID.
commerce_line_item_save($line_item);
// Add the line item to the order using fago's rockin' wrapper.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
if ($is_cli) {
drush_print('Saving order...');
}
// Save the order again to update its line item reference field.
commerce_order_save($order);
// Redirect to the order's checkout form. Obviously, if this were a
// form submit handler, you'd just set $form_state['redirect'].
if ($is_cli) {
drush_print('Checking out the order...');
}
commerce_checkout_complete($order);
if ($is_cli) {
drush_print('Marking order as fully paid...');
}
$payment_method = commerce_payment_method_instance_load('commerce_payment_example|commerce_payment_commerce_payment_example');
if (!$payment_method) {
if ($is_cli) {
drush_print(" No example payment method found, we can't mark order as fully paid. Please enable commerce_payment_example module to use this feature.");
}
}
else {
if ($is_cli) {
drush_print(" Creating example transaction...");
}
// Creating new transaction via commerce_payment_example module.
$charge = $order->commerce_order_total['und'][0];
$transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
$transaction->instance_id = $payment_method['instance_id'];
$transaction->amount = $charge['amount'];
$transaction->currency_code = $charge['currency_code'];
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
$transaction->message = 'Name: @name';
$transaction->message_variables = array('@name' => 'Example payment');
if ($is_cli) {
drush_print(" Notifying Commerce about new transaction...");
}
commerce_payment_transaction_save($transaction);
commerce_payment_commerce_payment_transaction_insert($transaction);
}
if ($is_cli) {
drush_print("Marking order as completed...");
}
commerce_order_status_update($order, 'completed');
if ($is_cli) {
drush_print("\nDone.");
}
দ্রষ্টব্য: মন্তব্যে যেমন পরামর্শ দেওয়া হয়েছে, অর্ডার সংরক্ষণের সময় পেমেন্ট পদ্ধতি সম্পর্কে যদি আপনার ত্রুটিটি অজানা থাকে তবে নিশ্চিত হয়ে নিন যে আপনি এটি নির্দিষ্ট করেছেন, উদাহরণস্বরূপ
$order->data['payment_method'] = 'commerce_payment_example|commerce_payment_commerce_payment_example';
commerce_order_save($order);