VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: thefbi on December 19, 2016, 18:10:01 PM

Title: Error updating cart
Post by: thefbi on December 19, 2016, 18:10:01 PM
Hello,

i know this question is current, but i have an error when updating cart.
I have make a new template with Themler, and when put a product in cart, it use the javascript method.

I have tested my site in local mode, and the function work fine, but when i am in live, i have the error :
XMLHttpRequest cannot load https://www.energie-sante.ch/index.php?option=com_virtuemart&nosef=1&view=c...ty%5B%5D=1&option=com_virtuemart&view=cart&virtuemart_product_id%5B%5D=340. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://energie-sante.ch' is therefore not allowed access.

But i dont understand why it work on local and not in live ???

Any idea ?

I have VM 3.0.18 and Joomla 3.6.5

Regards
Title: Re: Error updating cart
Post by: thefbi on December 19, 2016, 18:28:39 PM
Is the https can be cause problem ?
Title: Re: Error updating cart
Post by: thefbi on December 19, 2016, 18:44:54 PM
Hello again, i have find the problem. It is www and non www conflict.
I have to find how i can fix it now
Title: Re: Error updating cart
Post by: thefbi on December 19, 2016, 18:51:27 PM
Here we are !

I have make a htaccess redirection (http://dense13.com/blog/2008/02/27/redirecting-non-www-to-www-with-htaccess/) and now all my non www is redirected at www and my problem is gone. :)
Title: Re: Error updating cart
Post by: Milbo on December 19, 2016, 23:05:29 PM
You should do it exactly the opposite. Dont use www, it is old. And please be a aware, the add to cart for the product works with the form. So using a js should just fire the form
Title: Re: Error updating cart
Post by: thefbi on December 19, 2016, 23:11:09 PM
Hello, i have say JavaScript but I don't know anything in coding...
If a put non www, it don't work because VM try to call a www URL.
But I don't know where I can change this. You have the URL in my post before.
Title: Re: Error updating cart
Post by: thefbi on December 20, 2016, 20:55:14 PM
Hello again, i have made some tests and i can't find where is the configuration for this call.

The problem is here : If i am in the site wit URL without www, i can't load to cart. If i am with www, it is OK.
You can see in my screenshot the error when i am in non www url. You see Virtuemart can't load https://www.energie-sante.ch...... Because origin (i dont understand what is it) is https://energie-sante.ch

So for now, the only way i have is to force non www to www.

Can somebody tell me an idea to find where i can define it will be the https://energie-sante.ch wich is called for load ?

I can't load attachment... upload folder is full... So link to my screenshot : http://energie-sante.ch/media/energie-sante-2.jpg
Title: Re: Error updating cart
Post by: GJC Web Design on December 20, 2016, 22:47:32 PM
if u force no www doesn't it work?

the 'call' is the add to cart form which should take your "root" url

<form method="post" class="product" action="#">
Title: Re: Error updating cart
Post by: thefbi on December 20, 2016, 23:03:22 PM
Hello,
no, i have already tested it :)

OK, but the "Root" url, i can define it ?
I have try in the "Live site" in the configuration.php but dosent work...
Title: Re: Error updating cart
Post by: GJC Web Design on December 21, 2016, 17:16:07 PM
if u set it by htaccess it should be global

it takes what was requested

remove "Live site" -- only causes problems
Title: Re: Error updating cart
Post by: thefbi on December 21, 2016, 22:05:25 PM
OK, but how can i set in htaccess ?
Title: Re: Error updating cart
Post by: thefbi on December 21, 2016, 22:08:30 PM
Here is my htaccess :

### ===========================================================================
### Security Enhanced & Highly Optimized .htaccess File for Joomla!
### automatically generated by Admin Tools 3.6.6 on 2015-12-18 09:56:02 GMT
### Auto-detected Apache version: 2.5 (best guess)
### ===========================================================================
###
### The contents of this file are based on the same author's work "Master
### .htaccess", published on http://snipt.net/nikosdion/the-master-htaccess
###
### Admin Tools is Free Software, distributed under the terms of the GNU
### General Public License version 3 or, at your option, any later version
### published by the Free Software Foundation.
###
### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
### !!                                                                       !!
### !!  If you get an Internal Server Error 500 or a blank page when trying  !!
### !!  to access your site, remove this file and try tweaking its settings  !!
### !!  in the back-end of the Admin Tools component.                        !!
### !!                                                                       !!
### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
###

