3
votes

I am creating products from external in woocommerce site. My code is like bellow:

if($_POST["Type"] == "CREATE"){
         $data = array(
            'product' => array(
                'title' => $_POST["Title"],
                'type' => 'simple',
                'regular_price' => $_POST["Regular_price"],
                'description' => $_POST["Description"],
                'short_description' => $_POST["Short_description"],
                'categories' => array(
                    $_POST['CategoryName']
                ),
                'images' => array(
                    array(
                        'src' => $_POST["Image_url"],
                        'position' => 0
                    ),
                    array(
                        'src' => $_POST["Image_url"],
                        'position' => 1
                    )
                )
            )
        );
    $res = $client->products->create($data);
}

When using $_POST["Image_url"] such like http://app.test.net:8080/test/img/company-logo.png gives the following error:

PHP Fatal error:  Uncaught exception 'WC_API_Client_HTTP_Exception' with message 'Error: Error getting remote image

But if we give a normal url(url do not contain the specific port) such like http://test.com/wp-content/uploads/2016/02/test.png it's working properly.

How to resolve this?

2
i have tested only for the product.Also debug the api in the server side can't find the error.Kasun lakmal
no using original theme directly.Theme name is BlancoKasun lakmal
my images in separate web server running on port 8080Kasun lakmal

2 Answers

2
votes

In my case above mentioned code in the such a URL (http://app.test.net:8080/api/v1/product.php). Calling this API from .net application by (http://appname.test.net). Both are having the same domain part (test.net).

There fore difficult to find the URL to woo commerce.I have change URL the of .net application by my server configuration(I have using virtual hosts).Then it works properly.

1
votes

---- (Edit 2) ----

Sorry but your question is Not clear at all. You have to update it, because it is very incomplete and fuzzy. Same thing for the title.

The medias images are located in a 2nd server on port 8080, right…

Form me the problem is here in:

'images' => array(
    array(
        'src' => $_POST["Image_url"],
        'position' => 0
    ),
    array(
        'src' => $_POST["Image_url"],
        'position' => 0
    )
)

with 'src' => $_POST["Image_url"]

Have a look to this interesting related thread: Synchronize external database with woocommerce database