smalot / magento-client
Magento API 客户端 (SOAP v1)。允许对每个调用进行包装、依赖注入和代码补全。
v0.5.7
2016-06-02 10:32 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- atoum/atoum: dev-master
README
此库实现了 Magento SOAP v1 (标准) API。
功能
- 允许包装
- 允许依赖注入
- 允许代码补全
- 通过 composer 打包自动更新 (packagist.org)
注意: 此库与 Magento 公司 无关。
文档
此 API 是在 Magento SOAP API V1 之上设计的。
支持模块包括
- Mage_Catalog
- Mage_CatalogInventory
- Mage_Checkout
- Mage_Customer
- Mage_Directory
- Mage_Sales
- Enterprise_CustomerBalance
- Enterprise_CustomerGiftCard
- Mage_GiftMessage
- Mage_Core
- Store View
模块名称已标准化,以使其更加清晰
- 目录
- 目录库存
- 购物车
- 客户
- 目录
- 订单
- 客户余额
- 礼品卡
- 礼品信息
- 核心
- 商店
注意: login
和 logout
调用只有在需要时才会执行。
安装
使用 composer 下载
{ "require": { "smalot/magento-client": "*" } }
现在运行以下命令,让 composer 下载软件包
$ php composer.phar update smalot/magento-client
Composer 将安装软件包到项目的 vendor/smalot
目录,并创建/更新自动加载文件。
许可证
此库自 v0.5.0 版本起提供 MIT 许可证。查看完整许可证
LICENSE
实现
每个继承自 MagentoModuleAbstract
的 module manager
都将生成一个 action
。
动作可以直接执行或添加到 队列
。
如果直接执行,将生成一个 单个调用
,如果不是,则为 多个调用
。
单个调用
以下是一个示例代码,用于在单个调用中加载 default
网站的分类树。
<?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);
多个调用
多个调用仅适用于 Magento Soap v1
。
这就是为什么此库建立在 Magento Soap v1
之上的原因。
此功能允许将多个 SOAP 调用组合成一个单一的 HTTP 请求,这是一个非常好的优化实践。
它消除了 网络延迟
并减少了 Magento 启动过程。
通常,它可以用来在非常少的调用中同步整个产品目录。
<?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);
多调用支持回调
<?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();