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