Wordpress plugin Error

Greeting,

I am trying to develop Wordpress plugin to integrate Erpnext with woocommerce, the problem is my Wordpress website and Erpnext in different server, so when I tried to call rest API I am getting error :

XMLHttpRequest cannot load http://xxx.xxx.x.x. No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I tried Ajax request with JSONP but it seems it is not supported .

Could you tell me what the best practice to develop such plugin for integration.

Regards,
Mohammed Redha

You should always call from wordpress server to erpnext server. Your client should pull data from your server, not erpnext server directly.

thank you for your suggesting, i do some example :

      <?php
 $params = array ('usr' => 'Administrator',
      'pwd' => *********);
 
// Build Http query using params
$query = http_build_query ($params);
 
// Create Http context details
$contextData = array ( 
                'method' => 'POST',
                'header' => "Content-type: application/json" ,
                'content'=> $query );
 
// Create context resource for our request
$context = stream_context_create (array ( 
'http' => $contextData,
 ));
 
// Read page rendered as result of your POST request
$result =  file_get_contents (
                  'http://**********/api/method/login',  // page url
                  false,
                  $context);
                  
                  echo '$res = '.$result ;

but i get this error:
Warning: file_get_contents(http://*******/api/method/login): failed to open stream: Connection timed out in /home//public_html/test1.php on line 22

Regards,
Mohammed Redha

Check this php sample: Sample ERPNext Magento Connector · GitHub

Hi,

Did you manage to make the plugin? I don’t see it yet on word-press plugins.

Regards,
Besfort

1 Like

Hi All,

We have the plugin ready.

http://jamaliinfo.com/downloads/woocommerce-erpnext-connector/50

it will sync products both ways
orders from woocommerce to erpnext (If COD- it will create sales order and if paid, it will create sales invoice)
customers from woocommerce to erpnext only if the customer has placed an order in woocommerce site.