VirtueMart Forum

VirtueMart 2 + 3 => Product creation => Topic started by: sladogana on June 14, 2019, 08:43:53 am

Title: CORS error in product creation- product category field disabled
Post by: sladogana on June 14, 2019, 08:43:53 am
Hi,
we're experiencing the following problem with VirtueMart 3.4.2 on Joomla 3.9.8:
when creating a new product, the field named "Product Categories" appears as not usable because is showing a grey background with the word "Loading" and it's impossible to select a category (see the attached screenshot).
 We tried to activate the browser's console and found the following CORS error:
Access to XMLHttpRequest at 'http index.php?option=com_virtuemart&view=product:1 Access to XMLHttpRequest at 'https://www.ladante.it/administrator/index.php?option=com_virtuemart&view=product&type=getCategoriesTree&format=json&lang=it' from origin 'https://ladante.it' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Searching on the web we found that this problem can be solved adding the following piece of code in the htaccess file:
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

Nonetheless, this operation didn't solve the problem. The field "product categories" is still disabled
Title: Re: CORS error in product creation- product category field disabled
Post by: Jörgen on June 14, 2019, 09:09:12 am
Just a hunch I see https://www.ladante.it and https://ladante.it. Incorrect settings in htaccess ? Force either www or non www perhaps ?

Jörgen @ Kreativ Fotografi
Title: Re: CORS error in product creation- product category field disabled
Post by: sladogana on June 14, 2019, 10:14:49 am
Hi Jörgen,

thank you for your reply. Anyway, we just solved the problem. There was a field named "$live_site" in the configuration.php file whose value was "www.ladante.it". We changed it in "ladante.it" and the error disappeared.

Thanks again,

Best Regards
Title: Re: CORS error in product creation- product category field disabled
Post by: AH on June 14, 2019, 11:54:52 am
you should still consider routing www to non www in your .htaccess

Something like this:

###########################
  RewriteCond %{HTTPS}s on(s)|
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ http%2://%1%{REQUEST_URI} [R=301,L]
Title: Re: CORS error in product creation- product category field disabled
Post by: Studio 42 on June 14, 2019, 12:24:21 pm
@sladogana, leave $live_site empty if you have no reason to set it and all should always work perfect.