dspacelabs/shopify

此包已被废弃且不再维护。作者建议使用dspacelabs/shopify-client包。

Shopify 客户端

dev-master / 1.0.x-dev 2017-07-11 00:01 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:54:52 UTC


README

PHP Shopify 客户端,易于集成到您的项目和应用程序中

  • PHP 客户端,用于与 Shopify API 交互
  • 源代码有良好的文档
  • 经过大量测试和维护
  • 用于生产 Shopify 应用程序
  • 保持高标准的代码质量 Code Climate
  • 私有应用程序支持

要求

安装

composer require "dspacelabs/shopify:^1.0@dev"

用法

将用户重定向到 Shopify 以授权您的应用程序

<?php

use Dspacelabs\Component\Shopify\Client;

$client = new Client($accessKey, $secretKey);
$client->setShop('example.myshopify.com');
// This is the same thing as doing the entire domain
//$client->setShop('example');

// List of scopes can be in the Client class
$client->setScopes(
    array(
        Client::SCOPE_WRITE_CUSTOMERS,
        Client::SCOPE_READ_CUSTOMERS
    )
);

$nonce = time(); // Save in session, used in callback action

$authorizationUri = $client->getAuthorizationUrl('https://example.com/shopify/callback', $nonce);
// redirect user to $authorizationUri

Shopify 将用户重定向回您的回调 URL

<?php

use Dspacelabs\Component\Shopify\Client;

if (!$session->has('nonce')) {
    throw new AccessedDeniedError();
}

$client = new Client($accessKey, $secretKey);
$client->setShop('example.myshopify.com');

// `isValid` takes array of query parameters, think $_GET, $_POST, etc.
// This example is using a Request object from the symfony/http-foundation
// library
if (!$client->isValid($request->query->all())) {
    throw new \AccessDeniedError();
}

// Persist access token in database
$accessToken = $client->getAccessToken($request->query->get('code'));

向 Shopify 发送请求

<?php

use Dspacelabs\Component\Shopify\Client;

$client = new Client($accessKey, $secretKey):
$client
    ->setShop('example.myshopify.com')
    ->setAccessToken($accessToken);

$result = $client->call('GET', '/admin/customers.json');

// Process $result

定期应用程序费用

@todo

创建和使用 webhooks

@todo

私有应用程序

请参阅生成私有应用程序凭据

<?php

use Dspacelabs\Component\Shopify\Client;

/**
 * The API Key and Password are generated for you on Shopify once you create
 * Your private app. Those are the credentials you need here.
 */
$client = new Client($apiKey, $password):
$client
    ->setPrivate(true)
    ->setShop('example.myshopify.com');

使用此库的应用程序