Refactor and improve Versandarten settings

This commit is contained in:
Andreas Palm
2022-10-27 13:17:19 +02:00
parent cd93d643f8
commit 1ddee4350c
6 changed files with 172 additions and 227 deletions
+8 -26
View File
@@ -12,32 +12,14 @@ require_once dirname(__DIR__) . '/class.versanddienstleister.php';
class Versandart_sendcloud extends Versanddienstleister
{
protected SendCloudApi $api;
protected array $options;
/* @var SendCloudApi $api */
protected $api;
/* @var array $settings */
protected $settings;
protected $options;
/**
* Versandart_sendcloud constructor.
*
* @param ApplicationCore $app
* @param int $id
*/
public function __construct($app, $id)
public function __construct(Application $app, ?int $id)
{
$this->app = $app;
$this->id = $id;
//TODO move to better place
$res = $this->app->DB->SelectRow("SELECT * FROM versandarten WHERE id=$this->id");
$this->settings = json_decode($res['einstellungen_json']);
$this->type = $res['type'];
$this->paketmarke_drucker = $res['paketmarke_drucker'];
parent::__construct($app, $id);
if (!isset($this->id))
return;
$this->api = new SendCloudApi($this->settings->public_key, $this->settings->private_key);
}
@@ -59,10 +41,10 @@ class Versandart_sendcloud extends Versanddienstleister
$this->options['products'] = array_map(fn(ShippingProduct $x) => $x->Name, $shippingProducts ?? []);
$this->options['products'][0] = '';
$this->options['selectedProduct'] = $shippingProducts[$this->settings->shipping_product];
asort($this->options['products']);
natcasesort($this->options['products']);
}
protected function EinstellungenStruktur()
public function AdditionalSettings(): array
{
$this->FetchOptionsFromApi();
return [