Jump to content

can`t get the id_product from product page


Recommended Posts

Hello, I did update the Prestashop to  1.7.8.11.  and after it I have the issue when I want to open a category and a product. 
This the code what returns 'null'
 

foreach ($languages AS $key => $lang) {
                if ($page == 'index') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getPageLink('index', true, $lang['id_lang']);
                } elseif ($page == 'product') {
                    dump(Tools::getValue('id_product'));
        die;
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getProductLink(Tools::getValue('id_product'), null, null, null, $lang['id_lang']);
                } elseif ($page == 'category') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCategoryLink(Tools::getValue('id_category'), null, $lang['id_lang']);
                } elseif ($page == 'manufacturer') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getManufacturerLink(Tools::getValue('id_manufacturer'), null, $lang['id_lang']);
                } elseif ($page == 'supplier') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getSupplierLink(Tools::getValue('id_supplier'), null, $lang['id_lang']);
                } elseif ($page == 'cms' && Tools::getValue('id_cms','false') != 'false') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCmsLink(Tools::getValue('id_cms'), null, null, $lang['id_lang']);
                } elseif ($page == 'cms' && Tools::getValue('id_cms_category','false') != 'false') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCmsCategoryLink(Tools::getValue('id_cms_category'), null, $lang['id_lang']);
                }  elseif ($page == 'contact') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getPageLink('contact', null, $lang['id_lang']);
                }

from myhreflang module.  Like this code 'Tools::getValue('id_product') returns 'null'.

Link to comment
Share on other sites

3 minutes ago, Prestashop Addict said:

Please give more context about your module (type, on hook...).

This is the hook
 


    public function hookHeader($params)
    {
        
        $array_of_links[] = array();
        if (isset($this->context->controller->php_self)) {
            $page = $this->context->controller->php_self;
            $languages = Language::getLanguages(false);
          
            foreach ($languages AS $key => $lang) {
                if ($page == 'index') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getPageLink('index', true, $lang['id_lang']);
                } elseif ($page == 'product') {
        //           dump($_GET);
        // die;
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getProductLink(Tools::getValue('id_product'), null, null, null, $lang['id_lang']);
                } elseif ($page == 'category') {
        //              dump($_GET);
        // die;
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCategoryLink(Tools::getValue('id_category'), null, $lang['id_lang']);
                } elseif ($page == 'manufacturer') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getManufacturerLink(Tools::getValue('id_manufacturer'), null, $lang['id_lang']);
                } elseif ($page == 'supplier') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getSupplierLink(Tools::getValue('id_supplier'), null, $lang['id_lang']);
                } elseif ($page == 'cms' && Tools::getValue('id_cms','false') != 'false') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCmsLink(Tools::getValue('id_cms'), null, null, $lang['id_lang']);
                } elseif ($page == 'cms' && Tools::getValue('id_cms_category','false') != 'false') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getCmsCategoryLink(Tools::getValue('id_cms_category'), null, $lang['id_lang']);
                }  elseif ($page == 'contact') {
                    $array_of_links[$lang['language_code']]['url'] = $this->context->link->getPageLink('contact', null, $lang['id_lang']);
                }

                if (isset($array_of_links[$lang['language_code']]['url'])) {
                    $array_of_links[$lang['language_code']]['rel'] = 'alternate';
                    $array_of_links[$lang['language_code']]['hreflang'] = $lang['language_code'];

                    if ($this->context->language->id == $lang['id_lang']) {
                        $array_of_links['canonical']['url'] = $array_of_links[$lang['language_code']]['url'];
                        $array_of_links['canonical']['rel'] = 'canonical';
                        $array_of_links['canonical']['hreflang'] = '-';
                        $array_of_links['xdefault']['url'] = $array_of_links[$lang['language_code']]['url'];
                        $array_of_links['xdefault']['rel'] = 'alternate';
                        $array_of_links['xdefault']['hreflang'] = 'x-default';
                    }
                }

            }
        }
        if (count($array_of_links) > 0) {
            $this->context->smarty->assign('myhreflang', $array_of_links);
            return $this->display(__file__, 'views/hreflang.tpl');
        }
    }

 

Link to comment
Share on other sites

7 minutes ago, Prestashop Addict said:

Strange. Can you place this code and test directly on 1rst line of your hook

  public function hookDisplayheader($params)
  {
    Tools::dieObject(Tools::getAllValues());

 

array:3 [▼ "ars_rewrite_product" => "gas-and-wood-oven-70x75-manual-ignition" "fc" => "controller" "controller" => "product" ]

END
this what I get as the result

Link to comment
Share on other sites

Posted (edited)

You should obtain something like

array:6 [▼
  "isolang" => "fr"
  "id_lang" => 1
  "id_product" => "3"
  "id_product_attribute" => "13"
  "rewrite" => "affiche-encadree-the-best-is-yet-to"
  "controller" => "product"
]

It looks like you have a redirection, verify with other modules.

Edited by Prestashop Addict (see edit history)
Link to comment
Share on other sites

11 minutes ago, Prestashop Addict said:

It looks like you have a redirection, verify with other modules.

Maybe you have an example of what modules I need to check?

Link to comment
Share on other sites

14 minutes ago, Prestashop Addict said:

Search in php code something like

Tools::redirect 
or
header('Location:

 

I found a lot of things (Tools::redirect) like that, but about what exactly I need to change 

Link to comment
Share on other sites

33 minutes ago, Prestashop Addict said:

Search in php code something like

Tools::redirect 
or
header('Location:

I found where the issue but I have now, such results
 

array:2 [▼
  "rewrite" => "gas-and-wood-oven-70x75-manual-ignition"
  "controller" => "product"
]

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...