borsch/shopify

PHP Shopify REST API 的实现。

v0.2 2018-12-27 02:42 UTC

This package is auto-updated.

Last update: 2024-09-27 15:30:17 UTC


README

开发中,尚未覆盖全部 API...

Borsch - Shopify

PHP Shopify REST API 的实现。

此包是 Borsch 框架的一部分。

安装

通过Composer

$ composer require borsch/shopify 

使用

为了使用此包,您需要提供您的 商店地址访问令牌,以便进行 API 调用。

require_once __DIR__.'/vendor/autoload.php';

use Borsch\Shopify\Shopify;

// Initialize environment with your store address and access token
Shopify::init(
    'my-awesome-store.myshopify.com',
    '12c74ec231be94c9ee719c9483f330d1'
);

此包中的每个 Shopify API 都有一个类,可以通过 Shopify 类(工厂类)或直接调用构造函数来实例化。

use Borsch\Shopify\Shopify;
use Borsch\Shopify\CarrierService;

$carrier_service = Shopify::carrierService();
// OR
$carrier_service = new CarrierService('my-awesome-store.myshopify.com', '12c74ec231be94c9ee719c9483f330d1');

然后,您可以使用类方法设置值并调用 API

// Create a carrier service on Shopify
$carrier_service = Shopify::carrierService()
    ->name('My Carrier Service')
    ->callbackUrl('https://myapp.com')
    ->serviceDiscovery(true)
    ->post();

// We can use it to do POST, PUT or DELETE queries on it
// Let's just rename our carrier service for now
$carrier_service->name('My Awesome Carrier Service')->put();

要发送或从 Shopify API 获取数据,您需要使用相应的 HTTP 方法

示例

创建一个承运服务

// Create a carrier service on Shopify
$carrier_service = Shopify::carrierService()
    ->name('My Carrier Service')
    ->callbackUrl('https://myapp.com')
    ->serviceDiscovery(true)
    ->post();

// $carrier_service is now an instance of Borsch\Shopify\CarrierService that you just created
// Its properties are filled with the response from Shopify REST API.
// var_dump($carrier_service) will ouput :
// object(Borsch\Shopify\CarrierService)[3]
//     public 'active' => boolean true
//     public 'callback_url' => string 'https://myapp.com' (length=17)
//     public 'carrier_service_type' => string 'api' (length=3)
//     public 'format' => string 'json' (length=4)
//     public 'name' => string 'My Carrier Service' (length=18)
//     public 'service_discovery' => boolean true
//     public 'id' => float 12345678912

获取所有订单

$orders = Shopify::order()->get(null, ['status' => 'any']);

foreach ($orders as $order) {
    /** @var Borsch\Shopify\Order $order */
    $order->email('another-email@gmail.com')->put();
}

计数产品

$total_products = Shopify::product()->count();

获取客户 1089281327217 的地址 1250935701617,然后更新姓名和姓氏。

$address = Shopify::customerAddress()->customerId(1089281327217)->get(1250935701617)
    // Here we have all information fetched from API, let's update
    ->firstName('Samuel')
    ->lastName('de Champlain')
    ->name('Samuel de Champlain')
    ->put();

许可证

MIT License

Copyright (c) 2018 Alexandre DEBUSSCHERE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.