0
我編寫了允許添加新產品的prestashop模塊。我遇到了一個問題:在'ps_products'表中,它將所有信息都保存成功,但是當我在管理面板目錄 - >產品中打開添加的產品時,數量爲0且未選擇供應商。這裏是我的代碼:無法從prestashop模塊設置新產品的數量和供應商
$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.'));