![](/img/trans.png)
[英]Magento: Get all shipping costs for all countries for a product in Magento backend
[英]Laravel + Magento - Retrieve list of all countries from Magento
在我的应用程序中,它需要有一个来自 Magento 的所有国家/地区的列表。现在我在 Magento DevDocs 中找到了一个链接,其中有一个国家/地区 API。但是我如何通过使用 for 在我的应用程序中实现所有国家/地区的列表,例如,一个foreach? 我需要这个列表,这样我就可以将选定的值插入到我的数据库中。 这是我找到的链接: Link to the docs
这是需要显示的形式:
<div class="form-group">
<span class="andcode-dropdown">
<label for="country" class="label-muted">Land <span class="required">*
</span></label>
<select class="form-control andcode-select" name="country_name" id="country">
<option selected>Kies een land...</option>
@foreach($countries as $country)
<option>{{ $country->country_name }}</option>
@endforeach
</select>
</span>
</div>
要将数据从Magento检索到另一个应用程序,可以使用XML-RPC或SOAP或REST。
我没有做太多的PHP,但是我在Python中做过类似的事情。 我使用了XMLRPC 。
在PHP中应该有一个库来这样做。 在文档中,他们提到了Zend的lib。 刚发现这个 ,看起来像您可能想看看。
要使用该API,您必须获取凭据和访问权限。 在Magento中,转到“ System > Web Services > SOAP/XMLRPC Users|Roles
并创建一个用户,向该用户授予一些访问国家API的特权。
然后在您的PHP代码上,在连接上设置凭据。
$client = new Zend_XmlRpc_Client('http://magentohost/api/xmlrpc/');
// If somestuff requires api authentification,
// we should get session token
$session = $client->call('login', array('apiUser', 'apiKey'));
然后通过检索列表
$countries = $client->call('call', array($session, 'directory_country.list'));
由此,您的$countries
变量应具有Magento的数据。
首先,由于您得到的是空列表,因此我怀疑您在调用之前未授权请求,要在 Magento 中使用 RestAPI,您必须创建一个集成记录以生成 API 密钥以访问 Magento 核心 API。
如需参考,请点击此链接: https://www.beehexa.com/devdocs/how-to-create-an-integration-in-magento-2
当您手头有 API 密钥时,将其放入您的 header 授权中,然后再次尝试获取您需要的 API(在本例中为国家/地区 API)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.