我正在尝试创建用户列表,我想向每个客户显示客户组名称。 我用过:
$customers = Bigcommerce::getCustomers();
检索客户信息。
上述函数返回客户组ID;任何人都可以帮我说明如何获得客户群名?
我是Bigcommerce API的新手 - 任何帮助都将不胜感激。
由于
答案 0 :(得分: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: JohnDoe@bigcommerce.com
Customer Group: Retail
~~~~~~~~~~~~~~~~~
请参阅以下网址,了解有关$ customer返回的对象的更多信息: https://developer.bigcommerce.com/api/customers
答案 1 :(得分:0)
用于获取组ID等于1的客户组的PHP代码:
$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