![](/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.