Jump to content

Built-in Affiliate module and friendly urls


Recommended Posts

Hello.

 

I found that affiliates module is not working if i enable friendly urls.

I think, the dispatcher is removing all custom parameters that i add on the end of friendly url.

For example:

i've opened this url: shop.com/category/123-item.html?aff_id=1

in shop, the target parsed url is: shop.com/category/123-item.html (without aff_id parameter), and the aff_id is not assigned to session.

 

This is only working when i add parameters on clean domain, i.e shop.com?aff_id=1

 

I've tried to edit dispatcher class but i really don't know what i have to change (i think that i have to change something near preg_replace in the createUrl function, but this is live installation, and i don't wanna broke the shop).

 

Is there a fix for that?

Ah, and we are using 1.5.4.1.

 

Thanks!

Link to comment
Share on other sites

Thanks for fast reply.

 

What i should add to URL schemas?

I think i can add only keywords, that are listed under the fields.

Is there an option to add custom optional parameter?

 

This is our route for products (the default one): {category:/}{id}-{rewrite}{-:ean13}.html

Link to comment
Share on other sites

HI rytek,

 

You are adding a custom route in Preferences>SEO URLS> Schema of URLs?

 

Please, can you explain it?

 

I have Affiliate module working with HTTP Referrer but I am not be able to get it work with Request URI

 

Please explain a bit :)

Link to comment
Share on other sites

Oh okay, you are asking a different question, this thread is about the Friendly URL. it's better to stay on topic or create a new thread for a new question. Can you do that and link me to it? I will merge these posts together. Thanks!

 

I asked it here: http://www.prestashop.com/forums/topic/265904-cant-setup-the-referrers-program/page__p__1326821#entry1326821

 

thanks!

Link to comment
Share on other sites

Hi Benjamin.

I've checked this topic, and i didn't find solution for my problem.

 

It doesn't matter how i configure my affiliate, it just doesn't work when i come to subpage with aff_id.

It only works when i come to mainpage.

 

Configuration of example affiliate user:

All fields are blank, except Request URI Include: %aff_id=whatever%

I've ever tried example configuration from one of the comments below the how-to (http://www.inmotionh...iliate-referrer).

 

Here is url of my shop:

http://audiomagic.pl

 

If i come to: http://audiomagic.pl?aff_id=whatever presta redirects me to http://audiomagic.pl/?aff_id=whatever (adding just ending slash). And everything works fine (opened pages, registrations, orders, everything is tracked).

But.. if i come to, for example:

http://audiomagic.pl...aff_id=whatever

Presta won't track anything.

 

I've added some code to track request_uri (just one variable in frontcontroller and one - requ in header.tpl).

But everything seems to be fine.

 

Can I ask, in what file is that tracking module?

How it works?

 

Thanks for help.

 

Maybe it is problem with server configuration or bad .htaccess file?

Here is my .htaccess file:

# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
# php_flag display_errors on
# php_value output_handler ob_gzhandler
AddType application/json .json
AddCharset utf-8 .json
php_flag zlib.output_compression On
php_value zlib.output_compression_level 5
php_value max_execution_time 12000
php_value max_input_time 6000
php_value default_socket_timeout 6000
php_value mysql.connect_timeout -1
php_value memory_limit 256M
php_flag magic_quotes_gpc off
php_flag  log_errors on
php_value error_reporting 5111
php_value error_log  /home/admin/domains/audiomagic.pl/PHP_errors.log
SetEnv PHPRC /etc/php5/apache2/php.ini
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.audiomagic.pl$ [NC]
RewriteRule ^(.*)$ http://audiomagic.pl/$1 [R=301,L]
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9]+)\-([0-9]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^audiomagic.pl$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9]+)\-([0-9]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^audiomagic.eu$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
FileETag INode MTime Size
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
 AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript
</IfModule>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

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

Ok, i found something interesting.

I've opened the _connections_source table in phpmyadmin and i've done search for %?% in request_uri column. Presta doesn't have any links with parameters after friendly url. It contains only url's with mainpage (domain).

 

There is issue with friendly urls. This configuration is removing all _GET parameters that are added on the end of url.

But I don't know where is mistake. I've generated new .htaccess, but problem did not disappear.

Link to comment
Share on other sites

  • 2 weeks later...

I had an issue just like this where using the friendly URLs didn't capture the affiliate code I was using. For me I encountered a work around by making up the affiliate links that I handed out to match the non friendly URL's. I found that adding the affiliate id to a non-friendly version of the URL for any link to my site would allow the affiliate information to be correctly recorded and give the credit where it was deserved. Here are a couple of example links for reference:

 

user regular URL for the affilate

http://site.com/index.php?id_product=53&controller=product&affiliate=10

 

instead of the friendly URL

http://store.com/category/99-item-name.html?affiliate=10

Link to comment
Share on other sites

I found another solution.

classes/ConnectionsSource.php, Lines 86-91:

if (isset($_SERVER['REDIRECT_URL']))
  $source->request_uri .= strval($_SERVER['REDIRECT_URL']);
 elseif (isset($_SERVER['REQUEST_URI']))
  $source->request_uri .= strval($_SERVER['REQUEST_URI']);
 if (!Validate::isUrl($source->request_uri))
  $source->request_uri = '';

 

Replace with:

 

if (isset($_SERVER['REQUEST_URI']))
  $source->request_uri .= strval($_SERVER['REQUEST_URI']);
elseif (isset($_SERVER['REDIRECT_URL']))
  $source->request_uri .= strval($_SERVER['REDIRECT_URL']);
 if (!Validate::isUrl($source->request_uri))
  $source->request_uri = '';

 

It's working for me, even with friendly urls. :)

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

I found another solution.

classes/ConnectionsSource.php, Lines 86-91:

if (isset($_SERVER['REDIRECT_URL']))
  $source->request_uri .= strval($_SERVER['REDIRECT_URL']);
 elseif (isset($_SERVER['REQUEST_URI']))
  $source->request_uri .= strval($_SERVER['REQUEST_URI']);
 if (!Validate::isUrl($source->request_uri))
  $source->request_uri = '';

 

Replace with:

 

if (isset($_SERVER['REQUEST_URI']) OR isset($_SERVER['QUERY_STRING']) )
  $source->request_uri .= strval($_SERVER['REQUEST_URI']);
elseif (isset($_SERVER['REDIRECT_URL']))
  $source->request_uri .= strval($_SERVER['REDIRECT_URL']);
 if (!Validate::isUrl($source->request_uri))
  $source->request_uri = '';

 

It's working for me, even with friendly urls. :)

 

Hi rytek, is this a solution just for you/your server? I'm wondering if its a bug or a serious issue because a lot of people don't have an issue with this module and Friendly URL's.

Link to comment
Share on other sites

Hi rytek, is this a solution just for you/your server? I'm wondering if its a bug or a serious issue because a lot of people don't have an issue with this module and Friendly URL's.

I don't know why this did not work normally for me. I found that only with that changes my affiliates are working.

I managed that the connections_source table does not contain any of the parameters, that i added in the addresses. That modification causes the data appears correctly in the request_uri field.

 

My $_SERVER['REDIRECT_URL'] variable was the cause of this problem - it was created, but empty, so i changed order of the conditions.

 

Oh, and i realized, that my code wasn't perfect. Checking if the QUERY_STRING variable is set is not necessary, dunno why i added that :)

 

Btw, i think that i'm not the only one who have that problem - Emittman seems to have the same issue.

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

×
×
  • Create New...