From 878231a3069f5c24c92d4b265b4c549efaab6cf4 Mon Sep 17 00:00:00 2001 From: uryvskiy-dima Date: Wed, 28 Dec 2022 18:03:25 +0300 Subject: [PATCH] Add API methods for cart --- retailcrm/lib/api/RetailcrmApiClientV5.php | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/retailcrm/lib/api/RetailcrmApiClientV5.php b/retailcrm/lib/api/RetailcrmApiClientV5.php index abb2203..6e9885b 100644 --- a/retailcrm/lib/api/RetailcrmApiClientV5.php +++ b/retailcrm/lib/api/RetailcrmApiClientV5.php @@ -1207,6 +1207,84 @@ class RetailcrmApiClientV5 ); } + /** + * Get cart by id or externalId + * + * @param string $customerId order identificator + * @param string $site + * @param string $by (default: 'externalId') + * + * @return RetailcrmApiResponse + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + */ + public function cartsGet(string $customerId, string $site, string $by = 'externalId') + { + $this->checkIdParameter($by); + + return $this->client->makeRequest( + sprintf('/customer-interaction/%s/cart/%s', $site, $customerId), + RetailcrmHttpClient::METHOD_GET, + ['by' => $by] + ); + } + + /** + * Create or update cart + * + * @param array $cart + * @param string $site + * + * @return RetailcrmApiResponse + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + */ + public function cartsSet(array $cart, string $site) + { + if (empty($site)) { + throw new \InvalidArgumentException( + 'Site must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/customer-interaction/%s/cart/set', $site), + RetailcrmHttpClient::METHOD_POST, + ['cart' => json_encode($cart)] + ); + } + + /** + * Clear cart + * + * @param array $cart + * @param string $site + * + * @return RetailcrmApiResponse + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + */ + public function cartsClear(array $cart, string $site) + { + if (empty($site)) { + throw new \InvalidArgumentException( + 'Site must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/customer-interaction/%s/cart/clear', $site), + RetailcrmHttpClient::METHOD_POST, + ['cart' => json_encode($cart)] + ); + } + /** * Returns filtered corporate customers list *