alldigitalrewards/channeladvisor

非官方Channel Advisor库

1.2.1 2023-07-26 15:27 UTC

This package is auto-updated.

Last update: 2024-09-26 17:47:56 UTC


README

Latest Version on Packagist StyleCI Total Downloads

这是一个ChannelAdvisor API包装库

安装

通过Composer

composer require alldigitalrewards/channeladvisor

使用方法

使用construct创建客户端。

<?php
$client = new \AllDigitalRewards\ChannelAdvisor\Client(
    "REFRESH_TOKEN",
    "APPLICATION_ID",
    "SHARED_SECRET",
    123456789
);

使用工厂创建客户端。

当以下环境变量中定义了密钥时,您可以使用工厂来获取ChannelAdvisor客户端的实例。

  • CHANNELADVISOR_REFRESH_TOKEN
  • CHANNELADVISOR_APPLICATION_ID
  • CHANNELADVISOR_SHARED_SECRET
  • CHANNELADVISOR_PROFILE_ID
<?php
$client = \AllDigitalRewards\ChannelAdvisor\ClientFactory::getClient();

获取产品

如上创建客户端,然后...

获取所有产品(分页)

<?php
$productFetcher = new \AllDigitalRewards\ChannelAdvisor\ProductFetcher($client);
$next_link = null;
$counter = 0;

while(true) {
    $productCollection = $productFetcher->getProducts($next_link);

    // Do something with this page of products...
    // There should be about 100 products in the collection.
    echo count($productCollection) . " in collection {$counter}.\n";

    if($productCollection->isLastPage()) {
        // We're done iterating, break the cipher.
        break 1;
    }

    $next_link = $productCollection->getNextLink();
}

创建订单

$sampleOrderConfig = [
    "ProfileID" => 123456789, //Identifies the ChannelAdvisor profile
    "SiteOrderID" => "123456789-12341234", // This should be the Transaction GUID
    "TotalPrice" => 38.41,
    "BuyerEmailAddress" => "jmuto@alldigitalrewards.com",
    "ShippingTitle" => "Mr.",
    "ShippingFirstName" => "Joseph",
    "ShippingLastName" => "Muto",
    "ShippingSuffix" => null,
    "ShippingCompanyName" => null,
    "ShippingCompanyJobTitle" => null,
    "ShippingDaytimePhone" => "123456789",
    "ShippingEveningPhone" => null,
    "ShippingAddressLine1" => "935 Bungalow Ave",
    "ShippingAddressLine2" => "",
    "ShippingCity" => "Winter Park",
    "ShippingStateOrProvince" => "FL",
    "ShippingPostalCode" => "32789",
    "Items" => [
        [
            "Sku" => "72539",
            "Quantity" => 1,
            "UnitPrice" => 38.41,
        ]
    ]
]

测试

$ composer test

代码风格

此存储库实现了PSR2代码风格。在提交PR之前,请运行composer check-style
如有必要,可以使用composer fix-style自动清理问题。

参考