phpclassic / php-shopify

PHP SDK for Shopify API
Apache License 2.0
568 stars 211 forks source link

I am trying to obtain a list of orders with over 250 contents #314

Open aogg2023 opened 7 months ago

aogg2023 commented 7 months ago

namespace app\api\controller; use commonfunctions\src\Commonfunctions; use think\Controller; use app\api\controller\Baiduimages; use app\api\controller\Spapi;

use PHPShopify\ShopifySDK;

class Shopify extends Controller {

protected function _initialize(){

    $commonfunctions=   new Commonfunctions;
    $Baiduimages=   new Baiduimages;
    $Spapi= new Spapi;

}

protected function shopinfo($admin_id){

    $shop=db("admin_extend")->where(array("admin_id"=>$admin_id))->find();

    $shopname = $shop["store_name"] . ".myshopify.com";
    $apiKey = $shop["api_key"];
    $apiPassword = $shop["password"];
    $apiVersion = '2023-10';

    $config = array(
        'ShopUrl' => $shopname,
        'ApiKey' => $apiKey,
        'Password' => $apiPassword,
        'ApiVersion' => $apiVersion,
        'isEmbeddedApp' => false,
        'isPrivateApp' => false,
        'Curl' => array(
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false
        )
    );

    $shopify = new ShopifySDK($config);

    return $shopify;

}

//获取订单
public function get_orders(){

    //$products = $shopify->Product->get();

    //$productsCount = $shopify->Order->count();

    $id="";
    if(isset($orderid)){
        $id=$orderid;
    }

    $shopify=$this->shopinfo(2395);

    $fields="id,total_price,subtotal_price,total_discounts,total_tax,total_weight,currency,".
            "financial_status,fulfillment_status,note,created_at,processed_at,closed_at,location_id,email,".
            "shipping_address,line_items,order_number,fulfillments,shipping_lines,customer,payment_gateway_names,tags";

    $params = array(
        'status' => 'any',
        'limit' => 250,
        'fields' => $fields
    );

    $orders = $shopify->Order($id)->get($params);

    return $orders;

}