-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
191 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Gam6itko\OzonSeller\Service\Seller; | ||
|
||
use Gam6itko\OzonSeller\Service\AbstractService; | ||
|
||
/** | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action | ||
* | ||
* @author Alexander Strizhak <gam6itko@gmail.com> | ||
*/ | ||
class ActionsService extends AbstractService | ||
{ | ||
private $path = '/sa/v1/actions'; | ||
|
||
public function __construct(int $clientId, string $apiKey, string $host = 'https://seller-api.ozon.ru/') | ||
{ | ||
parent::__construct($clientId, $apiKey, $host); | ||
} | ||
|
||
/** | ||
* Promotional offers list. | ||
* | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action_available | ||
*/ | ||
public function list(): array | ||
{ | ||
return $this->request('GET', $this->path); | ||
} | ||
|
||
/** | ||
* List of products which can participate in the promotional offer. | ||
* | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action_available_products | ||
*/ | ||
public function candidates(int $actionId, int $offset = 0, int $limit = 10): array | ||
{ | ||
$body = [ | ||
'action_id' => $actionId, | ||
'offset' => $offset, | ||
'limit' => $limit, | ||
]; | ||
|
||
return $this->request('POST', "{$this->path}/candidates", ['body' => \GuzzleHttp\json_encode($body)]); | ||
} | ||
|
||
/** | ||
* List of products which participate in the promotional offer. | ||
* | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action_products | ||
*/ | ||
public function products(int $actionId, int $offset = 0, int $limit = 10) | ||
{ | ||
$body = [ | ||
'action_id' => $actionId, | ||
'offset' => $offset, | ||
'limit' => $limit, | ||
]; | ||
|
||
return $this->request('POST', "{$this->path}/products", ['body' => \GuzzleHttp\json_encode($body)]); | ||
} | ||
|
||
/** | ||
* Add product to the promotional offer. | ||
* | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action_add_products | ||
*/ | ||
public function productsActivate(int $actionId, array $products): array | ||
{ | ||
if (array_key_exists('product_id', $products)) { | ||
$products = [$products]; | ||
} | ||
|
||
foreach ($products as &$p) { | ||
$p = $this->faceControl($p, ['product_id', 'action_price']); | ||
} | ||
unset($p); | ||
|
||
$body = [ | ||
'action_id' => $actionId, | ||
'products' => $products, | ||
]; | ||
|
||
return $this->request('POST', "{$this->path}/products/activate", ['body' => \GuzzleHttp\json_encode($body)]); | ||
} | ||
|
||
/** | ||
* This method allows to delete products from the promotional offer. | ||
* | ||
* @see https://cb-api.ozonru.me/apiref/en/#t-title_action_add_products | ||
*/ | ||
public function productsDeactivate(int $actionId, array $productIds): array | ||
{ | ||
$body = [ | ||
'action_id' => $actionId, | ||
'product_ids' => $productIds, | ||
]; | ||
|
||
return $this->request('POST', "{$this->path}/products/deactivate", ['body' => \GuzzleHttp\json_encode($body)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters