コード例 #1
0
ファイル: Orders.php プロジェクト: kokkez/shineisp
 private static function SaveDomainsDetails($params, $orderid)
 {
     $i = 0;
     try {
         if (is_array($params)) {
             // Get the Billing Cycle information
             if (!empty($params['billingcycle_id'])) {
                 $months = BillingCycle::getMonthsNumber($params['billingcycle_id']);
             } else {
                 $bc = BillingCycle::getDefaultDomainBillingCycle();
                 $params['billingcycle_id'] = $bc['billing_cycle_id'];
                 $months = $bc['months'];
             }
             // Convert the domain selection into an array
             $params['domains_selected'] = explode(",", $params['domains_selected']);
             foreach ($params['domains_selected'] as $domain_id) {
                 // Get the domain information
                 $domain = Domains::getAllInfo($domain_id, null, "*", true);
                 // Get the taxes information
                 $tax = Taxes::getTaxbyTldID($domain[0]['tld_id']);
                 // Get the price of the product selected
                 $product = $domain[0]['DomainsTlds'];
                 // Domain name
                 $domain = $domain[0]['domain'] . "." . $domain[0]['DomainsTlds']['WhoisServers']['tld'];
                 if (!empty($product['tax_id'])) {
                     $vat = $product['registration_price'] * $tax['percentage'] / 100;
                     $subtotal = $product['registration_price'] * ($tax['percentage'] + 100) / 100;
                     $percentage = $tax['percentage'];
                 } else {
                     $vat = 0;
                     $subtotal = $product['registration_price'];
                     $percentage = 0;
                 }
                 // Adding the domain in the order selected
                 $details = new OrdersItems();
                 $details->order_id = $orderid;
                 $details->quantity = $params['quantity'];
                 $details->price = $product['registration_price'];
                 $details->vat = $vat;
                 $details->percentage = $percentage;
                 $details->subtotal = $subtotal;
                 $details->cost = $product['registration_cost'];
                 $details->date_start = Shineisp_Commons_Utilities::formatDateIn($params['date_start']);
                 $details->date_end = Shineisp_Commons_Utilities::formatDateIn($params['date_start']->add($months, Zend_Date::MONTH));
                 $details->billing_cycle_id = $params['billingcycle_id'];
                 $details->tld_id = $product['tld_id'];
                 $details->description = $domain;
                 // Register the domain paramenter registration
                 $details->parameters = json_encode(array('domain' => array('name' => $domain, 'tld' => $product['tld_id'], 'action' => 'registerDomain', 'authcode' => null)));
                 $details->save();
                 $orderitem_id = $details->getIncremented();
                 unset($details);
                 // Set the domain properties
                 $domain = Doctrine::getTable('Domains')->find($domain_id);
                 $domain->orderitem_id = $orderitem_id;
                 $domain->customer_id = $params['customer_id'];
                 $domain->save();
                 unset($domain);
                 unset($product);
                 $i++;
             }
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
コード例 #2
0
ファイル: Cart.php プロジェクト: kokkez/shineisp
 /**
  * Calculate the subtotal for each product in the cart
  *
  * @param integer $id        	
  * @param integer $qty        	
  * @param boolean $isvatfree        	
  * @return ArrayObject
  */
 private function calcSubtotal(CartItem $item, $isvatfree = false)
 {
     foreach ($this->items as $item) {
         $isrecurring = false;
         $months = 0;
         $percentage = 0;
         $tax = 0;
         if ("domain" == $item->getType()) {
             $item->setIsrecurring(true);
             // Get the billyng cycle / term / recurring period price
             if ($item->getTerm()) {
                 $priceInfo = ProductsTranches::getTranchebyId($item->getTerm());
                 $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']);
                 $months = $priceInfo['BillingCycle']['months'];
             } else {
                 $priceInfo = BillingCycle::getDefaultDomainBillingCycle();
                 $item->setBillingid($priceInfo['billing_cycle_id']);
                 $months = $priceInfo['months'];
             }
             $unitprice = $item->getUnitPrice();
             $setupfee = 0;
             // Calculate the price per Quantity
             $subtotal = $unitprice * $item->getQty();
             // check the taxes
             if (Taxes::get_percentage($item->getTaxId())) {
                 $percentage = Taxes::get_percentage($item->getTaxId());
                 $tax = $subtotal * $percentage / 100;
                 $price = $subtotal * (100 + $percentage) / 100;
             }
         } else {
             // Get all the product information
             $product = Products::getAllInfo($item->getId());
             // Check the type of the product and get the price information
             if ($product['ProductsAttributesGroups']['isrecurring']) {
                 $item->setIsrecurring(true);
                 // Get the billyng cycle / term / recurring period price
                 $priceInfo = ProductsTranches::getTranchebyId($item->getTerm());
                 // Price multiplier
                 $months = $priceInfo['BillingCycle']['months'];
                 $unitprice = $priceInfo['price'];
                 $setupfee = $priceInfo['setupfee'];
                 // Calculate the price per the months per Quantity
                 $subtotal = $unitprice * $months * $item->getQty();
                 $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']);
             } else {
                 $item->setIsrecurring(false);
                 $unitprice = $product['price_1'];
                 $setupfee = $product['setupfee'];
                 // Calculate the price per Quantity
                 $subtotal = $unitprice * $item->getQty();
             }
             // check the taxes for each product
             if (!empty($product['tax_id']) && !$isvatfree) {
                 if (!empty($product['Taxes']['percentage']) && is_numeric($product['Taxes']['percentage'])) {
                     $percentage = $product['Taxes']['percentage'];
                     $tax = $subtotal * $percentage / 100;
                     $price = $subtotal * (100 + $percentage) / 100;
                 }
             }
         }
         // ... and add the setup fees
         $price = $subtotal + $setupfee;
         $item->setSubtotals(array('months' => $months, 'subtotal' => $subtotal, 'setupfee' => $setupfee, 'price' => $price, 'taxes' => $tax, 'percentage' => $percentage));
     }
     return $this->items;
 }