示例#1
0
 /**
  * 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;
     }
 }
示例#2
0
 private function doDomainTask($task)
 {
     if (!isset($task['Domains']) || !isset($task['Domains']['Customers']) || !isset($task['Domains']['Customers']['customer_id'])) {
         PanelsActions::UpdateTaskLog($task['action_id'], $this->translations->translate('customer_id not found'));
     }
     $customer_id = intval($task['Domains']['Customers']['customer_id']);
     $ISP = Isp::getByCustomerId($customer_id);
     if (!$ISP || !isset($ISP['isp_id']) || !is_numeric($ISP['isp_id'])) {
         PanelsActions::UpdateTaskLog($task['action_id'], $this->translations->translate('isp_id not found'));
         return false;
     }
     try {
         // Getting domains details
         $domain = Domains::find($task['domain_id'], null, true);
         if (!empty($domain[0])) {
             $domain_name = $domain[0]['domain'] . "." . $domain[0]['tld'];
             // Get the associated registrar for the domain selected
             $registrar = Registrars::getRegistrarId($task['registrars_id']);
             if (!empty($registrar['class'])) {
                 // Create the class registrar object
                 $class = $registrar['class'];
                 $regclass = new $class();
                 $action = $task['action'];
                 // Check if the task is REGISTER or TRANSFER the domain name
                 if ($action == "registerDomain") {
                     $regclass->registerDomain($task['domain_id']);
                     // Set the DNS ZONES
                     DomainsTasks::AddTask($domain_name, "setDomainHosts");
                     // Update the domain information
                     DomainsTasks::AddTask($domain_name, "updateDomain");
                 } elseif ($action == "transferDomain") {
                     $regclass->transferDomain($task['domain_id']);
                 } elseif ($action == "renewDomain") {
                     $regclass->renewDomain($task['domain_id']);
                     // Update the domain information
                     DomainsTasks::AddTask($domain_name, "updateDomain");
                 } elseif ($action == "lockDomain") {
                     $regclass->lockDomain($task['domain_id']);
                 } elseif ($action == "unlockDomain") {
                     $regclass->unlockDomain($task['domain_id']);
                     // Update the domain information
                     DomainsTasks::AddTask($domain_name, "updateDomain");
                 } elseif ($action == "setNameServers") {
                     $regclass->setNameServers($task['domain_id']);
                 } elseif ($action == "setDomainHosts") {
                     $regclass->setDomainHosts($task['domain_id']);
                 } else {
                     $regclass->{$action}($task['domain_id']);
                 }
                 // Update the log description of the task
                 DomainsTasks::UpdateTaskLog($task['task_id'], $this->translations->translate("Your request has been executed."));
                 // Update the status of the task
                 DomainsTasks::UpdateTaskStatus($task['task_id'], Statuses::id('complete', 'domains_tasks'));
                 // Set the task as "Complete"
                 // Increment the task counter number
                 DomainsTasks::UpdateTaskCounter($task['task_id']);
                 // Set the status as Active
                 Domains::setStatus($task['domain_id'], Statuses::id('active', 'domains_tasks'));
             }
         }
     } catch (Exception $e) {
         DomainsTasks::UpdateTaskLog($task['task_id'], $this->translations->translate($e->getMessage()));
         Shineisp_Commons_Utilities::SendEmail($ISP['email'], $ISP['email'], null, "Task error message: " . $task['Domains']['domain'] . "." . $task['Domains']['tld'], $e->getMessage());
         Shineisp_Commons_Utilities::logs("Task error message: " . $task['Domains']['domain'] . "." . $task['Domains']['tld'] . ":" . $e->getMessage(), "tasks.log");
     }
     return true;
 }