/** * Create an order with many products * * * @param $product * @return integer $orderID */ public static function createOrderWithMultiProducts(array $products, $customer_id, $type = "domain") { $order = new Orders(); try { $customer = Customers::getAllInfo($customer_id); $isp_id = $customer['isp_id']; // Creating a new Order. $order->customer_id = $customer_id; $order->isp_id = $isp_id; $order->order_date = date('Y-m-d'); $order->status_id = Statuses::id("tobepaid", "orders"); // To pay $order->save(); $id = $order->getIncremented(); // Add a fastlink to a order $link_exist = Fastlinks::findlinks($id, $customer_id, 'orders'); if (count($link_exist) == 0) { $link = new Fastlinks(); $link->controller = "orders"; $link->action = "edit"; $link->params = json_encode(array('id' => $id)); $link->customer_id = $customer_id; $link->sqltable = "orders"; $link->id = $id; $link->code = Shineisp_Commons_Utilities::GenerateRandomString(); $link->save(); } foreach ($products as $product) { $product = Domains::getAllInfo($product, null, null, true); // Attaching the order item to the order previously created. $orderitem = new OrdersItems(); $date_end = Shineisp_Commons_Utilities::add_date(date('d-m-Y'), null, 365); // Fixed Renew $orderitem->order_id = $id; $orderitem->product_id = $product[0]['Products']['product_id']; $orderitem->billing_cycle_id = 1; $orderitem->date_start = date('Y-m-d H:i:s'); $orderitem->date_end = $date_end; $orderitem->autorenew = true; $orderitem->description = $product[0]['domain'] . "." . $product[0]['tld']; $orderitem->quantity = 1; $tax = Taxes::getTaxbyProductID($product[0]['Products']['product_id']); $orderitem->price = $product[0]['Products']['price_1']; $orderitem->cost = $product[0]['Products']['cost']; $orderitem->status_id = Statuses::id("processing", "orders"); // Processing status set $orderitem->save(); $detailid = $orderitem->getIncremented(); // Set the domains status as processing Domains::setStatus($product[0]['domain_id'], 6); } // Update the total of the order self::updateTotalsOrder($id); return $id; } catch (Exception $e) { echo $e->getMessage(); die; } }