过滤器&使用Bigcommerce API迭代stdclass对象数组

时间:2016-02-27 10:43:29

标签: php api curl bigcommerce

我正在尝试使用Big commerce API并将json响应过滤到我需要的任何参数。理想情况下,我想过滤在悉尼,澳大利亚和“等待取货”的运输状态的客户。这是我写的一个开始:

$request->get('name')

现在我得到了这个答案:

 <?php

    //Bigcommerce API credentials
    $username = 'xxxxxx'; 
    $api = 'xxxxxxxxxxxxxxxxxxxxxx';

    //Curl requests
    // Assign filters to variables
    $city_name = 'Sydney';
    $country_name = 'Australia';
    $items_shipped = 0;


    $customer_url = "https://store-xxxxxx.mybigcommerce.com/api/v2/customers.json";

    // intiate curl request
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $customer_url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $api);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_ENCODING, "");

    // execute curl requests
    $curlData = curl_exec($curl);

    // Parse requests in Json Format
    $product_rec  = json_decode($curlData);

    // returns a specific variable of StdClass Object, here the first name of obj[1]
     echo $product_rec[0]->first_name;

     // !!Here I'd like to implement an iteration othe reach std class objects and filter!!

    // print the requests in Json format on screen
     echo '<pre>';
     print_r($product_rec);

    // Close curl connexions
    curl_close($curl);

?>

我想现在用变量过滤结果。我想我需要做一个foreach循环,但我不知道该怎么做。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我实际上是从订单对象开始。这将提供开票和送货地址以及订单状态ID。可以过滤订单状态ID,然后您可以使用剩余的结果来过滤澳大利亚悉尼。 https://developer.bigcommerce.com/api/stores/v2/orders

popToRootViewController

我不确定您为什么要先尝试通过客户资源。如果您担心检查现有客户帐户,可以查找值不是0的客户ID。

相关问题