Jump to content

[Solved] Little script problem


Hacktor

Recommended Posts

Who can help me with this?

This is my PHP-script:

    function hookExtraLeft($params)
   {
       global $cookie, $link, $smarty;
       /* Product informations */
       $product = new Product(intval(Tools::getValue('id_product')), false, intval($cookie->id_lang));
       $productLink = $link->getProductLink($product);
       $smarty->assign('this_path', $this->_path);
       return $this->display(__FILE__, 'product_page.tpl');
   }



and this is my .tpl page:

 {l s='Email dit artikel aan vriend(in)' mod='sendtoafriend'}



when je execute this you wil get:
http://www.tweewielersite.nl/tweewielersite/modules/sendtoafriend/sendtoafriend-form.php?id_product=102

BUT it has to be:
http://www.tweewielersite.nl/tweewielersite/modules/sendtoafriend/sendtoafriend-form.php?id_product=102-sparta-e-motion-damesfiets.html

The script must not give the id_product code but a friendly URL code.

Who can solve this problem for me please...
Thanks... :cheese:

Link to comment
Share on other sites

I've modified to code

    function hookExtraLeft($params)
   {
       global $cookie, $link, $smarty;
           /* Product informations */
           $product = new Product(intval(Tools::getValue('id_product')), false, intval($cookie->id_lang));
           $productLinks = $link->getProductLink($product);
           $productLink = preg_replace("(https?)://*", "", $productLinks);
               $smarty->assign('productLink',$productLink);
               $smarty->assign('this_path', $this->_path);
       return $this->display(__FILE__, 'product_page.tpl');
   }



 {l s='Email dit artikel aan vriend(in)' mod='sendtoafriend'}



And it gives now this result:
www.tweewielersite.nl/tweewielersite/95-sparta-e-motion-damesfiets.html

How can I remove the red part from the URL:
www.tweewielersite.nl/tweewielersite/95-sparta-e-motion-damesfiets.html

I only need this part: 95-sparta-e-motion-damesfiets.html

Can someone help me with the code please

Link to comment
Share on other sites

    function hookExtraLeft($params)    
       {        
       global $cookie, $link, $smarty;
       /* Product informations */
       $product = new Product(intval(Tools::getValue('id_product')), false, intval($cookie->id_lang));
       $productLink = $link->getProductLink($product->id, $product->link_rewrite);
       $smarty->assign('productLink', parse_url($productLink,PHP_URL_QUERY));
//        $productLink = preg_replace("/[^\/]*$/","",$productLink);  
       $productLink = preg_replace("#^[^:/.]*[:/]+#i","",$productLink);  
       print_r($productLink);
       $smarty->assign(array(
           'this_path' => $this_path,
           'product' => $product,
           'productLink' => $productLink
       ));



 {l s='Email dit artikel aan vriend(in)' mod='sendtoafriend'}



Gives as result:
http://www.tweewielersite.nl/tweewielersite/sendtoafriend-form.php?id_product='>http://www.tweewielersite.nl/tweewielersite/sendtoafriend-form.php?id_product=http://www.tweewielersite.nl/tweewielersite/102-sparta-e-motion-damesfiets.html

but it must be:
http://www.tweewielersite.nl/tweewielersite/sendtoafriend-form.php?id_product='>http://www.tweewielersite.nl/tweewielersite/sendtoafriend-form.php?id_product=102-sparta-e-motion-damesfiets.html

Can someone help me to fix the above preg_replace code please????
THX

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...