2014-11-06 70 views
1

我正在嘗試創建用戶列表,並且想要向每個客戶顯示客戶組名稱。 我用:如何使用Bigcommerce API獲取客戶組名稱

$customers = Bigcommerce::getCustomers();

爲了獲取客戶信息。

以上函數返回客戶組ID;任何人都可以幫助我告訴我如何獲得客戶組名稱?

我對Bigcommerce API非常陌生 - 任何幫助將不勝感激。

感謝

回答

0

我假設你使用的是PHP庫在這裏找到: https://github.com/bigcommerce/bigcommerce-api-php

使用此功能可以打印所有客戶的完整信息:

$customers = Bigcommerce::getCustomers(); 
foreach($customers as $customer) { 
    print_r(Bigcommerce::getCustomer($customer->id)); 
} 

你會不過,請注意,這在返回的列表中,它只給出一個客戶組ID。爲了獲得與客戶組ID相關聯的名字,你就必須運行:

$group_name = Bigcommerce::getResource('/customer_groups/' ."$GROUP_ID"); 
//Where $GROUP_ID is the ID gotten from the first snippet. 

下面是它打印的第一個名字,姓氏,和客戶的電子郵件,以及名的小例子其相關客戶羣:

$echo "~~~~~~~~~~~~~~~~~\n"; 
$customers = Bigcommerce::getCustomers(); 
foreach ($customers as $customer) { 
    echo "Customer Info: \n"; 
    echo "First Name: $customer->first_name \n"; 
    echo "Last Name: $customer->last_name \n"; 
    echo "eMail: $customer->email \n"; 

    $customer_group = Bigcommerce::getResource('/customer_groups/' ."$customer->customer_group_id"); 
    echo "Customer Group: $customer_group->name \n"; 
    echo "~~~~~~~~~~~~~~~~~\n"; 
} 

應該輸出什麼類似於:

~~~~~~~~~~~~~~~~~ 
Customer Info: 
First Name: John 
Last Name: Doe 
eMail: [email protected] 
Customer Group: Retail 
~~~~~~~~~~~~~~~~~ 

請參考下面的網址上的對象更多信息$客戶退回: https://developer.bigcommerce.com/api/customers

0

PHP代碼來獲得其組ID等於1的客戶羣:

$customer_group = Bigcommerce::getResource('/customer_groups/' ."1"); 
echo "Customer ID: $customer_group->id \n"; 
echo "<br>"; 
echo "Customer Group Name: $customer_group->name \n"; 
echo "<br>";`enter code here` 

結果

客戶ID:1

客戶羣名稱:GSA