|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* For more information, see <http://www.g1mr.com/>. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Gpupo\NetshoesSdk\Entity\Product\Sku; |
|
12
|
|
|
|
|
13
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
|
14
|
|
|
use Gpupo\NetshoesSdk\Entity\ManagerAbstract; |
|
15
|
|
|
|
|
16
|
|
|
class Manager extends ManagerAbstract |
|
17
|
|
|
{ |
|
18
|
|
|
protected $entity = 'SkuCollection'; |
|
19
|
|
|
|
|
20
|
|
|
protected $maps = [ |
|
21
|
|
|
'save' => ['POST', '/products/{productId}/skus'], //Create a new sku for a product |
|
22
|
|
|
'findSkuById' => ['GET', '/products/{productId}/skus/{itemId}'], // Get the a sku by product Id and sku Id |
|
23
|
|
|
'update' => ['PUT', '/products/{productId}/skus/{itemId}'], //Update a product based on SKU |
|
24
|
|
|
'findById' => ['GET', '/products/{itemId}/skus'], //Get the list of product skus |
|
25
|
|
|
'saveStatus' => ['PUT', '/skus/{sku}/bus/{buId}/status'], //Enable or disable sku for sale |
|
26
|
|
|
'savePriceSchedule' => ['POST', '/skus/{sku}/priceSchedules'], //Save a price schedule |
|
27
|
|
|
'getPriceSchedule' => ['GET', '/skus/{sku}/priceSchedules'], //Get PriceSchedule |
|
28
|
|
|
'getPrice' => ['GET', '/skus/{sku}/prices'], //Get a base price |
|
29
|
|
|
'savePrice' => ['PUT', '/skus/{sku}/prices'], //Save a base price |
|
30
|
|
|
'saveStock' => ['PUT', '/skus/{sku}/stocks'], //Update stock quantity by sku |
|
31
|
|
|
'getStock' => ['GET', '/skus/{sku}/stocks'], //Get Stock |
|
32
|
|
|
'getStatus' => ['GET', '/skus/{sku}/bus/{buId}/status'], //Get Status |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
public function save(EntityInterface $product, $route = 'save') |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->execute($this->factoryMap($route), $product->toJson()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getDetail($skuId, $type) |
|
41
|
|
|
{ |
|
42
|
|
|
$response = $this->perform($this->factoryMap('get'.$type, ['sku' => $skuId])); |
|
43
|
|
|
$className = 'Gpupo\NetshoesSdk\Entity\Product\Sku\\'.$type; |
|
44
|
|
|
|
|
45
|
|
|
return new $className($this->processResponse($response)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDetailsById($skuId) |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'price' => $this->getDetail($skuId, 'Price'), |
|
52
|
|
|
'priceSchedule' => $this->getDetail($skuId, 'PriceSchedule'), |
|
53
|
|
|
'stock' => $this->getDetail($skuId, 'Stock'), |
|
54
|
|
|
'status' => $this->getDetail($skuId, 'Status'), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function update(EntityInterface $entity, EntityInterface $existent = null) |
|
62
|
|
|
{ |
|
63
|
|
|
parent::update($entity, $existent); |
|
64
|
|
|
|
|
65
|
|
|
$m = $this->factoryMap('update', [ |
|
66
|
|
|
'productId' => $entity->getId(), |
|
67
|
|
|
'itemId' => $entity->getId(), |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
return $this->execute($m, $entity->toJson()); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|