Jump to content

rec on DB prestashop


Recommended Posts

Hi i would like to request some help with a new module that i want create.

 

In this moment my module take the $_post of tpl and have to insert on database. but now i can't make insert on sql, only SELECT, can someone help me?

 

//if have post execute
if(isset($_POST['name'])) {
 $db = Db::getInstance(_PS_USE_SQL_

SLAVE_);

//if category exist
$nomecategoria = $_POST['ProductGroup'];
$sql = 'SELECT id_category FROM ps_category_lang WHERE name='.$nomecategoria.' AND id_shop= 1 AND id_lang = 1';
if ($results = $db->ExecuteS($sql)) {

foreach ($results as $row)
    if ($row['id_category'] > 0)
            $catrec = $row['id_category'];
    else       
            $cattarget = Tools::getValue('id'); //if don't exist creat in ps_category_lang and ps_category and take the id

            $sql_cat_lang = 'INSERT
                INTO `ps_category_lang`
                (`id_category`, `id_shop`,`id_lang`,`name`,`description`,`link_rewrite`,`meta_title`,`meta_keywords`,`meta_description`)
                VALUES
                ('.$cattarget.', 1, 1,'.pSQL($nomecategoria).','.pSQL($nomecategoria).','.pSQL($nomecategoria).','.pSQL($nomecategoria).','.pSQL($nomecategoria).','.pSQL($nomecategoria).') ';

            $db->ExecuteS($sql_cat_lang);

            //take posts and insert on ps_category
            $catvariabels2 = array(
                        'id_category' => pSQL($catrec),
                        'id_parent' => 0,
                        'id_shop_default'=>1,
                        'level_depth' =>0,
                        'nleft' =>1,
                        'nright'=>12,
                        'active'=>1,
                        'date_add' =>pSQL($_POST['date_add']),
                        'date_upd' =>pSQL($_POST['date_upd']),
                        'position'=>0,
                        'is_root_category'=>0,
); // here i try use another type to rec on db
$db->insert('ps_category', $catvariabels2);

            //take id for next step to insert on ps_product with rest posts data
            $sql_cat_consult = 'SELECT id_category FROM ps_category_lang WHERE name='.$_POST['ProductGroup'].' AND id_shop= 1 AND id_lang = 1'; //take id for next step that is insert on ps_product with rest posts data

if ($catrow = $db->executeS($sql_cat_consult))
foreach ($catrow as $rowcat)
    if ($rowcat['id_category'] > 0)
        $catrec = $rowcat['id_category'];                            }
Link to comment
Share on other sites

×
×
  • Create New...