Giter VIP home page Giter VIP logo

laravel-woocommerce's Introduction

License Build Status StyleCI Quality Score Downloads Latest Version on Packagist

Description

WooCommerce Rest API for Laravel. You can Get, Create, Update and Delete your woocommerce product using this package easily.

Documentation

Authors

License

Eloquent Style for Product, Customer and Order

// Where passing multiple parameters
$products = Product::where('title','hello')->get();
OR
// You can call field with where clause
$products = Product::whereTitle('hello')->get();
// Fields name are more than one words or seperate by underscore (_). For example field name is `min_price`
$products = Product::whereMinPrice(5)->get();

// Where passing an array
$orders = Order::where(['status' => 'processing']);
$orders = Order::where(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc'])->get();

// Set Options
$orders = Order::options(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc'])->get();

// You can set options by passing an array when call `all` method
$orders = Order::all(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc']);

#Product Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#products

#Customer Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#customers

#Order Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#orders

You can also use WooCommerce Facade

use Codexshaper\WooCommerce\Facades\WooCommerce;

public function products()
{
  return WooCommerce::all('products');
}

public function product( Request $request )
{
  $product = WooCommerce::find('products/'.$request->id);
}

public function orders()
{
  return WooCommerce::all('orders');
}

public function order( Request $request )
{
  $order = WooCommerce::all('orders/'.$request->id);
}

public function customers()
{
  return WooCommerce::all('customers');
}

public function customer( Request $request )
{
  $customer = WooCommerce::all('customers/'.$request->id);
}

Use Facade Alias

use WooCommerce // Same as use Codexshaper\WooCommerce\Facades\WooCommerce;
use Customer // Same as use Codexshaper\WooCommerce\Models\Customer;
use Order // Same as use Codexshaper\WooCommerce\Models\Order;
use Product // Same as Codexshaper\WooCommerce\Models\Product;

laravel-woocommerce's People

Contributors

ancient-spirit avatar bfiessinger avatar chrishardie avatar codexshaper avatar maab16 avatar stylecibot avatar vivekaris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-woocommerce's Issues

JSON ERROR Syntax error

Hello

I'm working on local project using API from remote server, i followed your instructions but when i try to load $orders = Order->all(); on my Model, i see JSON ERROR: Syntax error

My environment

Laravel 6
PHP 7.2.9
Webserver nginx

A Strange Problem

Hey,@maab16

I ran into a strange question,hope you can help me out.

Use the below code to create a product, but always create 2(even 3) same products.

Product::create($data);

The more strange is the newly created two products have the same SKU, which is disallowed by WooCommerce.

any suggestion?!


PS1: I double product images make response change to slow, the product data contain more than 10 product images.

PS2: tried to change explorer to make sure the code executes only one time but failed.


Thank you
Qin

Retrieve shipping_lines details from an order.

Hello,

When I am searching a specific order, I retrieve all information but I cannot access to the shippings_lines details.
I am looking to retrieve.

Example from Request done on the Woocmmerce API using insomnia :

"shipping_lines": [
  {
    "id": 13257,
    "method_id": "bpost_shipping",
    "method_title": "bpost - international",
    "total": "11.57"
  }

In the result in my application Laravel I have :

+"shipping_lines": array:1 [▼
  0 => {#324 …8}
]

How can I retrieve the details ?

Thanks

Trying to get all categories

Good day,

Please help with this. This is my code to get all(105) categories, but I only get 50.

$pageNum = 1;
        $categories = [];

        while($pageNum != false) {
            $wpCategories = Category::all(['per_page' => 50, 'page' => $pageNum]);

            if(count($wpCategories) > 0){
                $categories = array_merge((array)$wpCategories, $categories);
                $pageNum ++;
                } else {
                    $pageNum = false;
                }
            }

dd($categories); 

I know this loops work, as I use it for retrieve all my product, but for some reason I cannot get it to work for categories?

Set config on run time instead of config file

Hi, first of all, thank you for your work!

i guess it would be very nice to have the ability to set config as arguments to the WoocommerceApi Class, bypassing the static config file, this would help in case of batch calling on multiple endpoints, i know you can use the builtin config([]) function but in my test it does not work if i run a loop through php artisan command

example code:

foreach(['A', 'B', 'C'] as $endpoint){
   config(['woocommerce.store_url' => '...']);
   config(['woocommerce.consumer_key' => '...']);
   config(['woocommerce.consumer_secret' => '...']);

  $orders = WooCommerce::all('orders', ...);
  // $orders will output the same results for every endpoint, 
  // because the config changes only for the first endpoint
}

hope this make sense! ;-)

Product::all(); only 10 results.

Hi, I am doing this:
$products = Product::all();

and I just get an array with 10 results, why? (I have thousands of products)

i want to update a long list of products at the same time

first of all, thank you very much for this package you really helped us a lot.

well i want to update a list of products, and i think "Product::update" changes only one by one and that will cause a lot of requests to the serve.. is there a possibility to push a whole array to the server using update
Thank you in advance

X-WP-Total and X-WP-TotalPages are case-sensitive

Hi,

I moved my store from one hosting to another and suddenly everything broke up. After debugging I found out I get Fatals on WooCommerceTrait / Undefined Index: X-WP-Total.

I've checked the response from last call and it seems like some servers modify headers and set them all lowercase, so I had to replace functions countResults and countPages with this:

    public static function getTotalWooPages()
    {
        $headers = WooCommerce::getResponse()->getHeaders();

        foreach ($headers as $key => $value) {
            if (strtolower($key) == 'x-wp-totalpages') {
                return (int) $value;
            }
        }

        return 1;
    }

    public static function getTotalWooItems()
    {
        $headers = WooCommerce::getResponse()->getHeaders();

        foreach ($headers as $key => $value) {
            if (strtolower($key) == 'x-wp-total') {
                return (int) $value;
            }
        }

        return 0;
    }

The model of this package causing issue in tinker (URGENT)

Example I have model Product will return error when I try to run (my model) Product::find(1); in tinker,
the issue I notice when I have model same name in package(this package) model.

suggestion make the model of this package unique ex. wooProduct wooOrder don't used common name.

error: Exception with message 'cURL Error: Could not resolve host: YOUR_WEBSITE_URL'

image

Only get 10 registers

Hello, in the last version only get 10 registers.

For example in: $orders = Order::all();

Thanks.

Deduct from stock

Hello.
Say I have 5000 of a certain product.
I need a way to deduct from stock, programmatically.
I didn't find a way to do so.

$data = [
'stock_quantity' => //need to get actual stock and deduct from it (ie 'actual_stock - 5')
];
$product = Product::update($product_id, $data);

Also, I can't retrieve only the stock_quantity from an item.. how can I do that?
Something like this:

$product = Product::find($product_id);
$product->get_stock_quantity();

Thanks in advance!

[woocommerce_rest_cannot_view]

Server Ubuntu
Nginx
Mysql 5.7
PHP 7.2

Exception : Error: Desculpe, não pode listar os recursos. [woocommerce_rest_cannot_view]

at F:\Desenvolvimento\Projects\bpm\vendor\codexshaper\laravel-woocommerce\src\Traits\QueryBuilderTrait.php:241
237| $totalResults = WooCommerce::countResults();
238|
239| return $totalResults;
240| } catch (\Exception $ex) {

241| throw new \Exception($ex->getMessage(), 1);
242| }
243| }
244|
245| /**

Exception trace:

1 Codexshaper\WooCommerce\Models\Product::count()
F:\Desenvolvimento\Projects\bpm\vendor\codexshaper\laravel-woocommerce\src\Models\BaseModel.php:45

2 Codexshaper\WooCommerce\Models\BaseModel::__call("count", [])
F:\Desenvolvimento\Projects\bpm\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:237

Please use the argument -v to see more details.

Query orders

It would be cool if you could query the results like:

$orders = Order::where('status', 'processing')->get();

Using multiple connections

Is it possible to pass the API keys directly from the controller to use differents WordPress connections without be required to edit the config?

Thanks

ErrorException: Undefined index: X-WP-Total

Hello,
when i'am trying to get total products
$totalResult = WooProduct::count();
i've got error exception:
message | "Undefined index: X-WP-Total"
file | "/Applications/MAMP/htdocs/swati/vendor/codexshaper/laravel-woocommerce/src/Traits/WooCommerceTrait.php"
line | 114

problem seems coming from case used, if i update "X-WP-Total" to "x-wp-total" it's work.

As i need to use for multisite, some of them works only if not lowercase and some other with.
How can i fix this to make it works for all ?

Thanks

Paginate for Term::all($attribute_id)

Hi,
I'm trying to get all the terms of an attribute, but with the pagination of Wordpress I can't reach the goal with the following simple statement:

$myterms=Term::all($attribute_id);

I try with the following:

$next_page = null;
do {
    $myterms = WooCommerce::all("products/attributes/$attribute_id/terms", ['per_page' => 100, 'page'=> $next_page]);
    $next_page = WooCommerce::next();
    // do what you want with $myterms
} while ($next_page > 0);

Maybe there is a more elegant way?

Database migration

Do you planing to store local data so the sync will bi possible for example for multistore purpose?

Thanks

Access orders content

Hi @maab16,

When I do a find on an order I do:
$order = Order::find($id);
I get all the information in the $order object. But I am wondering how to access the data:
When I do $order->number, I got an error and when I do $order['number'] it's fine
When I do $order['billing']['first_name'] I got an error but when I do $order['billing']->first_name, it's fine.

I saw that the function find returns an collection object, do you have any inputs on that ?

Many thanks in advance,

David

Retrieve shipping_lines details

Hello,

When I am searching a specific order, I retrieve all information but I cannot access to the shippings_lines details.
I am looking to retrieve.

Example :

Retrieve products from Orders

Hello,
Can I retrieve list of products from orders with all information ?,
for example, I want to print all orders and under each order I want to list the products with the sku, image and other meta data.

I saw theres line_items but its not returning all the fields

Thanks

Note class missing

Hi,
I am using the latest version and I need to retrieve the note of an order and it seems the Note class is missing....

Can you check ?

Thanks,

how to get product variations?

Hi,

Is there any way to get all variations for special product?

This product is "variable" type, I want to get all variations' SKUs

Thank you
Qin

Product not find after update of the stock quantity to 0

Hi,

I have an issue after the update of the quantity to 0 (out of stock).

Product:all() return the correct list but after the update of the quantity to 0 (out of stock), Product:all() is not returning the product update to 0.

The product is availble in Woocommerce console and is correctly marked 'out of stock' on the front end.
I can retrieve the product based on his ID but it is missing from the list generated by product;all()

I see :
If the quantity = 0, missing in the list,
If the quantity is > 0 or blank, it is present in the list returned by product::all().

Any idea ?

Get product's reviews

Dear @maab16

According to the API document, I do the following command in order to get all the reviews for a specific product:
$reviews = Review::all(['product'=>[$id]]);

But I don't have any results event if I have a review in my database for the $id passed to the command.

FYI information, the review is not yet approved, Is there any restriction to list the on "hold" reviews ?

Many thanks in advance for your feedback.

Order Notes

Hi,

I saw in the Order Model that there is a possibility to add order notes (createNote($orderId)), how can I use this in my code?

Tried something like this, but that doesn't work:

$WcOrder = WcOrder::create($data);

$note = [
      'author' => 'System',
      'note' => 'This order was created from order #' . $order->id
];

$WcOrder->createNote($note);

API Keys,

How would i approach storing the api keys inside the database? and use those rather than config files im currently building a multi tenancy app

JSON ERROR: Syntax error

Sometimes may be you get this error. If you are using it first time then make sure you followed some steps

  1. Enable mod_rewrite in your server
  2. Make sure you have .htaccess file in your WordPress root directory. Contents should look like
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RewriteRule ^index\.php$ - [L]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /index.php [L]
</IfModule>
  1. Make sure your URL permalink is Post name

Is it compatible with WC4.0+

Hi,

Does laravel-woocommerce compatible with woo-commerce 4.0+, i have tried it ,but found curl error.

Env:
Laravel 6.X PHP 7.3

Best Regards

Multi languages

Hi,
First of all, many thanks for this very useful package.

I have a wordpress in 3 languages.

I was wondering how to handle the management of products translations (name, description, images). Do you have any idea how to handle that ?

Many thanks in advance,

David

How to add an existing attribute to a product ?

Dear @maab16 ,

I have created an attribute using the Attribute facade,.
I want to attach this attribute to an existing product using product update passing the following array as data:
$aData['attributes']=[
'id' => $attribute->id,
'name' => $attribute->name,
'position' => 0,
'visible' => false,
'variation' => false,
'options' => $aTerms,
];
Where $aTerms contains all terms name of the attribute's terms.

But I got the following error: attributes [rest_invalid_param]

Do you have any idea how to deal with this ?

Many thanks in advance,

David

Search where('name', 'like', 'abcde%') possible ?

Hi,

I have an issue when I try to query the Woocommerce products using Where ... like

Product::where('name', 'like', 'abcde%')->get();

Possible or do we need to setup a filter based on all products ?

i keep getting cURL Error:

i followed the instructions from your docs and i tried to test it:

part of my code:
use Codexshaper\WooCommerce\Facades\Product;

class InventoryController extends Controller
{
//
public function list(){
$products = Product::all();

    return view('inventory')->with('products', $products);
} 

}

and when i run my code i get : cURL Error:

Codexshaper\WooCommerce\WooCommerceApi::all
C:\Users***\vendor\codexshaper\laravel-woocommerce\src\Traits\WooCommerceTrait.php:23

Status of products created in WP from Laravel

I have implement creation of product in WP from Laravel and it works great !!
But, the status of the product created in WP seems to be "readonly" even if the status is published and visibility public. Which means that it does not appear in the shop until I edit it and simply click on "Update".

Do you have any feedback on that ?

Many thanks for your feedback.

FYI I use WP 5.4 with WOO 4.0.1

I can't update a product?

I can't update or delete products only add. Do you know why? it break on ;

` * @param string $endpoint API endpoint.

 * @param array  $data

 *

 * @return array

 */

public function update($endpoint, $data)

{

    try {

        self::__construct();



        return $this->client->put($endpoint, $data);

    } catch (\Exception $e) {

        throw new \Exception($e->getMessage(), 1);

    }

}`

Exception Error: []

Catching exceptions from the WooCommerce API

How do I catch exceptions like this from the response in my API calls:

"Error: Invalid ID. [woocommerce_rest_product_invalid_id]"

Not sure how do do this with your traits

$product = WooCommerce::find('products/'.$request->id);

cURL Error: Operation timed out after 15000 milliseconds with 0 bytes received

Getting these issues on the server after deploying the code. It's working fine in localhost.

Even I am adding the dummy products ie

$data = [
			'name' => 'TBI Test Product',
			'type' => 'simple',
			'regular_price' => '10.00',
			'description' => 'Simple product full description.',
			'short_description' => 'Simple product short description.',
			'categories' => [
				[
					'id' => 1
				]
			],
			'images' => [
				[
					'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
				],
				[
					'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg'
				]
			]
		];
		
		$product = Product::create($data);



**Complete error is:**

message: "cURL Error: Operation timed out after 15001 milliseconds with 0 bytes received",…}
exception: "Exception"
file: "/home/development/public_html/project/vendor/codexshaper/laravel-woocommerce/src/Traits/WooCommerceTrait.php"
line: 63
message: "cURL Error: Operation timed out after 15001 milliseconds with 0 bytes received"
trace: [{,…}, {,…}, {,…}, {,…},…]

Pagination

Hello everybody,
can someone with a kind soul help me understand how to make a pagination of orders with laravel 8?
I've followed the documentation but can't.
More precisely I can only set how many orders I want per page but I cannot figure out how to use $ orders ['meta] with the links () method of blade.

This is my controller:

image

this is my blade view

image

this is the error

Call to a member function links() on array (View: C:\Users\andrea\Desktop\developer\semprofile\ipanel\epanel\resources\views\Orders\index.blade.php)

Sync Product Images to WP

Hi,

I am wondering how to sync product images to WP as the WOO API does not accept remote URL images.

Do you have any idea if it is possible to do that ?

Many thanks in advance.

BR

David

get all data where number is identified

Hello there,
i have an issue when i use $order = Order::where('number','68876')->get();
is returning all order data,
i want to show number(order_id) is only 68876

thanks

Filter by categories

Hello,
The returned categories from the Product API are as json object
Can I filter products by category lets say Product::where("categories->name","clothes")->get(); ??
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.