dsilva94 / magento-client-v2
Magento API客户端(SOAP v1)。允许为每个调用创建包装器、依赖注入和代码补全。
v1.0.6
2017-04-18 23:43 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- atoum/atoum: dev-master
This package is not auto-updated.
Last update: 2024-09-20 20:41:41 UTC
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
。
动作可以是直接执行,也可以添加到队列
中。
如果直接执行,将生成一个单个调用
,如果不是,则为多个调用
。
单个调用
以下是一个示例代码,用于在单个调用中加载默认网站的分类树。
<?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();