Skip to content

Commit

Permalink
Merge pull request #420 from wizaplace/develop
Browse files Browse the repository at this point in the history
Merge develop for 1.44.3
  • Loading branch information
wizacedric authored Dec 27, 2018
2 parents 807db27 + bee0203 commit 30b63dd
Show file tree
Hide file tree
Showing 28 changed files with 1,415 additions and 74 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 1.44.3

## New features

- Updated `\Wizaplace\SDK\Catalog\Product` with `\Wizaplace\SDK\Division\Division`
- Added `\Wizaplace\SDK\Division\DivisionService::get`
- Added `\Wizaplace\SDK\Company\CompanyService::getDivisionsCountriesCodes`
- Added `\Wizaplace\SDK\Division\DivisionCompany`
- Added `\Wizaplace\SDK\Company\CompanyService::getDivisions`
- Added `\Wizaplace\SDK\Company\CompanyService::setDivisions`
- Added `\Wizaplace\SDK\Pim\Product\ProductService::getDivisionsCountriesCodes`
- Added `\Wizaplace\SDK\Pim\Product\ProductService::getDivisions`
- Added `\Wizaplace\SDK\Pim\Product\ProductService::setDivisions`
- Added `\Wizaplace\SDK\Division\DivisionService::set`
- Added `\Wizaplace\SDK\User\UserAddress::getDivision`
- Added `\Wizaplace\SDK\Catalog\ProductOffer`
- Added `\Wizaplace\SDK\Catalog\Product::getOffers`

## 1.44.2

### New features
Expand Down
9 changes: 9 additions & 0 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ public function put(string $endpoint, array $options = [])
);
}

public function patch(string $endpoint, array $options = [])
{
return $this->jsonDecode(
$this->rawRequest("PATCH", $endpoint, $options)
->getBody()
->getContents()
);
}

public function delete(string $endpoint, array $options = [])
{
return $this->jsonDecode(
Expand Down
17 changes: 17 additions & 0 deletions src/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ final class Product
/** @var bool */
private $infiniteStock;

/** @var null|ProductOffer[] */
private $offers;

/**
* @internal
*/
Expand Down Expand Up @@ -161,6 +164,12 @@ public function __construct(array $data, UriInterface $apiBaseUrl)
return new Image($imageData);
}, $data['images']);
}

if (isset($data['offers'])) {
$this->offers = array_map(function (array $offer): ProductOffer {
return new ProductOffer($offer);
}, $data['offers']);
}
}

public function getId(): string
Expand Down Expand Up @@ -409,4 +418,12 @@ public function hasInfiniteStock(): bool
{
return $this->infiniteStock;
}

/**
* @return null|ProductOffer[]
*/
public function getOffers(): ?array
{
return $this->offers;
}
}
49 changes: 49 additions & 0 deletions src/Catalog/ProductOffer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @author Wizacha DevTeam <[email protected]>
* @copyright Copyright (c) Wizacha
* @license Proprietary
*/
declare(strict_types=1);

namespace Wizaplace\SDK\Catalog;

class ProductOffer
{
/** @var int */
private $productId;
/** @var int */
private $companyId;
/** @var float */
private $price;
/** @var array */
private $divisions;

public function __construct(array $data)
{
$this->productId = (int) $data['productId'];
$this->companyId = (int) $data['companyId'];
$this->price = (float) $data['price'];
$this->divisions = array_filter($data['divisions']);
}

public function getProductId(): int
{
return $this->productId;
}

public function getCompanyId(): int
{
return $this->companyId;
}

public function getPrice(): float
{
return $this->price;
}

public function getDivisions(): array
{
return $this->divisions;
}
}
85 changes: 85 additions & 0 deletions src/Company/CompanyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
namespace Wizaplace\SDK\Company;

use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
use Wizaplace\SDK\AbstractService;
use Wizaplace\SDK\Authentication\AuthenticationRequired;
use Wizaplace\SDK\Division\DivisionCompany;
use Wizaplace\SDK\Exception\CompanyNotFound;
use Wizaplace\SDK\Exception\NotFound;

