shirtigo / cockpit-api-client

使用Shirtigo API的按需打印API客户端

dev-master 2023-04-24 20:49 UTC

This package is not auto-updated.

Last update: 2024-09-21 12:12:03 UTC


README

A PHP implementation of a client for the shirtigo print API. Check out our REST-API documentation for a full list of all features. Almost all features of the Shirtigo Cockpit can be accessed through our API, providing developers with a comprehensive interface to interact with and manage the platform's functionality programmatically. This enables seamless integration with various applications and platforms, ensuring a versatile and adaptable user experience.

In the following sections, we will showcase some examples that demonstrate the core functionality of the API, highlighting its key features and capabilities. These examples will provide a better understanding of how to interact with the API and leverage its potential to meet your specific requirements.

If you have any open questions or require further assistance, please don't hesitate to contact our technical support team at tech-support@shirtigo.de. Our experts will be more than happy to help you and provide guidance to ensure a smooth and efficient experience using our API.

基本用法

客户端对象初始化

use Shirtigo\ApiClient\ApiClient;

$BASE_URL = "https://cockpit.shirtigo.com/api/";
$API_TOKEN = "YOUR_API_TOKEN";

$client = new ApiClient($API_TOKEN, $BASE_URL);

访问您的shirtigo账户数据

$data = $client->get('user');
echo "{$data->firstname} {$data->lastname}";

设计

A "design" object represents a print motif that can be subsequently utilized for the creation of various products.

上传设计

创建产品需要先上传设计。

从文件

$design_path = './test_design.png';

$design = $client->post('designs/file', [], [], [
    'file' => fopen($design_path, 'r'),
]);

从URL

$design = $client->post('designs/url', [
    'url' => "https:/my-web-storage/my-design.png",
]);

获取现有设计列表

$designs = $client->get('designs')->data;

BaseProducts

BaseProducts是空白产品,可以与设计组合。您还可以在Cockpit仪表板中下载我们的产品系列列表(xlsx文件):下载目录

获取所有baseProducts列表

$baseProducts = $client->get('base-products')->data;

创建产品系列

产品组织到系列中,每个baseProduct只能分配给一个系列/项目一次。要创建新产品,首先创建项目,然后,在后续步骤中,将所需产品分配到该项目。

创建项目

$data = [
    'name' => "My test project " + random_string(),
];

$project = $client->post('projects', $data);

将产品添加到项目中

在此示例中,我们将添加一款黑色有机T恤,单面印刷到我们的项目中。处理规范定义了设计、其位置、尺寸和其他相关细节,这些细节对于定制BaseProduct至关重要。请注意,您可以为每种颜色添加自定义处理。

$data = [
    "project_id" => $project->reference,
    "base_product_id" => 235,
    "processings" => [
        [
            "processingarea_type" => "front",
            "processingposition" => "chest-center",
            "processingmethod" => "dtg",
            "design_reference" => $design->reference,
            "offset_top" => 50,
            "offset_center" => 0,
            "width" => 250,
            "is_customizable" => false,
            "force_position" => false,
            "colors" => [
                [
                    "colorId" => 326,
                    "price" => 2195,
                    "sortPosition" => 1
                ]
            ]
        ]
    ]
];

$product = $client->post('customized-product', $data);

创建订单

根据您的用例,有不同方式可以下订单

  • 订购现有产品
  • 订购不存在的产品(例如,您的每个产品都是定制的)

从您的账户订购现有产品

在此场景中,您的现有产品的sku模式如下:productId + baseProductColorId + baseProductSizeId

$data = [
    'delivery' => [
      'title' => 'Dr.',
      'company' => 'Shirtigo GmbH',
      'firstname' => 'Max',
      'lastname' => 'Mustermann',
      'street' => 'Musterstraße 12',
      'postcode' => '12345',
      'city' => 'Köln',
      'country' => 'Deutschland'
    ],
    'sender' => [
      'title' => 'Dr.',
      'company' => 'Shirtigo GmbH',
      'firstname' => 'Max',
      'lastname' => 'Mustermann',
      'street' => 'Musterstraße 12',
      'postcode' => '12345',
      'city' => 'Köln',
      'country' => 'Deutschland'
    ],
    'products' => [
        'sku' => 'c123456.122.8',
        'amount' => 1
    ]
];

$order = $client->post('orders', $data);

订购不存在的产品

在此场景中,使用base_product_sku来指定BaseProduct的变体(例如,STTU755C0021S代表黑色S码有机T恤)。除了SKU之外,还需要提供定制所需的处理规范,其格式与向项目添加产品相同。

$data = [
    'delivery' => [
      'title' => 'Dr.',
      'company' => 'Shirtigo GmbH',
      'firstname' => 'Max',
      'lastname' => 'Mustermann',
      'street' => 'Musterstraße 12',
      'postcode' => '12345',
      'city' => 'Köln',
      'country' => 'Deutschland'
    ],
    'sender' => [
      'title' => 'Dr.',
      'company' => 'Shirtigo GmbH',
      'firstname' => 'Max',
      'lastname' => 'Mustermann',
      'street' => 'Musterstraße 12',
      'postcode' => '12345',
      'city' => 'Köln',
      'country' => 'Deutschland'
    ],
    'products' => [
        'base_product_sku' => 'STTU755C0021S',
        'sales_price_gross' => '2199',
        'amount' => 1,
        'processings' => [
            [
                'design_url' => 'https://mydomain.com/myimage.png',
                'width' => 250,
                'height' => 350,
                'processingarea_type' => 'front',
                'processingposition' => 'chest-center',
                'processingmethod' => 'dtg',
                'offset_top' => 20,
                'offset_center' => 0,
                'force_position' => false,
            ],
        ],
    ],
];

$order = $client->post('orders', $data);

检查计划订单/购物车当前价格

$prices = $client->post('orders/predict-price', $order_data);