GithubHelp home page GithubHelp logo

ysqgit / magento-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smalot/magento-client

0.0 1.0 0.0 112 KB

Magento API Client (SOAP v1). Allows wrappers for each call, dependencies injections and code completion.

License: MIT License

PHP 100.00%

magento-client's Introduction

Magento API Client

This library implements the Magento SOAP v1 (standard) API.

Scrutinizer Quality Score Total Downloads Current Version License

Features:

  • allows wrappers
  • allows dependencies injections
  • allows code completion
  • auto-updated via composer packaging (packagist.org)

Note: This library is not related to Magento Company.

Documentation

This API is designed on top of Magento SOAP API V1.

Supported modules are :

  • Mage_Catalog
  • Mage_CatalogInventory
  • Mage_Checkout
  • Mage_Customer
  • Mage_Directory
  • Mage_Sales
  • Enterprise_CustomerBalance
  • Enterprise_CustomerGiftCard
  • Mage_GiftMessage
  • Mage_Core
  • Store View

Module's names has been standardized to be more clean :

  • Catalog
  • CatalogInventory
  • Cart
  • Customer
  • Directory
  • Order
  • CustomerBalance
  • GiftCard
  • GiftMessage
  • Core
  • Store

Note : login and logout calls are made only if needed.

Installation

Download using composer:

{
    "require": {
        "smalot/magento-client": "*"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update smalot/magento-client

Composer will install the bundle to your project's vendor/smalot directory and create/update an autoload file.

License

This library is provided under MIT license (since v0.5.0 release). See the complete license :

LICENSE

Implementation

Each module manager, which heritate from MagentoModuleAbstract, will generate an action.

Actions can be either directly executed or added to a queue.

If it is directly executed, it will generate a single call, if not, that's a multi call.

Single Call

Here is a sample code to load tree of categories of the default website in a single call.

<?php

// Include composer's autoloader mecanism
include 'vendor/autoload.php';

// Init config
$path    = 'http://domainname.tld/shop-folder/';
$apiUser = 'username';
$apiKey  = 'xxxxxxxxxxxxxxxxxxx';

// Create remote adapter which wrap soapclient
$adapter  = new \Smalot\Magento\RemoteAdapter($path, $apiUser, $apiKey);

// Call any module's class
$categoryManager = new \Smalot\Magento\Catalog\Category($adapter);
$tree            = $categoryManager->getTree()->execute();

var_dump($tree);

Multi Call

Multi call is only available on Magento Soap v1.

That's why this library is built on top of Magento Soap v1.

This function allows to group multiple soap calls into only one http request, which can be a very great optimization practice.

It removes network latency and reduce magento bootstrap processes.

Tipically, it can be used to synchronize a whole product catalog into very few number of calls.

<?php

// Include composer's autoloader mecanism
include 'vendor/autoload.php';

// Init config
$path    = 'http://domainname.tld/shop-folder/';
$apiUser = 'username';
$apiKey  = 'xxxxxxxxxxxxxxxxxxx';

// Create remote adapter which wrap soapclient
$adapter  = new \Smalot\Magento\RemoteAdapter($path, $apiUser, $apiKey);

// Build the queue for multicall
$queue = new \Smalot\Magento\MultiCallQueue($adapter);

// Call any module's class
$productManager = new \Smalot\Magento\Catalog\Product($adapter);
$productManager->getInfo(10)->addToQueue($queue);
$productManager->getInfo(11)->addToQueue($queue);
$productManager->getInfo(12)->addToQueue($queue);

// Request in one multicall information of 3 products (#10, #11, #12)
$products = $queue->execute();

var_dump($products);

Callback support for multicall

<?php

// Include composer's autoloader mecanism
include 'vendor/autoload.php';

// Init config
$path    = 'http://domainname.tld/shop-folder/';
$apiUser = 'username';
$apiKey  = 'xxxxxxxxxxxxxxxxxxx';

// Create remote adapter which wrap soapclient
$adapter  = new \Smalot\Magento\RemoteAdapter($path, $apiUser, $apiKey);

// Build the queue for multicall
$queue = new \Smalot\Magento\MultiCallQueue($adapter);

// Local catalog adapter
$localAdapter = new LocalAdapter(....);

// Store categories
$categoryManager = new \Smalot\Magento\Catalog\Category($adapter);
$categoryManager->getTree()->addToQueue($queue, array($localAdapter, 'updateCategories'));

// Store products into local catalog
$productManager = new \Smalot\Magento\Catalog\Product($adapter);
$productManager->getInfo(10)->addToQueue($queue, array($localAdapter, 'updateProduct'));
$productManager->getInfo(11)->addToQueue($queue, array($localAdapter, 'updateProduct'));
$productManager->getInfo(12)->addToQueue($queue, array($localAdapter, 'updateProduct'));

// Update local catalog
$products = $queue->execute();

magento-client's People

Contributors

smalot avatar john-tuck avatar 0s1r1s avatar vduglued avatar bitdeli-chef avatar whatwasmyusername avatar

Watchers

James Cloos avatar

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.