RetailCRM API Client

Packs extends AbstractApiResourceGroup

Class Packs

Tags
category

Packs

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

create()  : IdResponse
Makes POST "/api/v5/orders/packs/create" request.
delete()  : SuccessResponse
Makes POST "/api/v5/orders/packs/{id}/delete" request.
edit()  : IdResponse
Makes POST "/api/v5/orders/packs/{id}/edit" request.
get()  : PacksGetResponse
Makes GET "/api/v5/orders/packs/{id}" request.
history()  : PacksHistoryResponse
Makes GET "/api/v5/orders/packs/history" request.
list()  : PacksResponse
Makes GET "/api/v5/orders/packs" request.

Methods

create()

Makes POST "/api/v5/orders/packs/create" request.

public create(PacksCreateRequest $request) : IdResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Packs\OrderProductPack;
use RetailCrm\Api\Model\Request\Packs\PacksCreateRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$pack                     = new OrderProductPack();
$pack->itemId             = 11235;
$pack->invoiceNumber      = '1234567890';
$pack->deliveryNoteNumber = '1234567890';
$pack->shipmentDate       = (new DateTime())->add(new DateInterval('P1D'));
$pack->store              = 'main12';
$pack->quantity           = 1;
$pack->purchasePrice      = 100;

try {
    $response = $client->packs->create(new PacksCreateRequest($pack));
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Created pack with ID: ' . $response->id;
Parameters
$request : PacksCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
IdResponse

delete()

Makes POST "/api/v5/orders/packs/{id}/delete" request.

public delete(int $id) : SuccessResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $response = $client->packs->delete(143);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }
}
Parameters
$id : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

edit()

Makes POST "/api/v5/orders/packs/{id}/edit" request.

public edit(int $id, PacksCreateRequest $request) : IdResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Packs\OrderProductPack;
use RetailCrm\Api\Model\Request\Packs\PacksCreateRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$pack                     = new OrderProductPack();
$pack->shipmentDate       = (new DateTime())->add(new DateInterval('P1D'));

try {
    $response = $client->packs->edit(143, new PacksCreateRequest($pack));
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Edited pack #' . $response->id;
Parameters
$id : int
$request : PacksCreateRequest
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
IdResponse

get()

Makes GET "/api/v5/orders/packs/{id}" request.

public get(int $id) : PacksGetResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

try {
    $response = $client->packs->get(143);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Pack #143: ' . print_r($response->pack, true);
Parameters
$id : int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
PacksGetResponse

history()

Makes GET "/api/v5/orders/packs/history" request.

public history([PacksHistoryRequest|null $request = null ]) : PacksHistoryResponse

Example:

use RetailCrm\Api\Component\Transformer\DateTimeTransformer;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Packs\OrderProductPackHistoryFilterType;
use RetailCrm\Api\Model\Request\Packs\PacksHistoryRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$request              = new PacksHistoryRequest();
$request->filter      = new OrderProductPackHistoryFilterType();
$request->filter->startDate = DateTimeTransformer::create('2020-01-01 00:00:00');

try {
    $response = $client->packs->history($request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Packs history: ' . print_r($response->history, true);
Parameters
$request : PacksHistoryRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
PacksHistoryResponse

list()

Makes GET "/api/v5/orders/packs" request.

public list([PacksRequest|null $request = null ]) : PacksResponse

Example:

use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Packs\OrderProductPackFilter;
use RetailCrm\Api\Model\Request\Packs\PacksRequest;

$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');

$request              = new PacksRequest();
$request->filter      = new OrderProductPackFilter();
$request->filter->ids = [143];

try {
    $response = $client->packs->list($request);
} catch (ApiExceptionInterface $exception) {
    echo sprintf(
        'Error from RetailCRM API (status code: %d): %s',
        $exception->getStatusCode(),
        $exception->getMessage()
    );

    if (count($exception->getErrorResponse()->errors) > 0) {
        echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
    }

    return;
}

echo 'Packs: ' . print_r($response->packs, true);
Parameters
$request : PacksRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
PacksResponse

        
On this page

Search results