Author Topic: CORS error in product creation- product category field disabled  (Read 257 times)

sladogana

  • Beginner
  • *
  • Posts: 2
  • A beginner
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

  • Global Moderator
  • Full Member
  • *
  • Posts: 2290
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: CORS error in product creation- product category field disabled
« Reply #1 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
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

sladogana

  • Beginner
  • *
  • Posts: 2
  • A beginner
Re: CORS error in product creation- product category field disabled
« Reply #2 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

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2929
  • VirtueMart Version: 3.6.0
Re: CORS error in product creation- product category field disabled
« Reply #3 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]
regards
A

Joomla 3.9.8
php 7.1

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3960
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: CORS error in product creation- product category field disabled
« Reply #4 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.