Git Product home page Git Product logo

magento-client-php's Introduction

Magento Client Library For PHP

Build Status Coverage Status Total Downloads Latest Stable Version

Provides a client library to make REST and XMLRPC calls to a Magento instance.

Installation

Magento Client Library For PHP can be installed with Composer by adding it as a dependency to your project's composer.json file.

{
    "require": {
        "cpliakas/magento-client-php": "*"
    }
}

After running php composer.phar update on the command line, include the autoloader in your PHP scripts so that the SDK classes are made available.

require_once 'vendor/autoload.php';

Please refer to Composer's documentation for more detailed installation and usage instructions.

Usage

XMLRPC

The following example returns a list of products with SKUs that start with "123":

use Magento\Client\Xmlrpc\MagentoXmlrpcClient;

$client = MagentoXmlrpcClient::factory(array(
    'base_url' => 'http://magentohost',
    'api_user' => 'api.user',
    'api_key'  => 'some.private.key',
));

$filters = array(
    'sku' => array('like' => '123%'),
);

$result = $client->call('catalog_product.list', array($filters));

Rest

The following example returns a list of products:

use Magento\Client\Rest\MagentoRestClient;

$client = MagentoRestClient::factory(array(
    'base_url'        => 'http://magentohost',
    'consumer_key'    => 'abc123...',
    'consumer_secret' => 'def456...',
    'token'           => 'ghi789...',
    'token_secret'    => 'jkl012...',
));

$result = $client->get('/api/rest/products')->send()->json();

Refer to Guzzle's documentation for more information on sending requests to the server.

magento-client-php's People

Contributors

cpliakas 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

magento-client-php's Issues

Custom Product Options error

ResponseException in ResponseException.php line 33:
Invalid option type.
in ResponseException.php line 33
at ResponseException::fault(array('faultCode' => '104', 'faultString' => 'Invalid option type.')) in Client.php line 162
at Client->call('call', array('d308853df3d0ebedb21ce35a4195d15c', 'product_custom_option_value.list', array('4'))) in MagentoXmlrpcClient.php line 90
at MagentoXmlrpcClient->call('product_custom_option_value.list', array('4')) in E:\www\builder\app\Integration\Magento\RestXml\Library\Catalog\ProductCustomOptions.php line 93
at ProductCustomOptions->values('4') in E:\www\builder\app\Integration\Magento\Helper\Manager\Products.php line 363
at Products->_fillProductOptionValues(object(ProductsOptions)) in Products.php line 354
at Products->_fillProductOptions(object(Products)) in Products.php line 221
at Products->App\Integration\Magento\Helper\Manager\{closure}(object(MySqlConnection)) in Connection.php line 570
at Connection->transaction(object(Closure), '5') in DatabaseManager.php line 317
at DatabaseManager->__call('transaction', array(object(Closure), '5')) in Facade.php line 237
at Facade::__callStatic('transaction', array(object(Closure), '5')) in Products.php line 222
at Products->populateProducts() in Manager.php line 69
at Manager->App\Integration\Magento\Helper\{closure}(object(MySqlConnection)) in Connection.php line 570
at Connection->transaction(object(Closure), '5') in DatabaseManager.php line 317
at DatabaseManager->__call('transaction', array(object(Closure), '5')) in Facade.php line 237
at Facade::__callStatic('transaction', array(object(Closure), '5')) in Manager.php line 72
at Manager->_execute() in Products.php line 45
at Products->execute() in Manager.php line 52
at Manager->execute() in MagentoController.php line 107
at MagentoController->progress()

This is my stack trace with errors.
But propably i cant find "product_custom_option_value.list"

How do you get the OAuth token?

As I understand it Magento uses three-legged OAuth 1.0a (source: http://devdocs.magento.com/guides/m1x/api/rest/introduction.html#RESTAPIIntroduction-CreateasimpleproductasanAdminuserwithOAuthauthentication). In three-legged OAuth 1.0a you start with a key / secret and get the token from the service (http://oauthbible.com/#oauth-10a-three-legged). How do you get the token using this library? Are you supposed to write something to get the token before you use this library?

Forming POST Requests

I've found it easy to make GET requests using the client, but having problems trying to fire a products object onto a POST request. Something like:

$product = [
"description" => "Test description",
"gift_message_available" => 1,
"meta_description" => "Test meta",
"meta_keyword" => "Test keyword",
"meta_title" => "Test title",
"msrp" => 11.015000000000001,
"msrp_display_actual_price_type" => 1,
"msrp_enabled" => 1,
"name" => "Test",
"price" => 25.5,
"attribute_set_id" => "4",
"short_description" => "Test short description",
"sku" => "simple4f5490f31959f",
"special_from_date" => "02/16/2012",
"special_price" => 11.199999999999999,
"special_to_date" => "03/17/2012",
"status" => 1,
"stock_data" => [ "backorders" => 1,
"enable_qty_increments" => 0,
"is_in_stock" => 0,
"is_qty_decimal" => 0,
"manage_stock" => 1,
"max_sale_qty" => 1,
"min_qty" => 1.5600000000000001,
"min_sale_qty" => 1,
"notify_stock_qty" => -50.990000000000002,
"qty" => 1,
"use_config_manage_stock" => 1,
"use_config_min_qty" => 1,
"use_config_min_sale_qty"=> 1,
"use_config_max_sale_qty" => 1,
"use_config_backorders"=> 1,
"use_config_enable_qty_inc"=>1,
"use_config_notify_stock_qty"=>1 ],
"tax_class_id" => "2",
"type_id" => "simple",
"use_config_gift_message_available" => 0,
"visibility" => "4",
"weight" => 125
];

$request = $client->post('/api/rest/products', ['json' => [$product]])->send()->json();

I know this product object works as its been used over a REST client on my mac. Here's my error.

Client error response [status code] 400 [reason phrase] Bad Request [url] http://

Can't for the life of me figure out why?

Many thanks in advance.

doesn't handle base_url with path componenst

if the "base_url" contains path components (because Magento is not installed in "/" on the web server, this part of the path is stripped, resulting in a 404.
This should not happen.

add documentation for REST POST requests

e.g. for uploading images, other request types then GET (such as POST, DELETE, HEAD,...) must be done.
The Readme.md should be updated to cover at least the POST case.

How can I update products on magento?

I tried to use the put function to update my products in magento, but it doesn't work. Can you help me?
$result = $client->put('/api/rest/products/1333', null, ["price" => "50"])->send();

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.