News:

Support the VirtueMart project and become a member

Main Menu

CORS error in product creation- product category field disabled

Started by sladogana, June 14, 2019, 08:43:53 AM

Previous topic - Next topic

sladogana

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

Jörgen

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
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

sladogana

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

AH

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]
Regards
A

Joomla 4.4.5
php 8.1

Studio 42

@sladogana, leave $live_site empty if you have no reason to set it and all should always work perfect.