diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json index ee6c976..b57a11d 100755 --- a/Admin/Install/Media.install.json +++ b/Admin/Install/Media.install.json @@ -12,5 +12,19 @@ "name": "Articles", "virtualPath": "/Modules/ItemManagement", "user": 1 + }, + { + "type": "type", + "name": "item_profile_image", + "l11n": [ + { + "title": "Profile image", + "lang": "en" + }, + { + "title": "Profilbild", + "lang": "de" + } + ] } ] \ No newline at end of file diff --git a/Admin/Install/attributes.json b/Admin/Install/attributes.json index 0910c4e..232cd99 100755 --- a/Admin/Install/attributes.json +++ b/Admin/Install/attributes.json @@ -1,11 +1,71 @@ [ + { + "name": "featured", + "l11n": { + "en": "Featured", + "de": "Featured" + }, + "value_type": 1, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [ + { + "value": 0 + }, + { + "value": 1 + } + ] + }, + { + "name": "shop", + "l11n": { + "en": "Shop Item", + "de": "Shop Artikel" + }, + "value_type": 1, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [ + { + "value": 0 + }, + { + "value": 1 + } + ] + }, + { + "name": "front", + "l11n": { + "en": "Frontpage", + "de": "Frontpage" + }, + "value_type": 1, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [ + { + "value": 0 + }, + { + "value": 1 + } + ] + }, { "name": "segment", "l11n": { "en": "Segment", "de": "Segment" }, - "value_type": "int", + "value_type": 1, "is_custom_allowed": false, "validation_pattern": "", "is_required": true, @@ -26,7 +86,7 @@ "en": "Section", "de": "Sparte" }, - "value_type": "int", + "value_type": 1, "is_custom_allowed": false, "validation_pattern": "", "is_required": true, @@ -47,7 +107,7 @@ "en": "Product Group", "de": "Produktgruppe" }, - "value_type": "int", + "value_type": 1, "is_custom_allowed": false, "validation_pattern": "", "is_required": true, @@ -68,7 +128,7 @@ "en": "Product Type", "de": "Produkttyp" }, - "value_type": "int", + "value_type": 1, "is_custom_allowed": false, "validation_pattern": "", "is_required": true, @@ -83,13 +143,26 @@ } ] }, + { + "name": "hc-code", + "l11n": { + "en": "HC-code", + "de": "Zolltarifnummer" + }, + "value_type": 2, + "is_custom_allowed": true, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [] + }, { "name": "color", "l11n": { "en": "Color", "de": "Farbe" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": false, @@ -138,7 +211,7 @@ "en": "Length", "de": "Laenge" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": true, "validation_pattern": "", "is_required": false, @@ -147,7 +220,7 @@ }, { "name": "weight", - "value_type": "string", + "value_type": 2, "is_custom_allowed": true, "validation_pattern": "", "is_required": false, @@ -164,7 +237,7 @@ "en": "Country of origin", "de": "Herkunftsland" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": true, @@ -177,7 +250,7 @@ "en": "License", "de": "Lizenz" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": false, @@ -190,7 +263,7 @@ "en": "Platform", "de": "Plattform" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": false, @@ -228,7 +301,7 @@ "en": "Operating System", "de": "Betriebssystem" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": false, @@ -259,14 +332,14 @@ } } ] - } + }, { "name": "os_version", "l11n": { "en": "Operating System Version", "de": "Betriebssystem Version" }, - "value_type": "string", + "value_type": 2, "is_custom_allowed": false, "validation_pattern": "", "is_required": false, diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 0f2673b..863e5cd 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -45,6 +45,66 @@ "default": null, "foreignTable": "itemmgmt_item", "foreignKey": "itemmgmt_item_id" + }, + "itemmgmt_item_unit": { + "name": "itemmgmt_item_unit", + "type": "INT", + "default": null, + "null": true, + "foreignTable": "organization_unit", + "foreignKey": "organization_unit_id" + } + } + }, + "itemmgmt_item_relation_type": { + "description": "Items can be related in many ways e.g. expansions, services, successor, tools, spare parts, materials", + "name": "itemmgmt_item_relation_type", + "fields": { + "itemmgmt_item_relation_type_id": { + "name": "itemmgmt_item_relation_type_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "itemmgmt_item_relation_type_title": { + "name": "itemmgmt_item_relation_type_title", + "type": "VARCHAR(30)", + "null": false, + "unique": true + } + } + }, + "itemmgmt_item_relation": { + "name": "itemmgmt_item_relation", + "fields": { + "itemmgmt_item_relation_id": { + "name": "itemmgmt_item_relation_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "itemmgmt_item_relation_type": { + "name": "itemmgmt_item_relation_type", + "type": "INT", + "null": false, + "foreignTable": "itemmgmt_item_relation_type", + "foreignKey": "itemmgmt_item_relation_type_id" + }, + "itemmgmt_item_relation_src": { + "name": "itemmgmt_item_relation_src", + "type": "INT", + "null": false, + "foreignTable": "itemmgmt_item", + "foreignKey": "itemmgmt_item_id" + }, + "itemmgmt_item_relation_dst": { + "name": "itemmgmt_item_relation_dst", + "type": "INT", + "null": false, + "foreignTable": "itemmgmt_item", + "foreignKey": "itemmgmt_item_id" } } }, @@ -60,7 +120,7 @@ }, "itemmgmt_item_l11n_type_title": { "name": "itemmgmt_item_l11n_type_title", - "type": "VARCHAR(255)", + "type": "VARCHAR(50)", "null": false }, "itemmgmt_item_l11n_type_required": { @@ -122,6 +182,12 @@ "itemmgmt_attr_type_name": { "name": "itemmgmt_attr_type_name", "type": "VARCHAR(255)", + "null": false, + "unique": true + }, + "itemmgmt_attr_type_datatype": { + "name": "itemmgmt_attr_type_datatype", + "type": "INT(11)", "null": false }, "itemmgmt_attr_type_fields": { @@ -194,11 +260,6 @@ "type": "TINYINT(1)", "null": false }, - "itemmgmt_attr_value_valuetype": { - "name": "itemmgmt_attr_value_valuetype", - "type": "INT(11)", - "null": false - }, "itemmgmt_attr_value_valueStr": { "name": "itemmgmt_attr_value_valueStr", "type": "VARCHAR(255)", diff --git a/Admin/Install/localizations.json b/Admin/Install/localizations.json index e69de29..b88f1d4 100755 --- a/Admin/Install/localizations.json +++ b/Admin/Install/localizations.json @@ -0,0 +1,22 @@ +[ + { + "name": "name1", + "is_required": true + }, + { + "name": "name2", + "is_required": false + }, + { + "name": "info", + "is_required": false + }, + { + "name": "description_short", + "is_required": false + }, + { + "name": "description_long", + "is_required": false + } +] \ No newline at end of file diff --git a/Admin/Install/relations.json b/Admin/Install/relations.json new file mode 100644 index 0000000..d42fe1e --- /dev/null +++ b/Admin/Install/relations.json @@ -0,0 +1,29 @@ +[ + { + "name": "spare_part" + }, + { + "name": "service" + }, + { + "name": "expansion" + }, + { + "name": "tool" + }, + { + "name": "material" + }, + { + "name": "successor" + }, + { + "name": "alternative" + }, + { + "name": "complementary" + }, + { + "name": "other" + } +] \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php index f3d3567..0e79d76 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -47,22 +47,33 @@ final class Installer extends InstallerAbstract { parent::install($app, $info, $cfgHandler); + /* Attributes */ $fileContent = \file_get_contents(__DIR__ . '/Install/attributes.json'); if ($fileContent === false) { return; } - $attributes = \json_decode($fileContent); + $attributes = \json_decode($fileContent, true); $attrTypes = self::createItemAttributeTypes($app, $attributes); - self::createItemAttributeValues($app, $attrTypes, $attributes); + $attrValues = self::createItemAttributeValues($app, $attrTypes, $attributes); + /* Localizations */ $fileContent = \file_get_contents(__DIR__ . '/Install/localizations.json'); if ($fileContent === false) { return; } - $localizations = \json_decode($fileContent); + $localizations = \json_decode($fileContent, true); $l11nTypes = self::createItemL11nTypes($app, $localizations); + + /* Relations */ + $fileContent = \file_get_contents(__DIR__ . '/Install/relations.json'); + if ($fileContent === false) { + return; + } + + $relations = \json_decode($fileContent, true); + $l11nTypes = self::createItemRelationTypes($app, $relations); } /** @@ -87,7 +98,7 @@ final class Installer extends InstallerAbstract $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); - $request->header->account = \mt_rand(2, 5); + $request->header->account = 1; $request->setData('title', $l11n['name']); $request->setData('is_required', $l11n['is_required'] ?? false); @@ -106,6 +117,46 @@ final class Installer extends InstallerAbstract return $l11nTypes; } + /** + * Install default relation types + * + * @param ApplicationAbstract $app Application + * @param array $relations Attribute definition + * + * @return array + * + * @since 1.0.0 + */ + private static function createItemRelationTypes(ApplicationAbstract $app, array $rels) : array + { + /** @var array $relations */ + $relations = []; + + /** @var \Modules\ItemManagement\Controller\ApiController $module */ + $module = $app->moduleManager->getModuleInstance('ItemManagement'); + + foreach ($rels as $rel) { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('title', $rel['name']); + + $module->apiItemRelationTypeCreate($request, $response); + + $responseData = $response->get(''); + if (!\is_array($responseData)) { + continue; + } + + $relations[] = !\is_array($responseData['response']) + ? $responseData['response']->toArray() + : $responseData['response']; + } + + return $relations; + } + /** * Install default attribute types * @@ -131,11 +182,12 @@ final class Installer extends InstallerAbstract $request->header->account = 1; $request->setData('name', $attribute['name'] ?? ''); - $request->setData('title', $attribute['l11n'][0] ?? ''); + $request->setData('title', \reset($attribute['l11n'])); $request->setData('language', \array_keys($attribute['l11n'])[0] ?? 'en'); $request->setData('is_required', $attribute['is_required'] ?? false); $request->setData('is_custom_allowed', $attribute['is_custom_allowed'] ?? false); $request->setData('validation_pattern', $attribute['validation_pattern'] ?? ''); + $request->setData('datatype', (int) $attribute['value_type']); $module->apiItemAttributeTypeCreate($request, $response); @@ -199,13 +251,12 @@ final class Installer extends InstallerAbstract $request->header->account = 1; $request->setData('value', $value['value'] ?? ''); - $request->setData('value_type', $attribute['value_type'] ?? 0); $request->setData('unit', $value['unit'] ?? ''); $request->setData('default', isset($attribute['values']) && !empty($attribute['values'])); $request->setData('attributetype', $itemAttrType[$attribute['name']]['id']); if (isset($value['l11n']) && !empty($value['l11n'])) { - $request->setData('title', $value['l11n'][0] ?? ''); + $request->setData('title', \reset($value['l11n'])); $request->setData('language', \array_keys($value['l11n'])[0] ?? 'en'); } diff --git a/Controller/ApiController.php b/Controller/ApiController.php index fe1bee4..4413395 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -18,17 +18,18 @@ use Modules\ItemManagement\Models\Item; use Modules\ItemManagement\Models\ItemAttribute; use Modules\ItemManagement\Models\ItemAttributeMapper; use Modules\ItemManagement\Models\ItemAttributeType; -use Modules\ItemManagement\Models\ItemAttributeTypeL11n; +use phpOMS\Localization\BaseStringL11n; use Modules\ItemManagement\Models\ItemAttributeTypeL11nMapper; use Modules\ItemManagement\Models\ItemAttributeTypeMapper; use Modules\ItemManagement\Models\ItemAttributeValue; -use Modules\ItemManagement\Models\ItemAttributeValueL11n; use Modules\ItemManagement\Models\ItemAttributeValueL11nMapper; use Modules\ItemManagement\Models\ItemAttributeValueMapper; use Modules\ItemManagement\Models\ItemL11n; use Modules\ItemManagement\Models\ItemL11nMapper; use Modules\ItemManagement\Models\ItemL11nType; use Modules\ItemManagement\Models\ItemL11nTypeMapper; +use Modules\ItemManagement\Models\ItemRelationType; +use Modules\ItemManagement\Models\ItemRelationTypeMapper; use Modules\ItemManagement\Models\ItemMapper; use Modules\ItemManagement\Models\ItemPrice; use Modules\ItemManagement\Models\ItemPriceStatus; @@ -78,7 +79,11 @@ final class ApiController extends Controller } $item = $this->createItemFromRequest($request); + + $this->app->dbPool->get()->con->beginTransaction(); $this->createModel($request->header->account, $item, ItemMapper::class, 'item', $request->getOrigin()); + $this->app->dbPool->get()->con->commit(); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Item', 'Item successfully created', $item); } @@ -99,6 +104,7 @@ final class ApiController extends Controller $item->purchasePrice = new Money($request->getData('purchaseprice', 'int') ?? 0); $item->info = (string) ($request->getData('info') ?? ''); $item->parent = ($request->getData('parent') !== null) ? (int) $request->getData('parent') : null; + $item->unit = ($request->getData('unit') !== null) ? (int) $request->getData('unit') : null; return $item; } @@ -314,18 +320,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ItemAttributeTypeL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createItemAttributeTypeL11nFromRequest(RequestAbstract $request) : ItemAttributeTypeL11n + private function createItemAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $attrL11n = new ItemAttributeTypeL11n(); - $attrL11n->type = (int) ($request->getData('type') ?? 0); + $attrL11n = new BaseStringL11n(); + $attrL11n->ref = (int) ($request->getData('type') ?? 0); $attrL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $attrL11n->title = (string) ($request->getData('title') ?? ''); + $attrL11n->content = (string) ($request->getData('title') ?? ''); return $attrL11n; } @@ -392,6 +398,7 @@ final class ApiController extends Controller { $attrType = new ItemAttributeType($request->getData('name') ?? ''); $attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN); + $attrType->datatype = (int) ($request->getData('datatype') ?? 0); $attrType->setFields((int) ($request->getData('fields') ?? 0)); $attrType->custom = (bool) ($request->getData('custom') ?? false); $attrType->isRequired = (bool) ($request->getData('is_required') ?? false); @@ -449,7 +456,7 @@ final class ApiController extends Controller if ($attrValue->isDefault) { $this->createModelRelation( $request->header->account, - (int) $request->getData('attributetype'), + (int) $request->getData('type'), $attrValue->getId(), ItemAttributeTypeMapper::class, 'defaults', '', $request->getOrigin() ); @@ -469,10 +476,13 @@ final class ApiController extends Controller */ private function createItemAttributeValueFromRequest(RequestAbstract $request) : ItemAttributeValue { - $type = (int) ($request->getData('type') ?? 0); + $type = ItemAttributeTypeMapper::get() + ->where('id', (int) ($request->getData('type') ?? 0)) + ->execute(); - $attrValue = new ItemAttributeValue($type, $request->getData('value')); + $attrValue = new ItemAttributeValue(); $attrValue->isDefault = (bool) ($request->getData('default') ?? false); + $attrValue->setValue($request->getData('value'), $type->datatype); if ($request->getData('title') !== null) { $attrValue->setL11n($request->getData('title'), $request->getData('language') ?? ISO639x1Enum::_EN); @@ -534,18 +544,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ItemAttributeValueL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createItemAttributeValueL11nFromRequest(RequestAbstract $request) : ItemAttributeValueL11n + private function createItemAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $attrL11n = new ItemAttributeValueL11n(); - $attrL11n->value = (int) ($request->getData('value') ?? 0); + $attrL11n = new BaseStringL11n(); + $attrL11n->ref = (int) ($request->getData('value') ?? 0); $attrL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $attrL11n->title = (string) ($request->getData('title') ?? ''); + $attrL11n->content = (string) ($request->getData('title') ?? ''); return $attrL11n; } @@ -635,6 +645,69 @@ final class ApiController extends Controller return []; } + /** + * Api method to create item l11n type + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiItemRelationTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void + { + if (!empty($val = $this->validateItemRelationTypeCreate($request))) { + $response->set('item_relation_type_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $itemRelationType = $this->createItemRelationTypeFromRequest($request); + $this->createModel($request->header->account, $itemRelationType, ItemRelationTypeMapper::class, 'item_relation_type', $request->getOrigin()); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Item relation type', 'Item relation type successfully created', $itemRelationType); + } + + /** + * Method to create item l11n type from request. + * + * @param RequestAbstract $request Request + * + * @return ItemRelationType + * + * @since 1.0.0 + */ + private function createItemRelationTypeFromRequest(RequestAbstract $request) : ItemRelationType + { + $itemRelationType = new ItemRelationType(); + $itemRelationType->title = (string) ($request->getData('title') ?? ''); + + return $itemRelationType; + } + + /** + * Validate item l11n type create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateItemRelationTypeCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['title'] = empty($request->getData('title')))) { + return $val; + } + + return []; + } + /** * Api method to create item l11n * diff --git a/Models/Item.php b/Models/Item.php index 917e5cc..2e361f3 100755 --- a/Models/Item.php +++ b/Models/Item.php @@ -101,6 +101,14 @@ class Item public string $info = ''; + /** + * Unit + * + * @var null|int + * @since 1.0.0 + */ + public ?int $unit = null; + /** * Constructor. * @@ -237,6 +245,47 @@ class Item return $this->attributes; } + /** + * Has attribute value + * + * @param string $attrName Attribute name + * @param mixed $attrValue Attribute value + * + * @return bool + * + * @since 1.0.0 + */ + public function hasAttributeValue(string $attrName, mixed $attrValue) : bool + { + foreach ($this->attributes as $attribute) { + if ($attribute->type->name === $attrName && $attribute->value->getValue() === $attrValue) { + return true; + } + } + + return false; + } + + /** + * Get attribute + * + * @param string $attrName Attribute name + * + * @return null|AttributeValue + * + * @since 1.0.0 + */ + public function getAttribute(string $attrName) : ?AttributeValue + { + foreach ($this->attributes as $attribute) { + if ($attribute->type->name === $attrName) { + return $attribute->value; + } + } + + return null; + } + /** * Add note to item * @@ -295,6 +344,26 @@ class Item return new NullMedia(); } + /** + * Get all media files by type name + * + * @param string $type Media type + * + * @return Media + * + * @since 1.0.0 + */ + public function getFileByTypeName(string $type) : Media + { + foreach ($this->files as $file) { + if ($file->type->name === $type) { + return $file; + } + } + + return new NullMedia(); + } + /** * Get all media files by type * diff --git a/Models/ItemAttributeType.php b/Models/ItemAttributeType.php index 56a5f88..061dc98 100755 --- a/Models/ItemAttributeType.php +++ b/Models/ItemAttributeType.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\Models; use phpOMS\Localization\ISO639x1Enum; +use phpOMS\Localization\BaseStringL11n; /** * Item Attribute Type class. @@ -62,12 +63,20 @@ class ItemAttributeType implements \JsonSerializable public bool $isRequired = false; + /** + * Datatype of the attribute + * + * @var int + * @since 1.0.0 + */ + public int $datatype = AttributeValueType::_STRING; + /** * Localization * - * @var ItemAttributeTypeL11n + * @var BaseStringL11n */ - private string | ItemAttributeTypeL11n $l11n = ''; + private string | BaseStringL11n $l11n = ''; /** * Possible default attribute values @@ -111,22 +120,22 @@ class ItemAttributeType implements \JsonSerializable /** * Set l11n * - * @param string|ItemAttributeTypeL11n $l11n Tag article l11n + * @param string|BaseStringL11n $l11n Tag article l11n * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setL11n(string | ItemAttributeTypeL11n $l11n, string $lang = ISO639x1Enum::_EN) : void + public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { - if ($l11n instanceof ItemAttributeTypeL11n) { + if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof ItemAttributeTypeL11n) { - $this->l11n->title = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; } else { - $this->l11n = new ItemAttributeTypeL11n(); - $this->l11n->title = $l11n; + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; $this->l11n->setLanguage($lang); } } @@ -138,7 +147,7 @@ class ItemAttributeType implements \JsonSerializable */ public function getL11n() : string { - return $this->l11n instanceof ItemAttributeTypeL11n ? $this->l11n->title : $this->l11n; + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** diff --git a/Models/ItemAttributeTypeL11n.php b/Models/ItemAttributeTypeL11n.php deleted file mode 100755 index 2802de4..0000000 --- a/Models/ItemAttributeTypeL11n.php +++ /dev/null @@ -1,135 +0,0 @@ -type = $type; - $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, - 'type' => $this->type, - 'language' => $this->language, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/ItemAttributeTypeL11nMapper.php b/Models/ItemAttributeTypeL11nMapper.php index 672181d..d2b3c09 100755 --- a/Models/ItemAttributeTypeL11nMapper.php +++ b/Models/ItemAttributeTypeL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Item mapper class. @@ -34,8 +35,8 @@ final class ItemAttributeTypeL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'itemmgmt_attr_type_l11n_id' => ['name' => 'itemmgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'itemmgmt_attr_type_l11n_title' => ['name' => 'itemmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'itemmgmt_attr_type_l11n_type' => ['name' => 'itemmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + 'itemmgmt_attr_type_l11n_title' => ['name' => 'itemmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'itemmgmt_attr_type_l11n_type' => ['name' => 'itemmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], 'itemmgmt_attr_type_l11n_lang' => ['name' => 'itemmgmt_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class ItemAttributeTypeL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='itemmgmt_attr_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/ItemAttributeTypeMapper.php b/Models/ItemAttributeTypeMapper.php index b0394cf..3ed099c 100755 --- a/Models/ItemAttributeTypeMapper.php +++ b/Models/ItemAttributeTypeMapper.php @@ -35,6 +35,7 @@ final class ItemAttributeTypeMapper extends DataMapperFactory public const COLUMNS = [ 'itemmgmt_attr_type_id' => ['name' => 'itemmgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'], 'itemmgmt_attr_type_name' => ['name' => 'itemmgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'itemmgmt_attr_type_datatype' => ['name' => 'itemmgmt_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'], 'itemmgmt_attr_type_fields' => ['name' => 'itemmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'itemmgmt_attr_type_custom' => ['name' => 'itemmgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], 'itemmgmt_attr_type_pattern' => ['name' => 'itemmgmt_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], diff --git a/Models/ItemAttributeValue.php b/Models/ItemAttributeValue.php index 29f29be..c5ace47 100755 --- a/Models/ItemAttributeValue.php +++ b/Models/ItemAttributeValue.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\Models; use phpOMS\Localization\ISO639x1Enum; +use phpOMS\Localization\BaseStringL11n; /** * Item attribute value class. @@ -36,14 +37,6 @@ class ItemAttributeValue implements \JsonSerializable */ protected int $id = 0; - /** - * Datatype of the attribute - * - * @var int - * @since 1.0.0 - */ - public int $type = 0; - /** * Int value * @@ -95,24 +88,9 @@ class ItemAttributeValue implements \JsonSerializable /** * Localization * - * @var null|ItemAttributeValueL11n + * @var null|BaseStringL11n */ - private ?ItemAttributeValueL11n $l11n = null; - - /** - * Constructor. - * - * @param int $type Type - * @param mixed $value Value - * - * @since 1.0.0 - */ - public function __construct(int $type = 0, mixed $value = '') - { - $this->type = $type; - - $this->setValue($value); - } + private ?BaseStringL11n $l11n = null; /** * Get id @@ -129,22 +107,23 @@ class ItemAttributeValue implements \JsonSerializable /** * Set l11n * - * @param string|ItemAttributeValueL11n $l11n Tag article l11n + * @param string|BaseStringL11n $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 + public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { - if ($l11n instanceof ItemAttributeValueL11n) { + if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof ItemAttributeValueL11n) { - $this->l11n->title = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; } else { - $this->l11n = new ItemAttributeValueL11n(); - $this->l11n->title = $l11n; + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; + $this->l11n->ref = $this->id; $this->l11n->setLanguage($lang); } } @@ -158,28 +137,29 @@ class ItemAttributeValue implements \JsonSerializable */ public function getL11n() : ?string { - return $this->l11n instanceof ItemAttributeValueL11n ? $this->l11n->title : $this->l11n; + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** * Set value * * @param int|string|float|\DateTimeInterface $value Value + * @param int $type Datatype * * @return void * * @since 1.0.0 */ - public function setValue(mixed $value) : void + public function setValue(mixed $value, int $datatype) : void { - if (\is_string($value)) { - $this->valueStr = $value; - } elseif (\is_int($value)) { - $this->valueInt = $value; - } elseif (\is_float($value)) { - $this->valueDec = $value; - } elseif ($value instanceof \DateTimeInterface) { - $this->valueDat = $value; + if ($datatype === AttributeValueType::_STRING) { + $this->valueStr = (string) $value; + } elseif ($datatype === AttributeValueType::_INT) { + $this->valueInt = (int) $value; + } elseif ($datatype === AttributeValueType::_FLOAT) { + $this->valueDec = (float) $value; + } elseif ($datatype === AttributeValueType::_DATETIME) { + $this->valueDat = new \DateTime($value); } } @@ -212,7 +192,6 @@ class ItemAttributeValue implements \JsonSerializable { return [ 'id' => $this->id, - 'type' => $this->type, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, diff --git a/Models/ItemAttributeValueL11n.php b/Models/ItemAttributeValueL11n.php deleted file mode 100755 index 56af345..0000000 --- a/Models/ItemAttributeValueL11n.php +++ /dev/null @@ -1,135 +0,0 @@ -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 index f608fee..be23920 100755 --- a/Models/ItemAttributeValueL11nMapper.php +++ b/Models/ItemAttributeValueL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Item mapper class. @@ -34,8 +35,8 @@ final class ItemAttributeValueL11nMapper extends DataMapperFactory */ 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_title' => ['name' => 'itemmgmt_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'itemmgmt_attr_value_l11n_value' => ['name' => 'itemmgmt_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'], 'itemmgmt_attr_value_l11n_lang' => ['name' => 'itemmgmt_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class ItemAttributeValueL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='itemmgmt_attr_value_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/ItemAttributeValueMapper.php b/Models/ItemAttributeValueMapper.php index 432ebd0..de5b3ac 100755 --- a/Models/ItemAttributeValueMapper.php +++ b/Models/ItemAttributeValueMapper.php @@ -35,7 +35,6 @@ final class ItemAttributeValueMapper extends DataMapperFactory public const COLUMNS = [ 'itemmgmt_attr_value_id' => ['name' => 'itemmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'], 'itemmgmt_attr_value_default' => ['name' => 'itemmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'itemmgmt_attr_value_valuetype' => ['name' => 'itemmgmt_attr_value_valuetype', 'type' => 'int', 'internal' => 'type'], 'itemmgmt_attr_value_valueStr' => ['name' => 'itemmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], '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'], @@ -53,8 +52,7 @@ final class ItemAttributeValueMapper extends DataMapperFactory 'l11n' => [ 'mapper' => ItemAttributeValueL11nMapper::class, 'table' => 'itemmgmt_attr_value_l11n', - 'self' => 'itemmgmt_attr_value_l11n_type', - 'column' => 'title', + 'self' => 'itemmgmt_attr_value_l11n_value', 'external' => null, ], ]; diff --git a/Models/ItemMapper.php b/Models/ItemMapper.php index 15002dc..b66fe18 100755 --- a/Models/ItemMapper.php +++ b/Models/ItemMapper.php @@ -42,6 +42,7 @@ final class ItemMapper extends DataMapperFactory 'itemmgmt_item_salesprice' => ['name' => 'itemmgmt_item_salesprice', 'type' => 'Serializable', 'internal' => 'salesPrice'], 'itemmgmt_item_purchaseprice' => ['name' => 'itemmgmt_item_purchaseprice', 'type' => 'Serializable', 'internal' => 'purchasePrice'], 'itemmgmt_item_parent' => ['name' => 'itemmgmt_item_parent', 'type' => 'int', 'internal' => 'parent'], + 'itemmgmt_item_unit' => ['name' => 'itemmgmt_item_unit', 'type' => 'int', 'internal' => 'unit'], ]; /** diff --git a/Models/ItemRelation.php b/Models/ItemRelation.php new file mode 100644 index 0000000..bce33c6 --- /dev/null +++ b/Models/ItemRelation.php @@ -0,0 +1,91 @@ +type = $type ?? new ItemRelationType(); + } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'source' => $this->source, + 'destination' => $this->destination, + 'type' => $this->type, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/ItemRelationMapper.php b/Models/ItemRelationMapper.php new file mode 100644 index 0000000..536a6a2 --- /dev/null +++ b/Models/ItemRelationMapper.php @@ -0,0 +1,70 @@ + + * @since 1.0.0 + */ + public const COLUMNS = [ + 'itemmgmt_item_relation_id' => ['name' => 'itemmgmt_item_relation_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_item_relation_src' => ['name' => 'itemmgmt_item_relation_src', 'type' => 'int', 'internal' => 'source'], + 'itemmgmt_item_relation_dst' => ['name' => 'itemmgmt_item_relation_dst', 'type' => 'int', 'internal' => 'destination'], + 'itemmgmt_item_relation_type' => ['name' => 'itemmgmt_item_relation_type', 'type' => 'int', 'internal' => 'type'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + public const OWNS_ONE = [ + 'type' => [ + 'mapper' => ItemRelationTypeMapper::class, + 'external' => 'itemmgmt_item_relation_type', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'itemmgmt_item_relation'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD ='itemmgmt_item_relation_id'; +} diff --git a/Models/ItemRelationType.php b/Models/ItemRelationType.php new file mode 100644 index 0000000..6bd52c4 --- /dev/null +++ b/Models/ItemRelationType.php @@ -0,0 +1,61 @@ + $this->id, + 'title' => $this->title, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return $this->toArray(); + } +} diff --git a/Models/ItemRelationTypeMapper.php b/Models/ItemRelationTypeMapper.php new file mode 100644 index 0000000..a4de905 --- /dev/null +++ b/Models/ItemRelationTypeMapper.php @@ -0,0 +1,55 @@ + + * @since 1.0.0 + */ + public const COLUMNS = [ + 'itemmgmt_item_relation_type_id' => ['name' => 'itemmgmt_item_relation_type_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_item_relation_type_title' => ['name' => 'itemmgmt_item_relation_type_title', 'type' => 'string', 'internal' => 'title'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'itemmgmt_item_relation_type'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD ='itemmgmt_item_relation_type_id'; +} diff --git a/Models/NullItemAttributeTypeL11n.php b/Models/NullItemRelation.php old mode 100755 new mode 100644 similarity index 88% rename from Models/NullItemAttributeTypeL11n.php rename to Models/NullItemRelation.php index 8f42a3d..f0acde9 --- a/Models/NullItemAttributeTypeL11n.php +++ b/Models/NullItemRelation.php @@ -22,7 +22,7 @@ namespace Modules\ItemManagement\Models; * @link https://jingga.app * @since 1.0.0 */ -final class NullItemAttributeTypeL11n extends ItemAttributeTypeL11n +final class NullItemRelation extends ItemRelation { /** * Constructor @@ -34,7 +34,6 @@ final class NullItemAttributeTypeL11n extends ItemAttributeTypeL11n public function __construct(int $id = 0) { $this->id = $id; - parent::__construct(); } /** diff --git a/Models/NullItemRelationType.php b/Models/NullItemRelationType.php new file mode 100644 index 0000000..15b6b4d --- /dev/null +++ b/Models/NullItemRelationType.php @@ -0,0 +1,46 @@ +id = $id; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Theme/Backend/sales-item-list.tpl.php b/Theme/Backend/sales-item-list.tpl.php index 5c701e8..87aaa5a 100755 --- a/Theme/Backend/sales-item-list.tpl.php +++ b/Theme/Backend/sales-item-list.tpl.php @@ -130,7 +130,7 @@ echo $this->getData('nav')->render(); ?> $value) : ++$count; $url = UriFactory::build('{/lang}/{/app}/sales/item/profile?{?}&id=' . $value->getId()); - $image = $value->getFileByType(0); + $image = $value->getFileByTypeName('item_profile_image'); ?> <?= $this->getHtml('IMG_alt_item'); ?>header->account = 1; + $request->setData('attributetype', '1'); $request->setData('type', AttributeValueType::_STRING); $request->setData('value', '1'); $request->setData('language', ISO639x1Enum::_DE); @@ -144,6 +145,7 @@ trait ApiControllerAttributeTrait $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; + $request->setData('attributetype', '1'); $request->setData('type', AttributeValueType::_FLOAT); $request->setData('value', '1.1'); $request->setData('language', ISO639x1Enum::_DE); @@ -163,6 +165,7 @@ trait ApiControllerAttributeTrait $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; + $request->setData('attributetype', '1'); $request->setData('type', AttributeValueType::_DATETIME); $request->setData('value', '2020-08-02'); $request->setData('language', ISO639x1Enum::_DE); diff --git a/tests/Models/ItemAttributeTypeL11nTest.php b/tests/Models/ItemAttributeTypeL11nTest.php deleted file mode 100755 index 36fa357..0000000 --- a/tests/Models/ItemAttributeTypeL11nTest.php +++ /dev/null @@ -1,87 +0,0 @@ -l11n = new ItemAttributeTypeL11n(); - } - - /** - * @covers Modules\ItemManagement\Models\ItemAttributeTypeL11n - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->l11n->getId()); - self::assertEquals('', $this->l11n->title); - self::assertEquals(0, $this->l11n->type); - self::assertEquals(ISO639x1Enum::_EN, $this->l11n->getLanguage()); - } - - /** - * @covers Modules\ItemManagement\Models\ItemAttributeTypeL11n - * @group module - */ - public function testNameInputOutput() : void - { - $this->l11n->title = 'TestName'; - self::assertEquals('TestName', $this->l11n->title); - } - - /** - * @covers Modules\ItemManagement\Models\ItemAttributeTypeL11n - * @group module - */ - public function testLanguageInputOutput() : void - { - $this->l11n->setLanguage(ISO639x1Enum::_DE); - self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage()); - } - - /** - * @covers Modules\ItemManagement\Models\ItemAttributeTypeL11n - * @group module - */ - public function testSerialize() : void - { - $this->l11n->title = 'Title'; - $this->l11n->type = 2; - $this->l11n->setLanguage(ISO639x1Enum::_DE); - - self::assertEquals( - [ - 'id' => 0, - 'title' => 'Title', - 'type' => 2, - 'language' => ISO639x1Enum::_DE, - ], - $this->l11n->jsonSerialize() - ); - } -} diff --git a/tests/Models/ItemAttributeTypeTest.php b/tests/Models/ItemAttributeTypeTest.php index 0d7689a..0a13851 100755 --- a/tests/Models/ItemAttributeTypeTest.php +++ b/tests/Models/ItemAttributeTypeTest.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\tests\Models; use Modules\ItemManagement\Models\ItemAttributeType; -use Modules\ItemManagement\Models\ItemAttributeTypeL11n; +use phpOMS\Localization\BaseStringL11n; /** * @internal @@ -55,7 +55,7 @@ final class ItemAttributeTypeTest extends \PHPUnit\Framework\TestCase $this->attr->setL11n('Test'); self::assertEquals('Test', $this->attr->getL11n()); - $this->attr->setL11n(new ItemAttributeTypeL11n(0, 'NewTest')); + $this->attr->setL11n(new BaseStringL11n('NewTest')); self::assertEquals('NewTest', $this->attr->getL11n()); } diff --git a/tests/Models/ItemAttributeValueTest.php b/tests/Models/ItemAttributeValueTest.php index d5d66a7..573ed3f 100755 --- a/tests/Models/ItemAttributeValueTest.php +++ b/tests/Models/ItemAttributeValueTest.php @@ -15,20 +15,21 @@ declare(strict_types=1); namespace Modules\ItemManagement\tests\Models; use Modules\ItemManagement\Models\ItemAttributeValue; +use Modules\ItemManagement\Models\AttributeValueType; /** * @internal */ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase { - private ItemAttributeValue $attr; + private ItemAttributeValue $value; /** * {@inheritdoc} */ protected function setUp() : void { - $this->attr = new ItemAttributeValue(); + $this->value = new ItemAttributeValue(); } /** @@ -37,10 +38,9 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testDefault() : void { - self::assertEquals(0, $this->attr->getId()); - self::assertEquals(0, $this->attr->type); - self::assertNull($this->attr->getValue()); - self::assertFalse($this->attr->isDefault); + self::assertEquals(0, $this->value->getId()); + self::assertNull($this->value->getValue()); + self::assertFalse($this->value->isDefault); } /** @@ -49,8 +49,8 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testValueIntInputOutput() : void { - $this->attr->setValue(1); - self::assertEquals(1, $this->attr->getValue()); + $this->value->setValue(1, AttributeValueType::_INT); + self::assertEquals(1, $this->value->getValue()); } /** @@ -59,8 +59,8 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testValueFloatInputOutput() : void { - $this->attr->setValue(1.1); - self::assertEquals(1.1, $this->attr->getValue()); + $this->value->setValue(1.1, AttributeValueType::_FLOAT); + self::assertEquals(1.1, $this->value->getValue()); } /** @@ -69,8 +69,8 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testValueStringInputOutput() : void { - $this->attr->setValue('test'); - self::assertEquals('test', $this->attr->getValue()); + $this->value->setValue('test', AttributeValueType::_STRING); + self::assertEquals('test', $this->value->getValue()); } /** @@ -79,8 +79,9 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testValueDateInputOutput() : void { - $this->attr->setValue($dat = new \DateTime('now')); - self::assertEquals($dat->format('Y-m-d'), $this->attr->getValue()->format('Y-m-d')); + $dat = new \DateTime('now'); + $this->value->setValue('now', AttributeValueType::_DATETIME); + self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d')); } /** @@ -89,21 +90,19 @@ final class ItemAttributeValueTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->attr->type = 1; - $this->attr->setValue('test'); - $this->attr->isDefault = true; + $this->value->setValue('test', AttributeValueType::_STRING); + $this->value->isDefault = true; self::assertEquals( [ 'id' => 0, - 'type' => 1, 'valueInt' => null, 'valueStr' => 'test', 'valueDec' => null, 'valueDat' => null, 'isDefault' => true, ], - $this->attr->jsonSerialize() + $this->value->jsonSerialize() ); } } diff --git a/tests/Models/NullItemAttributeTypeL11nTest.php b/tests/Models/NullItemAttributeTypeL11nTest.php deleted file mode 100755 index 50283fd..0000000 --- a/tests/Models/NullItemAttributeTypeL11nTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -}