예제 #1
0
 /**
  * Add a new attribute value
  * 
  * @param integer $product_id
  * @param integer $attribute_id
  * @param string $value
  */
 public static function addNew($product_id, $attribute_id, $value)
 {
     $attrs = new ProductsAttributesIndexes();
     $attrs['product_id'] = $product_id;
     $attrs['attribute_id'] = $value;
     $attrs['value'] = $value;
     $attrs->save();
     return $attrs;
 }
예제 #2
0
 /**
  * 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;
     }
 }
예제 #3
0
 public function getAction()
 {
     $ns = new Zend_Session_Namespace();
     $product = array();
     $uri = $this->getRequest()->getParam('q');
     if (!empty($uri)) {
         $fields = "p.*,pd.productdata_id as productdata_id, \n                           pd.name as name, \n                           pd.shortdescription as shortdescription,\n                           pd.description as description,\n                           pd.metakeywords as metakeywords,\n                           pd.metadescription as metadescription,\n                           pai.*";
         $data = Products::getProductbyUriID($uri, $fields, $ns->langid);
         if (!empty($data) && $data['enabled']) {
             if (!empty($data['blocks'])) {
                 $this->getHelper('layout')->setLayout('2columns-right');
             }
             $this->view->group = Products::GetAttributeGroupByProductID($data['product_id']);
             if (!empty($ns->cart)) {
                 $ns->lastproduct = $uri;
             }
             $refund = false;
             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 (in_array($data['product_id'], $upgradeProduct)) {
                         $refundInfo = OrdersItems::getRefundInfo($orderid);
                         $refund = $refundInfo['refund'];
                         break;
                     }
                 }
             }
             $form = $this->CreateProductForm();
             $items = ProductsTranches::getList($data['product_id'], $refund);
             // Check the default quantity value
             $term = ProductsTranches::getDefaultItem($data['product_id']);
             if (!empty($term)) {
                 $data['term'] = $term;
             }
             // Check if there are custom terms / billing cycles options
             if (count($items) > 0) {
                 $form->addElement('select', 'term', array('label' => $this->translator->translate('Term'), 'required' => true, 'multiOptions' => $items, 'decorators' => array('Bootstrap'), 'class' => 'form-control input-sm select-billing-cycle'));
                 $form->addElement('hidden', 'quantity', array('value' => '1', 'decorators' => array('ViewHelper')));
             } else {
                 $form->addElement('text', 'quantity', array('label' => $this->translator->translate('Quantity'), 'required' => true, 'value' => '1', 'decorators' => array('Bootstrap'), 'class' => 'form-control input-sm'));
                 $form->addElement('hidden', 'term', array('decorators' => array('ViewHelper')));
             }
             // Adding the product attributes
             $attributes = ProductsAttributesIndexes::getAttributebyProductID($data['product_id'], $ns->langid);
             if (count($attributes) > 0) {
                 $this->view->placeholder("features")->append($this->view->partial('partials/attributes.phtml', array('attributes' => $attributes)));
             }
             $layout = $this->getHelper('layout')->getLayout();
             // Adding the related products
             $related = ProductsRelated::get_products($data['product_id'], $ns->langid);
             if (count($related) > 0) {
                 if ($layout == "1column") {
                     $placeholder = $this->view->placeholder("right");
                     $this->getHelper('layout')->setLayout('2columns-right');
                 } else {
                     list($columns, $sidebar) = explode("-", $layout);
                     $placeholder = $this->view->placeholder($sidebar);
                 }
                 $placeholder->append($this->view->partial('products/related.phtml', array('products' => $related)));
             }
             // Attaching the WIKI Pages
             $wikipages = Wikilinks::getWikiPages($data['product_id'], "products", $ns->langid);
             if (count($wikipages) > 0) {
                 if ($layout == "1column") {
                     $placeholder = $this->view->placeholder("right");
                     $this->getHelper('layout')->setLayout('2columns-right');
                 } else {
                     list($columns, $sidebar) = explode("-", $layout);
                     $placeholder = $this->view->placeholder($sidebar);
                 }
                 $placeholder->append($this->view->partial('products/wikipages.phtml', array('wikipages' => $wikipages)));
             }
             $this->view->reviewsdata = Reviews::getbyProductId($data['product_id']);
             // Set the Metatag information
             $this->view->headTitle()->prepend($data['name']);
             if (!empty($data['metakeywords'])) {
                 $this->view->headMeta()->setName('keywords', $data['metakeywords']);
             }
             if (!empty($data['metadescription'])) {
                 $this->view->headMeta()->setName('description', $data['metadescription']);
             }
             // Send the variables to the view
             $this->view->headertitle = $data['name'];
             $this->view->product = $data;
             $this->view->prices = Products::getPrices($data['product_id'], $refund);
             $this->view->form = $form;
             $form->populate($data);
         } else {
             // Check if there is an url rewrite redirection
             $newuri = UrlRewrite::getTarget($uri);
             if ($newuri) {
                 header("HTTP/1.1 301 Moved Permanently");
                 header("Location: {$newuri}");
                 die;
             } else {
                 return $this->_helper->redirector('index', 'notfound', 'default', array('uri' => $uri));
             }
         }
     } else {
         return $this->_helper->redirector('index', 'index', 'default', array('mex' => 'The request is not correct.', 'status' => 'danger'));
     }
     $this->_helper->viewRenderer('details');
 }