在我的申请中,需要有Magento所有国家的清单。现在我在Magento DevDocs中找到了一个具有Country 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>
答案 0 :(得分:0)
要从Magento检索数据到另一个应用程序,您可以使用XML-RPC,SOAP或REST。
我没有做太多PHP,但我在Python中做过类似的事情。我使用 XMLRPC 。
在PHP中应该有一个库来执行此操作。在文档中,他们提到了Zend的lib。刚刚找到this,看起来就像你想看一样。
要使用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的数据。