##### RewriteEngine enabled - BEGIN
RewriteEngine On
##### RewriteEngine enabled - END

## Send ETag (selected method: )
##### Rewrite rules to block out some common exploits -- BEGIN
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_(en|de)code\(.*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
##### Rewrite rules to block out some common exploits -- END
##### Advanced server protection rules exceptions -- BEGIN
##### Advanced server protection rules exceptions -- END

##### Advanced server protection -- BEGIN

##### Advanced server protection -- END

##### Joomla! core SEF Section -- BEGIN
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##### Joomla! core SEF Section -- END

#RewriteCond %{HTTP:X-Forwarded-Proto} !https   
#RewriteRule (.*) https://www.energie-sante.ch/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]



#Force non-www:
#RewriteCond %{HTTP_HOST} ^www\.energie-sante\.ch [NC]
#RewriteRule ^(.*)$ http://energie-sante.ch/$1 [L,R=301]
Title: Re: Error updating cart
Post by: GJC Web Design on December 21, 2016, 23:14:27 PM
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]



#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.energie-sante\.ch [NC]
RewriteRule ^(.*)$ http://energie-sante.ch/$1 [L,R=301]
Title: Re: Error updating cart
Post by: thefbi on December 22, 2016, 06:28:12 AM
Yes, I have already try this, that's why it is in my htaccess, but VM still want call www.
Title: Re: Error updating cart
Post by: GJC Web Design on December 22, 2016, 12:29:10 PM
then needs further investigation on YOUR site.. no one else reports this problem so it is site specific, -- template, plugin etc etc
Title: Re: Error updating cart
Post by: thefbi on December 22, 2016, 12:39:29 PM
Ok, I will try to investigate. I come back when further informations
Thank you
Title: Re: Error updating cart
Post by: thefbi on December 23, 2016, 18:29:09 PM
Hello,

when i try to do www => non www, i have now another error :

Mixed Content: The page at 'https://energie-sante.ch/accueil-boutique/consommables-argent-colloidal.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://energie-sante.ch/index.php?option=com_virtuemart&nosef=1&view=cart&t...255D=1&option=com_virtuemart&view=cart&virtuemart_product_id%255B%255D=208'. This request has been blocked; the content must be served over HTTPS.

But the first error not appear

EDIT : No, it because i have modify the url in the Google search console to define non www. But dosent work...
Title: Re: Error updating cart
Post by: Jörgen on December 23, 2016, 20:36:24 PM
I think You should check that You don´t have this:
Quote

#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.energie-sante\.ch [NC]
RewriteRule ^(.*)$ http://energie-sante.ch/$1 [L,R=301]

It should probably say https://....  :)

regards

Jörgen @ Kreativ Fotografi
Title: Re: Error updating cart
Post by: thefbi on December 23, 2016, 20:40:38 PM
Yes, i have see it after and try to modify, but the problem still here.

But the main problem is why it will call www on my cart button. It is this i have to find.... I have try with the Protostar template and the problem still here, so not a template problem.
Title: Re: Error updating cart
Post by: thefbi on December 23, 2016, 23:27:51 PM
OK, i have make a new site and now it work when i am in non www. But it dosent work when in www, because error of mixed content...

I dont understand but have forced https and non www.
Title: Re: Error updating cart
Post by: thefbi on December 23, 2016, 23:33:20 PM
EDIT : I have put only the https redirection and it seem to be ok now with and without www.

Can somebody make a test and tell me if he can add to cart with and without www please : https://www.energie-sante.ch/accueil-boutique/consommables-argent-colloidal

Thanks a lot by advance
Title: Re: Error updating cart
Post by: GJC Web Design on December 24, 2016, 17:27:24 PM
Yes, can add on www and non www
Title: Re: Error updating cart
Post by: thefbi on December 24, 2016, 17:32:39 PM
Quote from: GJC Web Design on December 24, 2016, 17:27:24 PM
Yes, can add on www and non www

Cool, thank you :)