RetailCRM API Client

CustomerInteraction extends AbstractApiResourceGroup

Class CustomerInteraction

Tags
category

CustomerInteraction

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Methods

cartClear()  : SuccessResponse
Makes POST "/api/v5/customer-interaction/{site}/cart/clear" request.
cartGet()  : CustomerInteractionCartGetResponse
Makes GET "/api/v5/customer-interaction/{site}/cart/{customerId}" request.
cartSet()  : SuccessResponse
Makes POST "/api/v5/customer-interaction/{site}/cart/set" request.

Methods

cartClear()

Makes POST "/api/v5/customer-interaction/{site}/cart/clear" request.

public cartClear(CustomerInteractionCartClearRequest $request, string|int $site) : SuccessResponse

Example:

use RetailCrm\Api\Enum\BySite;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\CustomerInteraction\Cart;
use RetailCrm\Api\Model\Entity\CustomerInteraction\CartCustomer;
use RetailCrm\Api\Model\Request\CustomerInteraction\CustomerInteractionCartClearRequest;

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

$cart                       = new Cart();
$cart->clearedAt            = new DateTime('now');
$cart->customer             = new CartCustomer();
$cart->customer->id         = 4770;
$cart->customer->browserId  = 'browserId';
$cart->customer->gaClientId = 'gaClientId';

$request         = new CustomerInteractionCartClearRequest();
$request->cart   = $cart;
$request->siteBy = BySite::CODE;

try {
    $response = $client->customerInteraction->cartClear('testSite', $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;
}
Parameters
$request : CustomerInteractionCartClearRequest
$site : string|int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

cartGet()

Makes GET "/api/v5/customer-interaction/{site}/cart/{customerId}" request.

public cartGet(string|int $site, string|int $customerId[, ByAndSiteByRequest|null $request = null ]) : CustomerInteractionCartGetResponse

Example:

use RetailCrm\Api\Enum\ByIdentifier;
use RetailCrm\Api\Enum\BySite;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\ByAndSiteByRequest;

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

try {
    $response = $client->customerInteraction->cartGet(
        'testSite',
        4200,
        new ByAndSiteByRequest(ByIdentifier::ID, BySite::CODE)
    );
} 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 'Cart: ' . print_r($response->cart, true);
Parameters
$site : string|int
$customerId : string|int
$request : ByAndSiteByRequest|null = null
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
CustomerInteractionCartGetResponse

cartSet()

Makes POST "/api/v5/customer-interaction/{site}/cart/set" request.

public cartSet(CustomerInteractionCartSetRequest $request, string|int $site) : SuccessResponse

Example:

use RetailCrm\Api\Enum\BySite;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\CustomerInteraction\Cart;
use RetailCrm\Api\Model\Entity\CustomerInteraction\CartCustomer;
use RetailCrm\Api\Model\Entity\CustomerInteraction\CartItem;
use RetailCrm\Api\Model\Entity\Orders\Items\Offer;
use RetailCrm\Api\Model\Request\CustomerInteraction\CustomerInteractionCartSetRequest;

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

$customer     = new CartCustomer();
$customer->id = 4770;

$cartItem                    = new CartItem();
$cartItem->price             = 24.99;
$cartItem->quantity          = 2;
$cartItem->offer             = new Offer();
$cartItem->offer->externalId = '47701234567890';

$cart           = new Cart();
$cart->items[]  = $cartItem;
$cart->customer = $customer;

$request         = new CustomerInteractionCartSetRequest();
$request->cart   = $cart;
$request->siteBy = BySite::CODE;

 try {
     $response = $client->customerInteraction->cartSet('testSite', $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;
}
Parameters
$request : CustomerInteractionCartSetRequest
$site : string|int
Tags
throws
ApiExceptionInterface
throws
ClientExceptionInterface
throws
AccountDoesNotExistException
throws
ApiErrorException
throws
MissingCredentialsException
throws
MissingParameterException
throws
ValidationException
throws
HandlerException
throws
HttpClientException
Return values
SuccessResponse

        
On this page

Search results