无法从prestashop模块

时间:2015-05-08 06:49:27

标签: php prestashop prestashop-1.6

我写了一个prestashop模块,允许添加新产品。我有一个问题:在表'ps_products'中它会成功保存所有信息,但是当我在管理面板目录中打开添加的产品时 - >产品,数量为0,未选择供应商。这是我的代码:

 $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.'));

1 个答案:

答案 0 :(得分:2)

我的朋友,添加此内容以完成更新产品数量:

StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id)