dev-master
9999999-devA simple Magento Integration using SOAP v1 and v2
MIT
The Requires
- php >=5.4.0
- illuminate/support 4.2.*
by Michael Kyle Martin
laravel soap magento
Wallogit.com
2017 © Pedro Peláez
A simple Magento Integration using SOAP v1 and v2
A simple and somewhat intuitive package for managing and interacting with the Magento SOAP Api. Compatible with Laravel 4 and Magneto SOAP v1 & v2., (*1)
Note: This package is still in the beta phase of development. I'd advise against using to test against a production Magento application. This package is for Laravel 4, if you're looking for a Laravel 3 version of this package, checkout MatteoCastiglioni's bundle, (*3)
To install via composer, add the following to your requirements, (*4)
"require": {
...
"tinyrocket/magento": "1.0.*"
...
},
Note: You may need to change your minimum-stability to dev, (*5)
Add the following to your Laravel Application configuration (app/config/app.php), (*6)
To your providers array, (*7)
'providers' => array(
...
'Tinyrocket\Magento\MagentoServiceProvider',
...
),
and to your aliases array, (*8)
'aliases' => array(
...
'Magento' => 'Tinyrocket\Magento\Facades\Magento',
...
),
Publish the the package configuration file by running the following in CLI, (*9)
php artisan config:publish tinyrocket/magento
The quickest way to get started with Magento integration is to add your connection(s) to the newly published configuration file. The file can be found in, (*10)
app/config/packages/tinyrocket/magento/config.php
There is no limit to the amount of connections that you can save, but you should set a default configuration to handle fallbacks. Inside of the configuration file, set the following with your Magento SOAP information., (*11)
Note: Use your store's base URL, not the URL for the SOAP endpoint. (e.g. http://magentostore.com rather than http://magentostore.com/api/soap?wsdl), (*12)
'connections' => [
...
'default' => [
'site_url' => 'http://magentohost',
'user' => '',
'key' => '',
'version' => 'v2'
],
...
]
The first parameter defines the name of the connection and should be unique. The API version is optional and will default to v2 for all connections, unless set otherwise., (*13)
An exhaustive list of possible methods is available on the Magento Website, (*14)
There are two basic methods used to interact with the SOAP Api, (*15)
For SOAP v2, (*16)
Magento::call()->someSoapRequest($requestParams) // Example Magento::call()->customerCustomerList()
For SOAP v1, (*17)
Magento::get('some.method', array($requestParams))
//Example
Magento::get('customer.list')
Alternatively, you can call methods directly for SOAP v2 requests, (*18)
Magento::someSoapRequest($requestParams)
// Example
$customerParams = array(
'email' => 'customer@example.org',
'firstname' => 'Dough',
'lastname' => 'Deeks',
'password' => 'password',
'website_id' => 1,
'store_id' => 1,
'group_id' => 1
);
$customerId = Magento::customerCustomerCreate($customerParams)
To make working with the SOAP API slightly more intuitive, some request results are returned as data objects and collections, inspired by Varien_Object and Varien_Object_Collection classes in Magento. These classes allow for the calling of information with some basic methods., (*19)
For SOAP responses that return a group of items, results are returned as object collections containing individual objects. These collections have four basic methods., (*20)
getCollection() - Returns all items as a group of objects, (*21)
getCount() - Returns number of items in the collection, (*22)
getFirstItem() - Returns the first response item, (*23)
getLastItem() - Returns the last response item, (*24)
foreach ( Magento::salesOrderList()->getCollection() as $order ) {
// Do stuff
For SOAP responses that return a single array item, or when iterating through a response collection, the MagnetoObject is used. This object comes with a couple methods that should be familiar to a Magento developer, (*25)
getData(optional $key) - Either returns all of an objects values or a single value that matches the provided key., (*26)
getId() - Returns the primary key of a given response object, (*27)
Like a Varien_Object you can also use a magic getter to pull information from an object. For example, you can use the following two methods to return the incrementId of an order object, (*28)
foreach ( Magento::salesOrderList()->getCollection() as $order ) {
// with data
echo $order->getData('increment_id')
// with magic getter
echo $order->getIncrementId()
}
For SOAP responses that return a single value or boolean, results are returned as a string/integer/boolean, (*29)
// will return an integer echo Magento::customerCustomerCreate($customerParams)
You have the option to use connections to multiple Magento websites. This can be done by either adding a secondary connection to the package configuration or by creating a connection on the fly. Connections are stored, so once registered, you can continue to use that connection by referencing it's unique identifier or the newly created connection object., (*30)
To create a connection on the fly, (*31)
$connection = Magento::createConnection($name, $url, $user, $key, $version)
To use a stored connection, (*32)
// SOAP v2
$orders = Magento::call($connection)->salesOrderList();
$orders = Magento::call('unique_identifier')->salesOrderList();
// SOAP v1
$customers = Magento::get('customers.list', null, $connection)
$customers = Magento::get('customers.list', null, 'unique_identifier')
To register a connection programmatically, (*33)
Magento::createAndRegisterConnection($name, $url, $user, $key, $version)
To see a list of available connections, (*34)
print_r( Magento::getAvailableConnections() )
Setting a primary connection Inherently, unless explicitly passed to a SOAP call, the default connection found in the configuration file is used when making all calls. To change which connection is used by default, you can use, (*35)
Magento::setPrimaryConnection('unique_identifier')
// Then use for subsequent calls
Magento::salesOrderList()
To see the currently primary connection, (*36)
echo Magento::getPrimaryConnection()
To remove a connection from memory, (*37)
Magento::unregister('unique_identifier')
To create a temporary connection, (*38)
$connection = Magento::createAndForgetConnection($name, $url, $user, $key, $version) // Then reference it in the call $orders = Magento::call($connection)->salesOrderList()
Getting Magic Getters for an object/collection Though used just to return data, you can use the following to get a list of available functions for a given object or collection, (*39)
// For a collection echo Magento::call()->customerCustomerList()->getFunctions(); // For an object $customer->getFunctions();
This will return something like, (*40)
Array
(
[0] => getCustomerId
[1] => getCreatedAt
[2] => getUpdatedAt
[3] => getStoreId
[4] => getWebsiteId
[5] => getCreatedIn
[6] => getEmail
[7] => getFirstname
[8] => getLastname
[9] => getGroupId
[10] => getDob
[11] => getPasswordHash
)
Test your SOAP connection Returns a boolean by default, but can return headers by flagging the second parameter as true., (*41)
var_dump( Magento::testConnection('unique_identifier', $returnHeaders = false) )
Get Magento Version Returns the build version of either the default connection or the one passed, (*42)
// Example return Community 1.9.0.0 var_dump( Magento::getMagentoVersion(optional $connection) )
Currently, there is no support of XML request and responses. But, it's planned for future releases., (*43)
Currently, there is no way enforce WS-I Compliance Mode., (*44)
A simple Magento Integration using SOAP v1 and v2
MIT
laravel soap magento