prestashop: get values from the ulr from a module

1

Good day community, I'm new at prestashop so I have a problem, I'm using prestahop 1.6.

I need to get the value of the url from a module.

The value I want to take is "category_rewrite" from the following ulr:

dominio.com/index.php?category_rewrite=ropa-dama&controller=category

Why to take this value, well I'm using the module to delete the IDs of the url, then the css class "active" of the menu stops working.

In the menu module I have the following function:

public function getCurrentCategoriesId($lang_id = NULL) {
        if (isset($_GET['category_rewrite'])) {
            $link_rewrite = $_GET['category_rewrite'];
            $id_lang = $this->context->language->id;
        $id_shop = $this->context->shop->id;
        $sql = 'SELECT 'id_category'
                FROM '._DB_PREFIX_.'category_lang
                WHERE 'link_rewrite' = \''.pSQL($link_rewrite).'\'
                AND 'id_lang' = '.(int)$id_lang.'
                AND 'id_shop' = '.(int)$id_shop;
        $id_category = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
        } else {
            $link_rewrite = false;
        }

        $lastCate = new Category((int) $id_category);
        $parentCate = $lastCate->getParentsCategories($lang_id);
        $arrayCateCurrent = array();
        foreach ($parentCate as $pcate) {
            $arrayCateCurrent[] = $pcate['id_category'];
        }
        return $arrayCateCurrent;
    }

but I still do not get the value of the url, the original code is the following and it works correctly when I deactivate the urls module and the id is shown:

public function getCurrentCategoriesId($lang_id = NULL) {
        if (isset($_GET['id_category'])) {
            $lastCateId = $_GET['id_category'];
        } else {
            $lastCateId = 0;
        }

        $lastCate = new Category((int) $lastCateId);
        //echo $lastCate->name[1]; echo '--------';
        $parentCate = $lastCate->getParentsCategories($lang_id);
        $arrayCateCurrent = array();
        foreach ($parentCate as $pcate) {
            $arrayCateCurrent[] = $pcate['id_category'];
        }
        return $arrayCateCurrent;
    }

I hope you can help me, regards

    
asked by Dontommy 21.08.2018 в 01:54
source

1 answer

0

Maybe it's difficult for someone to help you because as you mentioned there is a modulus that alters the variables, what I would recommend is that in that method you make a die of $_GET so that before you can review which are the variables that you have since it is probable that there is no category_rewrite , you can do it with d($_GET) .

If you find a variable that you can use to obtain the id_category , do not use $_GET['la_varible'] , for security reasons and mandatory practices of PrestaShop obtain it in the following way Tools::getValue('la_variable') .

    
answered by 21.08.2018 / 02:56
source