1
0
mirror of synced 2024-11-21 21:06:07 +03:00

Merge pull request #27 from gwinn/master

prices methods: get, edit, upload
This commit is contained in:
Alex Lushpai 2016-09-21 00:12:23 +03:00 committed by GitHub
commit 5be40d1d09
2 changed files with 240 additions and 0 deletions

View File

@ -61,6 +61,8 @@ class ApiClient
$this->client = new Client($url, array('apiKey' => $apiKey));
$this->siteCode = $site;
return $this->client;
}
/**
@ -97,6 +99,35 @@ class ApiClient
);
}
/**
* Get user groups
*
* @param null $page
* @param null $limit
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
*
* @return ApiResponse
*/
public function usersGroups($page = null, $limit = null)
{
$parameters = array();
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest(
'/user-groups',
Client::METHOD_GET,
$parameters
);
}
/**
* Returns user data
*
@ -835,6 +866,33 @@ class ApiClient
);
}
/**
* Upload store prices
*
* @param array $prices prices data
* @param string $site default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function storePricesUpload(array $prices, $site = null)
{
if (!count($prices)) {
throw new \InvalidArgumentException(
'Parameter `prices` must contains array of the prices'
);
}
return $this->client->makeRequest(
'/store/prices/upload',
Client::METHOD_POST,
$this->fillSite($site, array('prices' => json_encode($prices)))
);
}
/**
* Get products
*
@ -1419,6 +1477,54 @@ class ApiClient
);
}
/**
* Get prices types
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function pricesTypes()
{
return $this->client->makeRequest(
'/reference/price-types',
Client::METHOD_GET
);
}
/**
* Edit price type
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function pricesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
if (!array_key_exists('name', $data)) {
throw new \InvalidArgumentException(
'Data must contain "name" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/price-types/%s/edit', $data['code']),
Client::METHOD_POST,
array('priceType' => json_encode($data))
);
}
/**
* Get telephony settings
*

View File

@ -0,0 +1,134 @@
<?php
/**
* PHP version 5.3
*
* API client prices test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
namespace RetailCrm\Tests;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPricesTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class ApiClientPricesTest extends TestCase
{
protected $code;
/**
* ApiClientPricesTest constructor.
*/
public function __construct()
{
parent::__construct();
$this->code = 'price-code-a-' . time();
}
/**
* @group prices
*/
public function testUsersGroups()
{
$client = static::getApiClient();
$response = $client->usersGroups();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
}
/**
* @group prices
*/
public function testPricesGet()
{
$client = static::getApiClient();
$response = $client->pricesTypes();
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
}
/**
* @group prices
*/
public function testPricesEdit()
{
$client = static::getApiClient();
$response = $client->pricesEdit(
array(
'code' => $this->code,
'name' => $this->code,
'ordering' => 500,
'active' => true
)
);
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(201, $response->getStatusCode());
$this->assertTrue($response->isSuccessful());
}
/**
* @group prices
* @expectedException \InvalidArgumentException
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->storePricesUpload(array());
}
/**
* @group prices
*/
public function testPricesUpload()
{
$client = static::getApiClient();
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();
$response = $client->storePricesUpload(array(
array(
'xmlId' => $xmlIdA,
'prices' => array(
array(
'code' => $this->code,
'price' => 1700
)
)
),
array(
'xmlId' => $xmlIdB,
'prices' => array(
array(
'code' => $this->code,
'price' => 1500
)
)
),
));
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
}
}