php - Can't set new product's quantity and supplier from a prestashop module -


i write prestashop module allows adding new products. have problem: in table 'ps_products' saves information success when open added product in admin panel catalog-> products, quantity 0 , no supplier selected. here code:

 $message = ''; $erori = false; $arr = array(); $feats = array(); $imgs = array();   $arr['nume_produs'] = tools::getvalue('pr_name'); $arr['pr_pret_ach'] = tools::getvalue('pr_pret_ach');   $arr['pr_pret_angro'] = tools::getvalue('pr_pret_angro');   $arr['pr_supp'] = explode("=", tools::getvalue('pr_supp'));   $arr['pr_refer'] = tools::getvalue('pr_refer');  $arr['pr_manuf'] = tools::getvalue('pr_manuf');  $arr['pr_short_desc'] = tools::getvalue('pr_short_desc');  $arr['proxy'] = tools::getvalue('proxy');  $res = yamarketsync::update_proxy($arr['proxy']);   $arr['categorii'] = tools::getvalue('categorybox');   if(tools::getvalue('active') == 1)   $arr['activ'] = true;  else  $arr['activ'] = false;   $product = new product();      $langid = (int) (configuration::get('ps_lang_default'));      $name_ro = tools::getvalue('pr_name_ro');     if(tools::getvalue('pr_name_ru') != '')$name_ru = tools::getvalue('pr_name_ru'); else $name_ru = $name_ro;     if(tools::getvalue('pr_name_en') != '')$name_en = tools::getvalue('pr_name_en'); else $name_en = $name_ro;     if(tools::getvalue('pr_name_uk') != '')$name_uk = tools::getvalue('pr_name_uk'); else $name_uk = $name_ro;      $s_desc_ro = tools::getvalue('pr_short_desc_ro');     if(tools::getvalue('pr_short_desc_ru') != '')$s_desc_ru = tools::getvalue('pr_short_desc_ru'); else $s_desc_ru = $s_desc_ro;     if(tools::getvalue('pr_short_desc_en') != '')$s_desc_en = tools::getvalue('pr_short_desc_en'); else $s_desc_en = $s_desc_ro;     if(tools::getvalue('pr_short_desc_uk') != '')$s_desc_uk = tools::getvalue('pr_short_desc_uk'); else $s_desc_uk = $s_desc_ro;      $desc_ro = tools::getvalue('pr_desc_ro');     if(tools::getvalue('pr_desc_ru') != '')$desc_ru = tools::getvalue('pr_desc_ru'); else $desc_ru = $desc_ro;     if(tools::getvalue('pr_desc_en') != '')$desc_en = tools::getvalue('pr_desc_en'); else $desc_en = $desc_ro;     if(tools::getvalue('pr_desc_uk') != '')$desc_uk = tools::getvalue('pr_desc_uk'); else $desc_uk = $desc_ro;      $product->id_supplier =  $arr['pr_supp'][0];     $product->supplier_name = $arr['pr_supp'][1];     $product->id_manufacturer = tools::getvalue('pr_manuf');     $product->description_short = array('4' => $s_desc_ro, '3' => $s_desc_ru, '1' => $s_desc_en,'5' => $s_desc_uk);     $product->description = array('4' => $desc_ro, '3' => $desc_ru, '1' => $desc_en,'5' => $desc_uk);     $product->quantity = tools::getvalue('pr_cant');      $product->name = array('4' => $name_ro, '3' => $name_ru, '1' => $name_en,'5' => $name_uk);     $product->price = tools::getvalue('pr_pret_ach');     $product->wholesale_price = tools::getvalue('pr_pret_angro');     $product->active = $arr['activ'];       $product->id_category_default= $arr['categorii'][0];     $product->category=$arr['categorii'];     $product->reference = $arr['pr_refer'];     $product->link_rewrite = array('4' => tools::link_rewrite($name_ro),'3' => tools::link_rewrite($name_ru),'1' => tools::link_rewrite($name_en),'5' => tools::link_rewrite($name_uk));        $res = $product->add();     if(!$res) $erori = true;      //adaugam features     $num = tools::getvalue('feat_num');     $i=0;      $id_product = (int)$product->id;       while($i <= $num){         if( tools::getvalue('feat_name-'.$i) !='' && tools::getvalue('feat_value-'.$i) != ''){                if(!yamarketsync::exista_deja_asociere(tools::getvalue('ya_feature_name-'.$i), tools::getvalue('feat_name-'.$i) )){                       yamarketsync::save_asociere(tools::getvalue('ya_feature_name-'.$i), tools::getvalue('feat_name-'.$i) );                      }               $rezultat =  product::addfeatureproductimport($id_product, tools::getvalue('feat_name-'.$i), tools::getvalue('feat_value-'.$i));               if(!$rezultat) $erori = true;         }     $feats[$i]['name'] = tools::getvalue('feat_name-'.$i);     $feats[$i]['value'] = tools::getvalue('feat_value-'.$i);     $i++; }        $i=0;      $num = tools::getvalue('img_num');  while($i < $num){     $imgs[$i] = tools::getvalue('image-'.$i);      $img = new image();     $img->id_product = $product->id;     $img->add();    $rezultat = adminimportcontroller::copyimg2($product->id, $img->id, $imgs[$i]);     if(!$rezultat) $erori = true;     $i++; }          if($erori == true) return $this->displayerror($this->l('au aparut erori in timpul salvarii.'));     else return $this->displayconfirmation($this->l('modificarile au fost salvate.')); 

my friend, add complete update product quantity:

stockavailable::setquantity((int)$product->id, 0, $product->quantity, $this->context->shop->id) 

Comments