protected function CommerceReportsBaseTestCase::createOrders in Commerce Reporting 7.4
Helper function creating multiple dummy orders. If no customers or products exist, then one of each get created.
18 calls to CommerceReportsBaseTestCase::createOrders()
- CommerceReportsCustomerTestCase::testMultipleCustomers in src/
Tests/ CommerceReportsCustomerTestCase.php - Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
- CommerceReportsCustomerTestCase::testSingleCustomer in src/
Tests/ CommerceReportsCustomerTestCase.php - Tests creating a single order for a single customer, containing a single product with a variable quantity. Then verifies if the reporting is correct.
- CommerceReportsCustomerTestCase::testSingleCustomerMultipleProducts in src/
Tests/ CommerceReportsCustomerTestCase.php - Make one customer perform multiple orders with multiple products. Then verifies if the reporting is correct.
- CommerceReportsPaymentMethodTestCase::testExampleMethod in src/
Tests/ CommerceReportsPaymentMethodTestCase.php - CommerceReportsProductTestCase::testMultipleOrdersProducts in src/
Tests/ CommerceReportsProductTestCase.php - Tests creating a multiple orders, containing multiple products with a variable quantity. Then verifies if the reporting is correct.
File
- src/
Tests/ CommerceReportsBaseTestCase.php, line 140
Class
- CommerceReportsBaseTestCase
- Class CommerceReportsBaseTestCase
Namespace
Drupal\commerce_reports\TestsCode
protected function createOrders($amount = 1, $createTransactions = FALSE, $possibleDates = array()) {
if (empty($this->products)) {
$this
->createProducts();
}
if (empty($this->customers)) {
$this
->createCustomers();
}
$order_status = 'completed';
if ($createTransactions) {
$order_status = 'pending';
}
for ($i = 0; $i < $amount; $i++) {
$totalProducts = rand(1, count($this->products));
$products = array();
for ($x = 0; $x < $totalProducts; $x++) {
$product = $this->products[array_rand($this->products)];
$products[$product->product_id] = rand(1, 10);
}
if (!($customer = next($this->customers))) {
$customer = reset($this->customers);
}
$order = $this
->createDummyOrder($customer->uid, $products, $order_status);
if (!empty($possibleDates)) {
$date = $possibleDates[array_rand($possibleDates)];
$order->created = $date;
commerce_order_save($order);
}
$transaction = NULL;
if ($createTransactions) {
$transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
$transaction->amount = $order->commerce_order_total[LANGUAGE_NONE][0]['amount'];
$transaction->status = 'success';
commerce_payment_transaction_save($transaction);
}
$this->orders[] = array(
'commerce_transaction' => $transaction,
'commerce_order' => $order,
'products' => $products,
);
}
}