0

我正在使用 [此处][1] 找到的 Woocommerce REST API 客户端库

[1]:https ://github.com/kloon/WooCommerce-REST-API-Client-Library 。当请求发送到我的本地主机时,一切正常。但是,当请求发送到实时服务器时,不会返回任何数据。有人知道可能缺少什么吗?检查执行请求的整个代码的片段。

<?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
}

}


?>

4

0 回答 0