alldigitalrewards/channeladvisor

Unofficial Channel Advisor library

1.2.1 2023-07-26 15:27 UTC

This package is auto-updated.

Last update: 2024-10-26 18:01:23 UTC


README

Latest Version on Packagist StyleCI Total Downloads

This is a ChannelAdvisor API Wrapper Library

Install

Via Composer

composer require alldigitalrewards/channeladvisor

Usage

Create Client using construct.

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

Create Client using Factory

When secrets are defined in the following environment variables, you may use the factory to obtain an instance of the ChannelAdvisor client.:

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

Fetching Products

Create a client as seen above, then...

Fetch All Products (Paginated)

<?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();
}

Create Order

$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,
        ]
    ]
]

Testing

$ composer test

Code Style

This repository implements PSR2 code style. Please run composer check-style before opening PRs.
If necessary composer fix-style can be used to automatically clean up issues.

References