| 1 |
<?php |
| 2 |
|
| 3 |
use MyParcelNL\Sdk\src\Model\Consignment\PostNLConsignment; |
| 4 |
use WPO\WC\PostNL\Collections\SettingsCollection; |
| 5 |
|
| 6 |
class WCPN_Initialize_Settings_Collection |
| 7 |
{ |
| 8 |
/** |
| 9 |
* Initialize the PHP 7.1+ settings collection. |
| 10 |
*/ |
| 11 |
public function initialize(): SettingsCollection |
| 12 |
{ |
| 13 |
// Load settings |
| 14 |
$settings = new SettingsCollection(); |
| 15 |
|
| 16 |
$settings->setSettingsByType($this->getOption("woocommerce_postnl_general_settings"), "general"); |
| 17 |
$settings->setSettingsByType($this->getOption("woocommerce_postnl_checkout_settings"), "checkout"); |
| 18 |
$settings->setSettingsByType($this->getOption("woocommerce_postnl_export_defaults_settings"), "export"); |
| 19 |
|
| 20 |
$settings->setSettingsByType( |
| 21 |
$this->getOption("woocommerce_postnl_postnl_settings"), |
| 22 |
"carrier", |
| 23 |
PostNLConsignment::CARRIER_NAME |
| 24 |
); |
| 25 |
|
| 26 |
return $settings; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @param $option |
| 31 |
* |
| 32 |
* @return array |
| 33 |
*/ |
| 34 |
private function getOption($option): array |
| 35 |
{ |
| 36 |
$option = get_option($option); |
| 37 |
|
| 38 |
if (! $option) { |
| 39 |
return []; |
| 40 |
} |
| 41 |
|
| 42 |
return $option; |
| 43 |
} |
| 44 |
} |
| 45 |
|