pixelpeter / laravel5-woocommerce-api-client

Laravel 5 wrapper for the Woocommerce REST API
MIT License
125 stars 48 forks source link

[rest_invalid_param] #31

Closed fabianomoier closed 6 years ago

fabianomoier commented 6 years ago

What would be the correct way to send the value of the category that is in $ tr? Erro >> "Error: Parâmetro(s) inválido(s): categories [rest_invalid_param]"

$params_produto = [ //'title' => $produto->cd_item, 'name' => $produto->descricao, 'categories' => [ [ 'id' => $tr ], ], 'in_stock' => "true", 'manage_stock' => "true", ];

pixelpeter commented 6 years ago

This library is just a wrapper to simplify the integration into/with Laravel. Everything else works like the bare php package https://github.com/woocommerce/wc-api-php.

Therefor you can refer to the documentation to look up how things work. I just copied from the documentation to get it to work https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product

$data = [
    'name' => 'Premium Quality',
    'type' => 'simple',
    'regular_price' => '21.99',
    'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
    'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
    'categories' => [
        [
            'id' => 9
        ],
        [
            'id' => 14
        ]
    ],
    'images' => [
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
            'position' => 0
        ],
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
            'position' => 1
        ]
    ]
];

Woocommerce::post('products', $data);
fabianomoier commented 6 years ago

somehow have how to use the firstOrCreate I have a great list products that need to always keep updated I would love to use the firstOrCreate

pixelpeter commented 6 years ago

FirstOrCreate is provided by the Eloquent ORM specific to Laravel. The Woocommerce API does not provide such functionality and this library is only a wrapper adding no new functionality to the API.

Please have a close look at the documentation: https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product