public function MerciBaseTestCase::createDummyReservation in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3
Create a dummy order in a given status.
Parameters
$uid: ID of the user that owns the order.
$products: Array of products that are going to be added to the order: keys are product ids, values are the quantity of products to add.
$status: Status of the order
Return value
A commerce order object in the given status.
File
- merci_core/
tests/ merci_base.test, line 410 - Defines abstract base test class for the Merci module tests.
Class
- MerciBaseTestCase
- Abstract class for Merci testing. All Merci tests should extend this class.
Code
public function createDummyReservation($uid = 1, $products = array(), $status = 'cart', $customer_profile_id = NULL) {
// If there aren't any products to add to the order, create one.
if (empty($products)) {
$product = $this
->createDummyProduct('PROD-01', 'Product One', -1, 'USD', $uid);
$products[$product->product_id] = rand(1, 10);
}
// Create a new shopping cart order by adding the products to it.
foreach ($products as $product_id => $quantity) {
if ($product = commerce_product_load($product_id)) {
$line_item = commerce_product_line_item_new($product, $quantity);
$line_item = commerce_cart_product_add($uid, $line_item);
}
}
// Load the order for returning it.
$order = commerce_cart_order_load($uid);
if (!empty($customer_profile_id)) {
$order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'] = $customer_profile_id;
}
// If the order should be in a different status, update it.
if ($status != 'cart') {
$order = commerce_order_status_update($order, $status, TRUE);
}
commerce_order_save($order);
return $order;
}