Exemplo n.º 1
0
 function addSpec($cat_id)
 {
     $productcat = new Productcat($cat_id);
     //check the product GenSpecID
     $specNewType = $this->input->post("specNewType");
     if ($specNewType == "1") {
         $productCatSpecId = $this->input->post("productSpecId");
         $catSpecCheck = new productcatspec();
         $catSpecCheck->where_related_productgenspec("id", $productCatSpecId);
         $catSpecCheck->where_related_productcat("id", $cat_id);
         $catSpecCheck->get();
         if (!$catSpecCheck->exists()) {
             $productGenSpec = new productgenspec($productCatSpecId);
             $productCatSpec = new productcatspec();
             $productCatSpec->productcat_id = $cat_id;
             if (!$productCatSpec->save(array("productgenspec" => $productGenSpec))) {
                 return "Có lỗi khi lưu productcatspec";
             }
         }
     } else {
         $productGenSpec = new productgenspec();
         $productGenSpec->name = $this->input->post("specName");
         $productGenSpec->description = $this->input->post("specDescription");
         $productGenSpec->type = $this->input->post('specElementType');
         if ($this->input->post("specType") == "1") {
             $productGenSpec->parentcat_id = $this->input->post("specGroupId");
             $productGenSpec->isGroup = 0;
         } else {
             $productGenSpec->isGroup = 1;
         }
         if ($productGenSpec->save()) {
             $productCatSpec = new productcatspec();
             $productCatSpec->productcat_id = $cat_id;
             if (!$productCatSpec->save(array("productgenspec" => $productGenSpec))) {
                 return "Có lỗi khi lưu productcatspec";
             }
         } else {
             return "Lỗi khi lưu product general spect";
         }
     }
 }