| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sendy\WooCommerce\Repositories; |
| 4 |
|
| 5 |
class Shops extends Repository |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Returns a map of shops |
| 9 |
* |
| 10 |
* The shops are stored in the transient for the duration of one hour. The results from the API are transformed to |
| 11 |
* a map of shops with the UUID as key and the name as value. |
| 12 |
* |
| 13 |
* @return array |
| 14 |
* @throws \GuzzleHttp\Exception\GuzzleException |
| 15 |
* @throws \Sendy\Api\ApiException |
| 16 |
*/ |
| 17 |
public function list(): array |
| 18 |
{ |
| 19 |
$shops = get_transient('sendy_shops'); |
| 20 |
|
| 21 |
if (! $shops) { |
| 22 |
$result = $this->connection->shop->list(); |
| 23 |
|
| 24 |
$shops = []; |
| 25 |
|
| 26 |
foreach ($result as $shop) { |
| 27 |
$shops[$shop['uuid']] = $shop['name']; |
| 28 |
} |
| 29 |
|
| 30 |
set_transient('sendy_shops', $shops, 3600); |
| 31 |
} |
| 32 |
|
| 33 |
return $shops; |
| 34 |
} |
| 35 |
} |
| 36 |
|