问题描述:

I am trying to create a user list and I want to show Customer Group Name with each customer.

I used:

$customers = Bigcommerce::getCustomers();

To retrieve customer information.

The above function returns customer group id; can anyone help me telling how can I get customer group name?

I am very new to Bigcommerce API - any help will be appreciated.

Thanks

网友答案:

I assume you are using the PHP Library found here: https://github.com/bigcommerce/bigcommerce-api-php

Use this to print full information on all your customers:

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

You will notice however, that within the list returned, it only gives a customer group ID. To get the associated name with a customer group id, you would have to run:

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

Here's a little example which prints the first name, last name, and email of a customer, as well as the name of its associated customer group:

$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";
}

Should output something similar to:

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

Please reference the following URL for more information on the objects returned for $customer: https://developer.bigcommerce.com/api/customers

相关阅读:
Top