/** * saveAll * Save all the data * @param $params * @return Boolean */ public static function saveAll($id, $params) { $date_end = null; if (!is_array($params)) { return false; } $details = Doctrine::getTable('OrdersItems')->find($id); // Generic price setting $rowtotal = $params['price']; $vat = null; $percentage = null; // Get the taxes applied $tax = Taxes::getTaxbyProductID($params['product_id']); if ($tax['percentage'] > 0) { $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100; $vat = $params['price'] * $tax['percentage'] / 100; $percentage = $tax['percentage']; } else { if (!empty($params['parameters'])) { // it is a domain $domainparams = json_decode($params['parameters'], true); if (!empty($domainparams['domain']['tld'])) { $tax = Taxes::getTaxbyTldID($domainparams['domain']['tld']); if ($tax['percentage'] > 0) { $vat = $params['price'] * $tax['percentage'] / 100; $percentage = $tax['percentage']; $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100; } } } } if (!empty($params['billing_cycle_id'])) { $months = BillingCycle::getMonthsNumber($params['billing_cycle_id']); } if ($months > 0 && is_numeric($params['product_id']) && $params['product_id'] > 0) { // only for the product and services. Domains excluded $rowtotal = $rowtotal * $months; } $params['date_end'] = Shineisp_Commons_Utilities::add_date($params['date_start'], null, $months); $details->quantity = $params['quantity']; $details->date_start = Shineisp_Commons_Utilities::formatDateIn($params['date_start']); $details->date_end = Shineisp_Commons_Utilities::formatDateIn($params['date_end']); $details->billing_cycle_id = !empty($params['billing_cycle_id']) ? $params['billing_cycle_id'] : null; $details->price = $params['price']; $details->vat = $vat; $details->percentage = $percentage; $details->cost = $params['cost']; $details->product_id = is_numeric($params['product_id']) && $params['product_id'] > 0 ? $params['product_id'] : NULL; $details->setupfee = $params['setupfee']; $details->discount = $params['discount']; $details->subtotal = $rowtotal * $params['quantity']; $details->status_id = $params['status_id']; $details->description = $params['description']; $details->parameters = $params['parameters']; if ($details->trySave()) { OrdersItems::setAutorenew($id, $params['autorenew']); // Remove all domains OrdersItemsDomains::removeAllDomains($id); if ($params['domains_selected']) { foreach ($params['domains_selected'] as $domain) { OrdersItemsDomains::addDomain($details['order_id'], $domain); } } return true; } return false; }
public static function CreateDomainsbyOrderID($orderid) { $domains = array(); if (is_numeric($orderid)) { // Get the order information $order = Orders::getAllInfo($orderid, "o.*, oi.*", true); // Get the order items if (!empty($order[0]['OrdersItems'])) { // Get all the order products $products = $order[0]['OrdersItems']; if (is_array($products) && count($products) > 0) { // For each product in order foreach ($products as $product) { // If it is a domain product if (is_numeric($product['tld_id'])) { // Get the additional parameters in the order item record $parameters = !empty($product['parameters']) ? json_decode($product['parameters'], true) : array(); // If the parameters are present go on... if (count($parameters) > 0) { // Get the Authcode for the domains that need the transfer action $authcode = !empty($parameters['authcode']) ? $parameters['authcode'] : ""; // Create the domain found in the order $domainID = self::Create($parameters['domain'], $product['tld_id'], $order[0]['customer_id'], $product['detail_id'], 6, $authcode); // Attach the domain to the order OrdersItemsDomains::addDomain($orderid, $domainID); // Prepare the result domain ids list $domains[] = $domainID; } } } } } } return $domains; }