/** * Save the include of billing tranches * * * @param integer $trancheid * @param integer $includeid * @param string $category */ public static function saveAll($trancheid, $includeid, $type) { $includes = new ProductsTranchesIncludes(); $includes->tranche_id = $trancheid; $includes->include_id = $includeid; $includes->type = $type; $includes->save(); }
/** * Save all the data * * * @param unknown_type $data * @param unknown_type $locale */ public static function saveAll($id, $params, $locale = 1) { $products = new Products(); // Set the new values if (is_numeric($id)) { $products = self::find($id, null, false, $locale); if ($products[0]) { $products = $products[0]; } } else { $products->inserted_at = date('Y-m-d H:i:s'); } // Product UUID is missing, generate a new one if (empty($products->uuid)) { $products->uuid = Shineisp_Commons_Uuid::generate(); } try { if (!empty($_FILES['attachments'])) { $file = $_FILES['attachments']; if (!empty($file)) { if (!is_dir(PUBLIC_PATH . "/media/products/")) { @mkdir(PUBLIC_PATH . "/media"); @mkdir(PUBLIC_PATH . "/media/products"); } } } if (is_array($params)) { $products->updated_at = date('Y-m-d H:i:s'); $products->categories = !empty($params['categories']) ? $params['categories'] : null; $products->uri = !empty($params['uri']) ? Shineisp_Commons_UrlRewrites::format($params['uri']) : Shineisp_Commons_UrlRewrites::format($params['name']); $products->sku = !empty($params['sku']) ? $params['sku'] : ''; $products->cost = $params['cost']; $products->price_1 = !empty($params['price_1']) ? $params['price_1'] : NULL; $products->setupfee = !empty($params['setupfee']) ? $params['setupfee'] : NULL; $products->enabled = !empty($params['enabled']) ? 1 : 0; $products->iscomparable = !empty($params['iscomparable']) ? 1 : 0; $products->tax_id = !empty($params['tax_id']) ? $params['tax_id'] : NULL; $products->type = !empty($params['type']) ? $params['type'] : "generic"; $products->blocks = !empty($params['blocks']) ? $params['blocks'] : NULL; $products->group_id = !empty($params['group_id']) ? $params['group_id'] : NULL; $products->position = !empty($params['position']) ? $params['position'] : NULL; $products->setup = !empty($params['setup']) ? $params['setup'] : NULL; $products->ishighlighted = !empty($params['ishighlighted']) ? 1 : 0; $products->isrefundable = !empty($params['isrefundable']) ? 1 : 0; $products->showonrss = !empty($params['showonrss']) ? 1 : 0; $products->external_id = !empty($params['external_id']) ? $params['external_id'] : NULL; $products->downgradable = !empty($params['downgradable']) ? 1 : 0; $products->server_group_id = !empty($params['server_group_id']) ? intval($params['server_group_id']) : null; $products->autosetup = !empty($params['autosetup']) ? intval($params['autosetup']) : 0; $products->isp_id = Shineisp_Registry::get('ISP')->isp_id; // If 0 or NULL, se to NULL. Avoid constraint errors $products->welcome_mail_id = !empty($params['welcome_mail_id']) && intval($params['welcome_mail_id']) > 0 ? intval($params['welcome_mail_id']) : null; // Save the data $products->save(); $product_id = $products->product_id; // Save the product attributes ProductsAttributesIndexes::saveAll($params, $product_id); $Pdata = ProductsData::findbyProductID($product_id, $locale); if (empty($Pdata)) { $Pdata = new ProductsData(); } // TODO: Guestisp: this criteria is not complete. I cannot translate a product already sold in another language // a solution is write the name of the product sold in the order as flat data //* Product name can not be changed if product is sold // if ( ! (bool)OrdersItems::CheckIfProductExist($product_id) ) { // $Pdata->name = $params ['name']; // } $Pdata->name = $params['name']; $Pdata->nickname = $params['nickname']; $Pdata->shortdescription = $params['shortdescription']; $Pdata->description = $params['description']; $Pdata->metakeywords = $params['metakeywords']; $Pdata->metadescription = $params['metadescription']; $Pdata->product_id = $product_id; $Pdata->language_id = $locale; $Pdata->save(); // Create the price tranches if (!empty($params['tranche_qty']) && !empty($params['tranche_measure']) && !empty($params['tranche_price'])) { $params['tranche_setupfee'] = isset($params['tranche_setupfee']) ? $params['tranche_setupfee'] : 0; $tranches = ProductsTranches::saveAll($product_id, $params['tranche_billing_cycle_id'], $params['tranche_qty'], $params['tranche_measure'], $params['tranche_price'], $params['tranche_setupfee']); $trancheid = $tranches['tranche_id']; if (!empty($params['tranche_includes_domains'])) { foreach ($params['tranche_includes_domains'] as $includeid) { ProductsTranchesIncludes::saveAll($trancheid, $includeid, 'domains'); } } } // Attach the wiki pages to a product if (!empty($params['wikipages'])) { Wikilinks::addWikiPages2Products($product_id, $params['wikipages']); } // Add the related products if (!empty($params['related'])) { self::AddRelatedProducts($product_id, $params['related']); } // Add the upgrade products if (!empty($params['upgrade'])) { self::AddUpgradeProducts($product_id, $params['upgrade']); } // Before to get the Values of the form I upload the files in the folders if (!empty($file)) { if ($_FILES['attachments']['error'] == 0) { // Uploading the file $filename = mt_rand(10, 999) . '_' . $_FILES['attachments']['name']; $retval = move_uploaded_file($_FILES['attachments']['tmp_name'], PUBLIC_PATH . "/media/products/" . $filename); if ($retval) { $media = new ProductsMedia(); $media->filename = $filename; $media->path = "/media/products/{$filename}"; $media->product_id = $product_id; $media->description = $params['filedescription']; $media->enabled = 1; $media->save(); } } } return $product_id; } else { throw new Exception('Parameters data are not correct.'); } } catch (Exception $e) { echo $e->getMessage(); die; return false; } }
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)); }
/** * Get a record and populate the application form * @return unknown_type */ public function editAction() { $form = $this->getForm('/admin/products/process'); $id = $this->getRequest()->getParam('id'); $orders = ""; // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/products/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/products/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); if (!empty($id) && is_numeric($id)) { $this->session->productid = $id; $rs = $this->products->getAllInfo($id, $this->session->langid); if (!empty($rs)) { // Join the translated data information to populate the form $data = !empty($rs['ProductsData'][0]) ? $rs['ProductsData'][0] : array(); $rs = array_merge($rs, $data); $form = $this->createAttributesElements($form, $rs['group_id']); $this->view->isrecurring = $rs['ProductsAttributesGroups']['isrecurring']; $rs['language_id'] = $this->session->langid; // added to the form the language id selected $rs['related'] = ProductsRelated::getItemsbyProductID($rs['product_id']); //add panel for select upgrade $rs['upgrade'] = ProductsUpgrades::getItemsbyProductID($rs['product_id']); // Get the wiki pages attached to the product selected $rs['wikipages'] = Wikilinks::getWikiPagesList($rs['product_id'], "products", $this->session->langid); $form->populate($rs); $categories = explode("/", $rs['categories']); $this->view->categories = json_encode($this->createCategoryTree(0, $categories)); $this->view->title = !empty($rs['name']) ? $rs['name'] : ""; $this->view->icon = "fa fa-barcode"; $this->view->titlelink = !empty($rs['uri']) ? "/" . $rs['uri'] . ".html" : ""; $media = ProductsMedia::getMediabyProductId($id, "pm.media_id, pm.filename, pm.path"); if (isset($media[0])) { $this->view->media = array('records' => $media, 'delete' => array('controller' => 'products', 'action' => 'delmedia')); } $tranches = ProductsTranches::getTranches($id, "tranche_id, quantity, measurement, setupfee, price, bc.name as billingcycle, selected"); if (isset($tranches[0])) { $onclick = array(); foreach ($tranches as &$tranche) { $trancheid = $tranche['tranche_id']; $include = ProductsTranchesIncludes::getIncludeForTrancheId($trancheid); $textInclude = array(); if (array_key_exists('domains', $include)) { $textInclude[] = "Domains: " . implode(", ", $include['domains']); } $tranche['include'] = implode("<br/>", $textInclude); } $this->view->tranches = array('records' => $tranches, 'actions' => array('/admin/products/setdefaultrance/id/' => 'Set as default'), 'delete' => array('controller' => 'products', 'action' => 'deltranche')); } } $orders = array('records' => OrdersItems::ProductsInOrdersItems($id), 'edit' => array('controller' => 'ordersitems', 'action' => 'edit')); $this->view->buttons[] = array("url" => "/admin/products/confirm/id/{$id}", "label" => $this->translator->translate('Delete'), "params" => array('css' => null)); } $this->view->description = $this->translator->translate("Here you can edit the product details"); $this->view->mex = $this->getRequest()->getParam('mex'); $this->view->mexstatus = $this->getRequest()->getParam('status'); $this->view->orders = $orders; $this->view->isSold = (bool) OrdersItems::CheckIfProductExist($id); $this->view->form = $form; $this->render('applicantform'); }