mavericks-lab/bigcommerce

dev-master 2018-02-01 17:15 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:40:41 UTC


README

描述

此包作为BigCommerce产品、订单、客户和商家端点的请求映射器。

安装

    composer require mavericks-lab/bigcommerce

初始化

use Maverickslab\BigCommerce\Http\Client\BigCommerceHttpClient;
use Maverickslab\BigCommerce\Http\Request\{
    ProductRequest, CategoryRequest, OrderRequest, MerchantRequest, CustomerRequest
};

$authToken = 'h5wm9usftmq7zkmn1bggaj6cr8h3ml3';
$clientId = 'nbioblf5th4u4y9iqhtbwbjyl6qb6jt';
$clientSecret = '';
$storeId = '9ma06';

$httpClient = new BigCommerceHttpClient($authToken, $clientId, $clientSecret, $storeId);

//Create an instance of a product request
$productRequest = new ProductRequest($httpClient);

//Create an instance of a category request
$categoryRequest = new CategoryRequest($httpClient);

//Create an instance of an order request
$orderRequest = new OrderRequest($httpClient);

//Create an instance of a merchant request
$merchantRequest = new MerchantRequest($httpClient);

//Create an instance of a customer request
$customerRequest = new CustomerRequest($httpClient);

您还可以创建一个Maverickslab\BigCommerce\BigCommerce的实例,该实例将上述所有请求组合成一个对象。

use Maverickslab\BigCommerce\BigCommerce;

$bigCommerce = new BigCommerce($httpClient);

//Get instance of a ProductRequest
$bigCommerce->product();

//Get instance of a CategoryRequest
$bigCommerce->category();

//Get instance of an OrderRequest
$bigCommerce->order();

//Get instance of a CustomerRequest
$bigCommerce->customer();

Get instance of a MerchantRequest
$bigCommerce->merchant();

注意:这些仓库中所有公开可访问的方法都返回Psr\Http\Message\ResponseInterface的实例,因此您必须解析它们以获取其实际返回值。

处理产品请求

创建产品


$product = array(
    'name' => 'Dell XPS 15',
    'weight' => 10.5,
    'price' => 1500,
    'sku' => 'DELL-XPS-15'
);

$promise = $productRequest->create($product);

更新产品

$id = 1;
$productInfo = array(
    'name' => 'Dell XPS 13'
);

$promise = $productRequest->update($id, $productInfo);

获取产品集合

$page = 1;
$limit = 1000;
$includes = ['images', 'variants'];

$promise = $productRequest->fetch($page, $limit, $includes);

获取单个产品

$id = 1;
$promise = $productRequest->fetchById($id);

删除产品

$id = 1;
$promise = $productRequest->deleteById($id);

获取产品的图像

$productId = 1;

$promise = $productRequest->fetchProductImages($productId);

上传产品的图像

$productId = 1;

//External image
$imageFile = 'http://www.somedomain.com/images/product1.jpeg';

//Or
//Local image
$imageFile = 'images/product1.png';

$promise = $productRequest->uploadProductImage($productId, $imageFile);

有关执行其他产品相关请求的更多信息,请参阅Maverickslab\BigCommerce\Http\Request\ProductRequest

处理类别请求

创建类别

$category = array(
    'name' => 'Cars',
    'parent_id' => 0
);

$promise = $categoryRequest->create($category);

更新类别

$categoryId = 1;
$categoryInfo = array(
    'name' => 'Bikes',
    'parent_id' => 1
);

$promise = $categoryRequest->update($categoryId, $categoryInfo);

获取类别集合

$page = 1;
$limit = 500;

$promise = $categoryRequest->fetch($page, $limit);

有关执行其他类别相关请求的更多信息,请参阅Maverickslab\BigCommerce\Http\Request\CategoryRequest

处理订单请求

获取订单集合

$page = 1;
$limit = 500;
$filters = [];

$promise = $orderRequest->fetch($page, $limit, $filters);

更新订单

$orderId = 1;
$orderInfo = array(
    'status_id' => 10
);

$promise = $orderRequest->update($orderId, $orderInfo);

获取订单产品

$orderId = 1;
$page = 1;
$limit = 250;

$promise = $orderRequest->fetchOrderedProducts($orderId, $page, $limit);

有关执行其他订单相关请求的更多信息,请参阅Maverickslab\BigCommerce\Http\Request\OrderRequest

处理客户请求

获取客户集合

$page = 1;
$limit = 250;
$filters = [];
$promise = $customerRequest->fetch($page, $limit, $filters);

获取单个客户

$customerId = 2;

$promise = $customerRequest->fetchById($customerId);

创建客户

$customer = array(
    'first_name' => 'John',
    'last_name' => 'Smith',
    'email' => 'johnsmith@somedomain.com',
    'phone' => '+2335457487484'
);

$promise = $customerRequest->create($customer);

有关执行其他客户相关请求的更多信息,请参阅Maverickslab\BigCommerce\Http\Request\CustomerRequest

处理商家请求

获取商家信息

$promise = $merchantRequest->fetchDetails();

解析承诺

use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;

$promise->then(function(ResponseInterface $response){
    //Do something wih the response
}, function(RequestException $e){
    echo $e->getMessage();
});