Woocommerce REST API Client Library not working on live stores

404 views Asked by At

I am using the Woocommerce REST API Client Library found [here][1]

[1]: https://github.com/kloon/WooCommerce-REST-API-Client-Library . Everything works fine when the request is to my local host. However, when the request is to a live server, no data is returned. Anyone with an idea of what could be missing? check the snippet for the entire code that does the requests.

<?php
/* template Name: Update Products Table */
global $wpdb;

//$consumer_key = $_GET['customerkey'];// "ck_d491f1aed52256b7a5e23117f8055a27d0cc1f00";//
//$consumer_secret = $_GET['customersecret'];// "cs_2efe861f2ca3ede008b31b3b39787fcece57ae32"; //
//$storeURL = $_GET['storeurl'];

require_once( 'lib/woocommerce-api.php' );
$options = array(
    'ssl_verify'      => false
);

//get the stores
$storesRows = $wpdb -> get_results("SELECT * FROM quantumall_stores WHERE approvalStatus='Approved");

/*if($wpdb-> num_rows !== 0){
       echo "product found";
     }else{
       echo "product not found";
     }*/

//run foreach on the stores
foreach($storesRows as $row){
  //get the store products
  //echo $row -> storename;
  try {
  $client = new WC_API_Client( $row -> storeUrl, $row -> customerKey, $row -> customerSecret, $options );
 
  $jsonClient = strip_tags(json_encode($client->products->get('',array('filter[limit]' => -1))));
//Insert the products into products table
 $decodeData = json_decode($jsonClient, true);
 echo $jsonClient;
 //print_r($decodeData['products']);
 $theProductsAssArray = $decodeData['products'];
    //running for each on the products
    foreach ($theProductsAssArray as $product){
      //echo $product['title'];
     // $productStoreId = $product['id'];
     // echo "11";
      //for now just add the product if it is not found in the table
      //?How is each product going  to be uniquly identified? 
      //identify the product by combination its unique creation time, id, storename (This breaks if you have two products with the same creation time, storename and id)

      $storeCheckRow =  $wpdb -> get_results('SELECT * FROM productstable WHERE productuniquness=' .$row-> storeUrl.$product['id']);
     $storeCheckRowjson = json_encode($storeCheckRow);
     if($wpdb-> num_rows !== 0){
       echo "product found";
       $imagesrc1 = json_encode($product['images']);
       $imagesrc = json_decode($imagesrc1, true);
    
    
       //update the product information
        $updateProductInformation = $wpdb -> update('productstable' , array('title'=>$product['title'], 'idinstore'=>$product['id'], 'permalink'=>$product['permalink'], 'price'=>$product['price'], 'stockquantity'=>$product['stock_quantity'],  'stockstatus'=>$product['in_stock'],  
      'imagesrc'=>$imagesrc[0]["src"], 'description'=>$product['description'], 'shortdescription'=>$product['short_description'], 'storeid'=>$row-> userID, 'productuniquness'=>$row-> userID.$product['id']), array('productuniquness'=> $row-> userID.$product['id']));
     }else{
       echo "product not found";
       $dataDecoded = json_decode(json_encode($product['images']));
       //var_dump($dataDecoded['title']);
       $imagesrc1 = json_encode($product['images']);
       $imagesrc = json_decode($imagesrc1, true);
       //Insert product into table 

       //NB: You need to perform a check that all values have been provided
      $insertProduct = $wpdb -> insert('productstable' , array('title'=>$product['title'], 'idinstore'=>$product['id'], 'permalink'=>$product['permalink'], 'price'=>$product['price'], 'stockquantity'=>$product['stock_quantity'],  'stockstatus'=>$product['in_stock'],  
      'imagesrc'=>$imagesrc[0]["src"], 'description'=>$product['description'], 'shortdescription'=>$product['short_description'], 'storeid'=>$row-> userID, 'productuniquness'=>$row-> userID.$product['id']));
    //'table', array( 'column' => 'foo', 'field' => 1337 )
    //$wpdb-> last_error;
     }
    }
   

  }catch ( WC_API_Client_Exception $e ) {
   //no update happend due to error
}

}


?>

0

There are 0 answers