Example #1
0
 public function getpriceAction()
 {
     $currency = Shineisp_Registry::get('Zend_Currency');
     $translator = Shineisp_Registry::get('Zend_Translate');
     $id = $this->getRequest()->getParam('id');
     $refund = $this->getRequest()->getParam('refund');
     $data = array();
     if (is_numeric($id)) {
         $tranche = ProductsTranches::getTranchebyId($id);
         // JAY 20130409 - Add refund if exist
         $NS = new Zend_Session_Namespace('Default');
         if (is_array($NS->upgrade)) {
             //Check if the product is OK for upgrade and if OK take refund
             foreach ($NS->upgrade as $orderid => $upgradeProduct) {
                 if ($orderid != 0) {
                     if (in_array($id, $upgradeProduct)) {
                         $refundInfo = OrdersItems::getRefundInfo($orderid);
                         $refund = $refundInfo['refund'];
                         $idBillingCircle = $tranche['BillingCycle']['billing_cycle_id'];
                         $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle);
                         if ($monthBilling > 0) {
                             $priceToPay = $tranche['price'] * $monthBilling;
                             $priceToPayWithRefund = $priceToPay - $refund;
                             if ($priceToPayWithRefund < 0) {
                                 $priceToPayWithRefund = $priceToPay;
                             }
                             $tranche['price'] = round($priceToPayWithRefund / $monthBilling, 2);
                         } else {
                             $priceToPayWithRefund = $tranche['price'] - $refund;
                             if ($priceToPayWithRefund > 0) {
                                 $tranche['price'] = $priceToPayWithRefund;
                             }
                         }
                         break;
                     }
                 }
             }
         }
         $includes = ProductsTranchesIncludes::getIncludeForTrancheId($id);
         $textIncludes = array();
         if (array_key_exists('domains', $includes)) {
             $textIncludes[] = $this->translator->translate('Domains Included') . ": " . implode(", ", $includes['domains']);
         }
         $textInclude = "";
         if (!empty($textIncludes)) {
             $textInclude = implode("<br/>", $textIncludes);
         }
         // Prepare the data to send to the json
         $data['price'] = $tranche['price'];
         if (!empty($tranche['Products']['Taxes']['percentage']) && is_numeric($tranche['Products']['Taxes']['percentage'])) {
             $data['pricetax'] = $tranche['price'] * ($tranche['Products']['Taxes']['percentage'] + 100) / 100;
         } else {
             $data['pricetax'] = $tranche['price'];
         }
         $data['pricelbl'] = $currency->toCurrency($tranche['price'], array('currency' => Settings::findbyParam('currency')));
         $data['months'] = $tranche['BillingCycle']['months'];
         $data['pricepermonths'] = $data['pricetax'] * $tranche['BillingCycle']['months'];
         $data['name'] = $this->translator->translate($tranche['BillingCycle']['name']);
         $data['pricetax'] = $currency->toCurrency($data['pricetax'], array('currency' => Settings::findbyParam('currency')));
         $data['pricepermonths'] = $currency->toCurrency($data['pricepermonths'], array('currency' => Settings::findbyParam('currency')));
         $data['setupfee'] = $currency->toCurrency($tranche['setupfee'], array('currency' => Settings::findbyParam('currency')));
         $data['includes'] = $textInclude;
     }
     die(json_encode($data));
 }