shopgate/connect-integration-sdk-php

A PHP framework supporting the integration with the Shopgate Connect Platform.

v1.3.8 2021-02-22 10:53 UTC

README

Build Status Coverage Status License GitHub (pre-)release

The Shopgate Connect Integration SDK is a compilation of classes to manage the communication between your shop system and Shopgate Connect.

Create a developer account at https://developer.shopgate.com

Requirements

  • PHP 5.6 and above

Getting Started

Via Composer

composer require shopgate/connect-integration-sdk-php

Usage

Example for calling our service in order to create, update or delete a category:

<?php
use Shopgate\ConnectSdk\ShopgateSdk;
use Shopgate\ConnectSdk\Dto\Catalog\Category;

$config = [
    'merchantCode'  => 'xxx',
    'clientId'      => 'xxx',
    'clientSecret'  => 'xxx',
    'username'      => 'xxx',
    'password'      => 'xxx',
    'env'           => 'pg' // Optional. "dev", "pg" or empty (= production)
];

$sgSdk = new ShopgateSdk($config);

// create new category
$categoryPayload = new Category\Create();
$name            = new Category\Dto\Name(['en-us' => 'Denim Pants']);
$categoryPayload->setCode('pants')->setName($name)->setSequenceId(1);
$sgSdk->getCatalogService()->addCategories([$categoryPayload]);

// update category with constructor input example
$updateDto = new Category\Update(['name' => ['en-us' => 'Skirts']]);
$sgSdk->getCatalogService()->updateCategory('pants', $updateDto);

// delete category
$sgSdk->getCatalogService()->deleteCategory('pants');

// get categories
$categories = $sgSdk->getCatalogService()->getCategories(['limit' => 5]);

// update category sync
$name      = (new Category\Dto\Name())->add('en-us', 'Skirts');
$updateDto = new Category\Update(['name' => $name]);
$sgSdk->getCatalogService()->updateCategory('4', $updateDto, ['requestType' => 'direct']);

Example for calling our service in order to create, update or delete a simple product:

<?php
use Shopgate\ConnectSdk\ShopgateSdk;
use Shopgate\ConnectSdk\Dto\Catalog\Product;
use Shopgate\ConnectSdk\Dto\Catalog\Product\Dto\Price as PriceDto;

$config = [
    'merchantCode'  => 'xxx',
    'clientId'      => 'xxx',
    'clientSecret'  => 'xxx',
    'username'      => 'xxx',
    'password'      => 'xxx',
    'env'           => 'pg' // Optional. "dev", "pg" or empty (= production)
];

$sgSdk = new ShopgateSdk($config);

// create new price
$price = new PriceDto();
$price->setPrice(90)->setSalePrice(84.99)->setCurrencyCode(PriceDto::CURRENCY_CODE_EUR);

// create new product
$productPayload = new Product\Create();
$name = new Product\Dto\Name(['en-us' => 'Blue Jeans regular']);
$productPayload->setCode('42')
               ->setCatalogCode('my_catalog')
               ->setName($name)
               ->setStatus(Product\Create::STATUS_ACTIVE)
               ->setModelType(Product\Create::MODEL_TYPE_STANDARD)
               ->setIsInventoryManaged(true)
               ->setPrice($price);
$sgSdk->getCatalogService()->addProducts([$productPayload]);

// update product with constructor input example
$updateDto = new Product\Update(['name' => new Product\Dto\Name(['en-us' => 'Blue Jeans regular'])]);
$sgSdk->getCatalogService()->updateProduct('42', $updateDto);

// delete product
$sgSdk->getCatalogService()->deleteProduct('42');

// update product sync
$updateDto = new Product\Update(['status' => Product\Create::STATUS_INACTIVE]);
$sgSdk->getCatalogService()->updateProduct('42', $updateDto, ['requestType' => 'direct']);

Example for create bulk import:

<?php

use Shopgate\ConnectSdk\ShopgateSdk;
use Shopgate\ConnectSdk\Dto\Catalog\Category;

$config = [
    'merchantCode'  => 'xxx',
    'clientId'      => 'xxx',
    'clientSecret'  => 'xxx',
    'username'      => 'xxx',
    'password'      => 'xxx',
    'env'           => 'pg' // Optional. "dev", "pg" or empty (= production)
];

$sgSdk = new ShopgateSdk($config);

// create new category 1
$categoryPayload1 = new Category\Create();
$name1            = new Category\Dto\Name(['en-us' => 'Denim Pants']);
$categoryPayload1->setCode('pants')->setName($name1)->setSequenceId(1);

// create new category 2
$categoryPayload2 = new Category\Create();
$name2            = new Category\Dto\Name(['en-us' => 'Denim Shirts']);
$categoryPayload2->setCode('shirts')->setName($name2)->setSequenceId(1);

// init stream import
//$handler = $sgSdk->getBulkImportService()->createStreamImport();

// init file import
$handler = $sgSdk->getBulkImportService()->createFileImport();

// create product feed for catalog
// $productHandler = $handler->createProductFeed('8000');

// create category feed for catalog
$categoryHandler = $handler->createCategoryFeed('8000');

// add payloads
$categoryHandler->add($categoryPayload1);
$categoryHandler->add($categoryPayload2);

// submit items / stop stream
$categoryHandler->end();

// trigger import
$handler->trigger();

Config

  • clientId (string) - oAuth2 client ID
  • clientSecret (string) - oAuth2 client secret
  • merchantCode (string) - the following are template system related, the default base_uri provided takes in variables in {merchantCode} format. These params just replace these variables. This way you do not need to rewrite the base_uri, but just provide the correct variables to replace the template components.
  • username - (string) - your username
  • password - (string) - your password
  • base_uri (string, default: https://{service}.shopgate{env}.io/v{ver}/merchants/{merchantCode}/) - if rewriting, make sure to add a forward slash at end as the calls will append paths
  • ver (integer, default: 1) - template variable, can be substituted on a per call level in the meta array parameters
  • env (string, default: '') - template variable, can also be 'dev' or 'pg'. If empty, production environment is used.

Changelog

See CHANGELOG.md file for more information.

Contributing

See CONTRIBUTING.md file for more information.

About Shopgate

Shopgate is the leading mobile commerce platform.

License

The Shopgate Connect Integration SDK is available under the Apache License, Version 2.0.

See the LICENSE.md file for more information.