From d5054069762d45a24f742d24194f1a257e4482ac Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 22 Dec 2022 14:19:06 +0100 Subject: [PATCH] improve value localizations --- Admin/Install/db.json | 209 ++++++++++++++++++++++-- Models/ItemAttributeValue.php | 63 +++++-- Models/ItemAttributeValueL11n.php | 135 +++++++++++++++ Models/ItemAttributeValueL11nMapper.php | 57 +++++++ Models/ItemAttributeValueMapper.php | 19 ++- 5 files changed, 451 insertions(+), 32 deletions(-) create mode 100644 Models/ItemAttributeValueL11n.php create mode 100644 Models/ItemAttributeValueL11nMapper.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 0e457d7..f8f9492 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -209,21 +209,41 @@ "null": true, "default": null }, - "itemmgmt_attr_value_lang": { - "name": "itemmgmt_attr_value_lang", + "itemmgmt_attr_value_unit": { + "name": "itemmgmt_attr_value_unit", + "type": "VARCHAR(255)", + "null": false + }, + } + }, + "itemmgmt_attr_value_l11n": { + "name": "itemmgmt_attr_value_l11n", + "fields": { + "itemmgmt_attr_value_l11n_id": { + "name": "itemmgmt_attr_value_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "itemmgmt_attr_value_l11n_title": { + "name": "itemmgmt_attr_value_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "itemmgmt_attr_value_l11n_type": { + "name": "itemmgmt_attr_value_l11n_value", + "type": "INT(11)", + "null": false, + "foreignTable": "itemmgmt_attr_value", + "foreignKey": "itemmgmt_attr_value_id" + }, + "itemmgmt_attr_value_l11n_lang": { + "name": "itemmgmt_attr_value_l11n_lang", "type": "VARCHAR(2)", - "null": true, - "default": null, + "null": false, "foreignTable": "language", "foreignKey": "language_639_1" - }, - "itemmgmt_attr_value_country": { - "name": "itemmgmt_attr_value_country", - "type": "VARCHAR(2)", - "null": true, - "default": null, - "foreignTable": "country", - "foreignKey": "country_code2" } } }, @@ -287,6 +307,171 @@ } } }, + "itemmgmt_item_sales_price": { + "name": "itemmgmt_item_sales_price", + "fields": { + "itemmgmt_item_sales_price_id": { + "name": "itemmgmt_item_sales_price_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "itemmgmt_item_sales_price_name": { + "name": "itemmgmt_item_sales_price_name", + "type": "VARCHAR(255)", + "null": false + }, + "itemmgmt_item_sales_price_price": { + "name": "itemmgmt_item_sales_price_price", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_status": { + "name": "itemmgmt_item_sales_price_status", + "type": "TINYINT(1)", + "null": false + }, + "itemmgmt_item_sales_price_minquantity": { + "name": "itemmgmt_item_sales_price_minquantity", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_relativediscount": { + "name": "itemmgmt_item_sales_price_relativediscount", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_absolutediscount": { + "name": "itemmgmt_item_sales_price_absolutediscount", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_relativeunitdiscount": { + "name": "itemmgmt_item_sales_price_relativeunitdiscount", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_absoluteunitdiscount": { + "name": "itemmgmt_item_sales_price_absoluteunitdiscount", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_region": { + "name": "itemmgmt_item_sales_price_region", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_country": { + "name": "itemmgmt_item_sales_price_country", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_start": { + "name": "itemmgmt_item_sales_price_start", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_end": { + "name": "itemmgmt_item_sales_price_end", + "type": "INT(11)", + "null": false + }, + "itemmgmt_item_sales_price_promocode": { + "name": "itemmgmt_item_sales_price_end", + "type": "INT(11)", + "null": false + } + } + }, + "itemmgmt_item_sales_price_relation": { + "name": "itemmgmt_item_sales_price_relation", + "fields": { + "itemmgmt_item_note_id": { + "name": "itemmgmt_item_sales_price_relation_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "itemmgmt_item_sales_price_relation_item": { + "name": "itemmgmt_item_sales_price_relation_item", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "itemmgmt_item", + "foreignKey": "itemmgmt_item_id" + }, + "itemmgmt_item_sales_price_relation_itemgroup": { + "name": "itemmgmt_item_sales_price_relation_itemgroup", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "itemmgmt_item", + "foreignKey": "itemmgmt_item_id" + }, + "itemmgmt_item_sales_price_relation_client": { + "name": "itemmgmt_item_sales_price_relation_client", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "clientmgmt_client", + "foreignKey": "clientmgmt_client_id" + }, + "itemmgmt_item_sales_price_relation_clientgroup": { + "name": "itemmgmt_item_sales_price_relation_clientgroup", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "clientmgmt_client", + "foreignKey": "clientmgmt_client_id" + }, + "itemmgmt_item_sales_price_relation_price": { + "name": "itemmgmt_item_sales_price_relation_price", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "itemmgmt_item_sales_price", + "foreignKey": "itemmgmt_item_sales_price_id" + } + } + }, + "itemmgmt_item_sales_price_history": { + "name": "itemmgmt_item_sales_price_history", + "fields": { + "itemmgmt_item_sales_price_history_id": { + "name": "itemmgmt_item_sales_price_history_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + } + } + }, + "itemmgmt_item_purchase_price": { + "name": "itemmgmt_item_purchase_price", + "fields": { + "itemmgmt_item_purchase_price_id": { + "name": "itemmgmt_item_purchase_price_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + } + } + }, + "itemmgmt_item_purchase_price_history": { + "name": "itemmgmt_item_purchase_price_history", + "fields": { + "itemmgmt_item_purchase_price_history_id": { + "name": "itemmgmt_item_purchase_price_history_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + } + } + }, "itemmgmt_item_media": { "name": "itemmgmt_item_media", "fields": { diff --git a/Models/ItemAttributeValue.php b/Models/ItemAttributeValue.php index 266fffa..3a15ac4 100755 --- a/Models/ItemAttributeValue.php +++ b/Models/ItemAttributeValue.php @@ -90,36 +90,29 @@ class ItemAttributeValue implements \JsonSerializable // it should be basically the same ass the itemattributetype which has a itemattributetypel11n element. /** - * Language + * Localization * - * @var string - * @since 1.0.0 + * @var null|ItemAttributeValueL11n */ - protected string $language = ISO639x1Enum::_EN; - - /** - * Country - * - * @var string - * @since 1.0.0 - */ - protected string $country = ISO3166TwoEnum::_USA; + private ?ItemAttributeValueL11n $l11n = null; /** * Constructor. * - * @param int $type Type - * @param mixed $value Value - * @param string $language Language + * @param int $type Type + * @param mixed $value Value * * @since 1.0.0 */ - public function __construct(int $type = 0, $value = '', string $language = ISO639x1Enum::_EN) + public function __construct(int $type = 0, mixed $value = '', string $name = '') { - $this->type = $type; - $this->language = $language; + $this->type = $type; $this->setValue($value); + + if (!empty($name)) { + $this->setL11n($name); + } } /** @@ -134,6 +127,40 @@ class ItemAttributeValue implements \JsonSerializable return $this->id; } + + /** + * Set l11n + * + * @param string|ItemAttributeTypeL11n $l11n Tag article l11n + * @param string $lang Language + * + * @return void + * + * @since 1.0.0 + */ + public function setL11n(string | ItemAttributeValueL11n $l11n, string $lang = ISO639x1Enum::_EN) : void + { + if ($l11n instanceof ItemAttributeValueL11n) { + $this->l11n = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof ItemAttributeValueL11n) { + $this->l11n->title = $l11n; + } else { + $this->l11n = new ItemAttributeValueL11n(); + $this->l11n->title = $l11n; + $this->l11n->setLanguage($lang); + } + } + + /** + * @return string + * + * @since 1.0.0 + */ + public function getL11n() : string + { + return $this->l11n instanceof ItemAttributeTypeL11n ? $this->l11n->title : $this->l11n; + } + /** * Set value * diff --git a/Models/ItemAttributeValueL11n.php b/Models/ItemAttributeValueL11n.php new file mode 100644 index 0000000..56af345 --- /dev/null +++ b/Models/ItemAttributeValueL11n.php @@ -0,0 +1,135 @@ +value = $value; + $this->title = $title; + $this->language = $language; + } + + /** + * Get id + * + * @return int + * + * @since 1.0.0 + */ + public function getId() : int + { + return $this->id; + } + + /** + * Get language + * + * @return string + * + * @since 1.0.0 + */ + public function getLanguage() : string + { + return $this->language; + } + + /** + * Set language + * + * @param string $language Language + * + * @return void + * + * @since 1.0.0 + */ + public function setLanguage(string $language) : void + { + $this->language = $language; + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'title' => $this->title, + 'value' => $this->value, + 'language' => $this->language, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/ItemAttributeValueL11nMapper.php b/Models/ItemAttributeValueL11nMapper.php new file mode 100644 index 0000000..c285084 --- /dev/null +++ b/Models/ItemAttributeValueL11nMapper.php @@ -0,0 +1,57 @@ + + * @since 1.0.0 + */ + public const COLUMNS = [ + 'itemmgmt_attr_value_l11n_id' => ['name' => 'itemmgmt_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_attr_value_l11n_title' => ['name' => 'itemmgmt_attr_value_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + 'itemmgmt_attr_value_l11n_value' => ['name' => 'itemmgmt_attr_value_l11n_value', 'type' => 'int', 'internal' => 'value'], + 'itemmgmt_attr_value_l11n_lang' => ['name' => 'itemmgmt_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'itemmgmt_attr_value_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD ='itemmgmt_attr_value_l11n_id'; +} diff --git a/Models/ItemAttributeValueMapper.php b/Models/ItemAttributeValueMapper.php index 53b43bc..7ffe140 100755 --- a/Models/ItemAttributeValueMapper.php +++ b/Models/ItemAttributeValueMapper.php @@ -40,10 +40,25 @@ final class ItemAttributeValueMapper extends DataMapperFactory 'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], 'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], 'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], - 'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'], - 'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'], ]; + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + public const HAS_MANY = [ + 'l11n' => [ + 'mapper' => ItemAttributeValueL11nMapper::class, + 'table' => 'itemmgmt_attr_value_l11n', + 'self' => 'itemmgmt_attr_value_l11n_type', + 'column' => 'title', + 'external' => null, + ], + ]; + + /** * Primary table. *