final class CompanyService extends AbstractService
{
Expand Down Expand Up @@ -225,6 +228,88 @@ public function deleteFile(int $companyId, string $filename)
return $this->client->delete("companies/{$companyId}/files/{$filename}");
}

/**
* Allow to get a list of countries codes of enabled divisions for the company
*
* @param int $companyId
*
* @return array
* @throws AuthenticationRequired
* @throws NotFound
*/
public function getDivisionsCountriesCodes(int $companyId): array
{
$this->client->mustBeAuthenticated();

try {
return $this->client->get("companies/{$companyId}/divisions");
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 404) {
throw new NotFound($e);
}
throw $e;
}
}

/**
* Allow to get a list of divsions enabled for the company
*
* @param int $companyId
* @param string $countryCode
*
* @return DivisionCompany[]
* @throws AuthenticationRequired
* @throws NotFound
*/
public function getDivisions(int $companyId, string $countryCode): array
{
$this->client->mustBeAuthenticated();

try {
return array_map(function ($datas) {
return new DivisionCompany($datas);
}, $this->client->get("companies/{$companyId}/divisions/{$countryCode}"));
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 404) {
throw new NotFound($e);
}
throw $e;
}
}

/**
* Allow to disable divisions for the company
*
* @param int $companyId
* @param string $countryCode
* @param array $codes
*
* @return DivisionCompany[]
* @throws AuthenticationRequired
* @throws NotFound
*/
public function putDivisions(int $companyId, string $countryCode, array $codes): array
{
$this->client->mustBeAuthenticated();

try {
$divisions = $this->client->put("companies/{$companyId}/divisions/{$countryCode}", [
RequestOptions::FORM_PARAMS => [
'code' => $codes,
],
]);

return array_map(function ($datas) {
return new DivisionCompany($datas);
}, $divisions);
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 404) {
throw new NotFound($e);
}
throw $e;
}
}

/**
* @param array $files {@see \Wizaplace\SDK\Company\CompanyRegistration::addFile}
* @return FileUploadResult[] a map of result by uploaded file.
Expand Down
151 changes: 151 additions & 0 deletions src/Division/Division.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php
/**
* @copyright Copyright (c) Wizacha
* @license Proprietary
*/

namespace Wizaplace\SDK\Division;

use Wizaplace\SDK\User\UserType;

final class Division
{
/**
* @var string
*/
private $code;

/**
* @var null|string
*/
private $parentCode;

/**
* @var int
*/
private $level;

/**
* @var bool
*/
private $isEnabled;

/**
* @var string
*/
private $description;

/**
* @var null|int
*/
private $companyId;

/**
* @var null|UserType
*/
private $disabledBy;

/**
* @var null|int
*/
private $productId;

/**
* @var Division[]
*/
private $children;

public function __construct(array $data)
{
$this->code = $data['code'];
$this->parentCode = $data['parentCode'];
$this->level = $data['level'];
$this->isEnabled = $data['isEnabled'];
$this->description = $data['description'];
$this->companyId = $data['companyId'] ?? null;
$this->disabledBy = $data['disabledBy'] ?? null;
$this->productId = $data['productId'] ?? null;
$this->children = [];
}

/**
* @return string
*/
public function getCode(): string
{
return $this->code;
}

/**
* @return null|string
*/
public function getParentCode(): ?string
{
return $this->parentCode;
}

/**
* @return int
*/
public function getLevel(): int
{
return $this->level;
}

/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->isEnabled;
}

/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}

/**
* @return int|null
*/
public function getCompanyId(): ?int
{
return $this->companyId;
}

/**
* @return null|UserType
*/
public function getDisabledBy(): ?UserType
{
if (is_null($this->disabledBy)) {
return null;
}

return ($this->disabledBy === UserType::ADMIN()->getValue()) ? UserType::ADMIN() : UserType::VENDOR();
}

/**
* @return int|null
*/
public function getProductId(): ?int
{
return $this->productId;
}

/**
* @return Division[]
*/
public function getChildren(): array
{
return $this->children;
}

public function addChild(Division $child): void
{
$this->children[] = $child;
}
}
Loading

0 comments on commit 30b63dd

Please sign in to comment.