2014-11-06 68 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