diff --git a/Admin/Install/attributes.json b/Admin/Install/attributes.json index 1adfdc3..7adf08b 100755 --- a/Admin/Install/attributes.json +++ b/Admin/Install/attributes.json @@ -633,19 +633,6 @@ } ] }, - { - "name": "demo_link", - "l11n": { - "en": "Demo link", - "de": "Demo Link" - }, - "value_type": 2, - "is_custom_allowed": true, - "validation_pattern": "", - "is_required": false, - "default_value": "", - "values": [] - }, { "name": "one_click_pay_cc", "l11n": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 88521a4..e223566 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -18,6 +18,7 @@ use Modules\Admin\Models\NullAccount; use Modules\Attribute\Models\Attribute; use Modules\Attribute\Models\AttributeType; use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttribute; use Modules\Attribute\Models\NullAttributeType; use Modules\Attribute\Models\NullAttributeValue; use Modules\ItemManagement\Models\Item; @@ -227,7 +228,7 @@ final class ApiController extends Controller ); } - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Item', 'Item successfully created', $item); + $this->createStandardCreateResponse($request, $response, $item); } /** @@ -319,7 +320,7 @@ final class ApiController extends Controller $item = $this->createItemPriceFromRequest($request); $this->createModel($request->header->account, $item, ItemMapper::class, 'item', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Item', 'Item successfully created', $item); + $this->createStandardCreateResponse($request, $response, $item); } /** @@ -394,8 +395,7 @@ final class ApiController extends Controller $attribute = $this->createItemAttributeFromRequest($request); $this->createModel($request->header->account, $attribute, ItemAttributeMapper::class, 'attribute', $request->getOrigin()); - - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute); + $this->createStandardCreateResponse($request, $response, $attribute); } /** @@ -479,13 +479,22 @@ final class ApiController extends Controller ->execute(); $new = $this->updateItemAttributeFromRequest($request, $old->deepClone()); + + if ($new->id === 0) { + // Set response header to invalid request because of invalid data + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $new); + + return; + } + $this->updateModel($request->header->account, $old, $new, ItemAttributeMapper::class, 'attribute', $request->getOrigin()); if ($new->value->getValue() !== $old->value->getValue()) { $this->updateModel($request->header->account, $old->value, $new->value, ItemAttributeValueMapper::class, 'attribute_value', $request->getOrigin()); } - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully updated', $new); + $this->createStandardUpdateResponse($request, $response, $new); } /** @@ -499,21 +508,21 @@ final class ApiController extends Controller */ private function updateItemAttributeFromRequest(RequestAbstract $request, Attribute $attribute) : Attribute { - if ($attribute->type->custom) { - if ($request->hasData('value')) { - // @question: we are overwriting the old value, could there be a use case where we want to create a new value and keep the old one? - $attribute->value->setValue($request->getData('value'), $attribute->type->datatype); - } - } else { - if ($request->hasData('value')) { - // @todo: fix by only accepting the value id to be used - // this is a workaround for now because the front end doesn't allow to dynamically show default values. - $value = $attribute->type->getDefaultByValue($request->getData('value')); - if ($value->id !== 0) { - $attribute->value = $attribute->type->getDefaultByValue($request->getData('value')); - } + if ($attribute->type->custom) { + // @question: we are overwriting the old value, could there be a use case where we want to create a new value and keep the old one? + $attribute->value->setValue($request->getData('value'), $attribute->type->datatype); + } else { + // @todo: fix by only accepting the value id to be used + // this is a workaround for now because the front end doesn't allow to dynamically show default values. + $value = $attribute->type->getDefaultByValue($request->getData('value')); + + // Couldn't find matching default value + if ($value->id === 0) { + return new NullAttribute(); } + + $attribute->value = $value; } return $attribute; @@ -532,6 +541,7 @@ final class ApiController extends Controller { $val = []; if (($val['id'] = !$request->hasData('id')) + || ($val['value'] = !$request->hasData('value')) ) { return $val; } @@ -563,7 +573,7 @@ final class ApiController extends Controller $attrL11n = $this->createItemAttributeTypeL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, ItemAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); + $this->createStandardCreateResponse($request, $response, $attrL11n); } /** @@ -632,8 +642,7 @@ final class ApiController extends Controller $attrType = $this->createAttributeTypeFromRequest($request); $this->createModel($request->header->account, $attrType, ItemAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); - - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType); + $this->createStandardCreateResponse($request, $response, $attrType); } /** @@ -713,7 +722,7 @@ final class ApiController extends Controller ); } - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue); + $this->createStandardCreateResponse($request, $response, $attrValue); } /** @@ -788,7 +797,7 @@ final class ApiController extends Controller $attrL11n = $this->createAttributeValueL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, ItemAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); + $this->createStandardCreateResponse($request, $response, $attrL11n); } /** @@ -857,7 +866,7 @@ final class ApiController extends Controller $attrL11n = $this->createAttributeValueL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, ItemAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); + $this->createStandardCreateResponse($request, $response, $attrL11n); } /** @@ -884,7 +893,7 @@ final class ApiController extends Controller $itemL11nType = $this->createItemL11nTypeFromRequest($request); $this->createModel($request->header->account, $itemL11nType, ItemL11nTypeMapper::class, 'item_l11n_type', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization type', 'Localization type successfully created', $itemL11nType); + $this->createStandardCreateResponse($request, $response, $itemL11nType); } /** @@ -948,7 +957,7 @@ final class ApiController extends Controller $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); + $this->createStandardCreateResponse($request, $response, $itemRelationType); } /** @@ -1011,7 +1020,7 @@ final class ApiController extends Controller $itemL11n = $this->createItemL11nFromRequest($request); $this->createModel($request->header->account, $itemL11n, ItemL11nMapper::class, 'item_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $itemL11n); + $this->createStandardCreateResponse($request, $response, $itemL11n); } /** @@ -1083,8 +1092,8 @@ final class ApiController extends Controller $uploadedFiles = $request->getFiles(); if (empty($uploadedFiles)) { - $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Item', 'Invalid item image', $uploadedFiles); $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $uploadedFiles); return; } @@ -1127,7 +1136,7 @@ final class ApiController extends Controller ItemMapper::class, 'files', '', $request->getOrigin() ); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Image', 'Image successfully updated', $uploaded); + $this->createStandardUpdateResponse($request, $response, $uploaded); } /** diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 9270070..63cf176 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -204,7 +204,7 @@ final class BackendController extends Controller ->where('l11n/language', $response->getLanguage()) ->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN') ->where('files/types/name', 'item_profile_image') - ->limit(25) + ->limit(50) ->execute(); $view->addData('items', $items); @@ -362,8 +362,8 @@ final class BackendController extends Controller ->with('notes') ->where('id', (int) $request->getData('id')) ->where('l11n/language', $response->getLanguage()) - ->where('attributes/type/l11n/language', $response->getLanguage()) ->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN') + ->where('attributes/type/l11n/language', $response->getLanguage()) ->limit(5, 'files')->sort('files/id', OrderType::DESC) ->limit(5, 'notes')->sort('notes/id', OrderType::DESC) ->execute(); @@ -410,7 +410,7 @@ final class BackendController extends Controller $l11nValues = ItemL11nMapper::getAll() ->with('type') - ->where('item', $item->id) + ->where('ref', $item->id) ->execute(); $view->setData('l11nValues', $l11nValues); diff --git a/Models/Item.php b/Models/Item.php index 455af0a..df33880 100755 --- a/Models/Item.php +++ b/Models/Item.php @@ -45,14 +45,44 @@ class Item implements \JsonSerializable */ public string $number = ''; + /** + * Successor value. + * + * @var int + * @since 1.0.0 + */ public int $successor = 0; + /** + * Parent value. + * + * @var int|null + * @since 1.0.0 + */ public ?int $parent = null; + /** + * Status value. + * + * @var int + * @since 1.0.0 + */ public int $status = ItemStatus::ACTIVE; + /** + * Sales price value. + * + * @var FloatInt + * @since 1.0.0 + */ public FloatInt $salesPrice; + /** + * Purchase price value. + * + * @var FloatInt + * @since 1.0.0 + */ public FloatInt $purchasePrice; /** @@ -71,8 +101,20 @@ class Item implements \JsonSerializable */ private array $l11n = []; + /** + * Parts list. + * + * @var int|null + * @since 1.0.0 + */ public ?int $partslist = null; + /** + * Disposal. + * + * @var int|null + * @since 1.0.0 + */ public ?int $disposal = null; /** @@ -83,6 +125,12 @@ class Item implements \JsonSerializable */ public \DateTimeImmutable $createdAt; + /** + * Info. + * + * @var string + * @since 1.0.0 + */ public string $info = ''; /** diff --git a/Theme/Backend/attribute-type.tpl.php b/Theme/Backend/attribute-type.tpl.php index c84c0bd..c8306c7 100755 --- a/Theme/Backend/attribute-type.tpl.php +++ b/Theme/Backend/attribute-type.tpl.php @@ -12,8 +12,11 @@ */ declare(strict_types=1); +use Modules\Attribute\Models\AttributeValueType; use phpOMS\Localization\ISO639Enum; +$types = AttributeValueType::getConstants(); + $attribute = $this->getData('attribute'); $l11ns = $this->getData('l11ns'); @@ -22,17 +25,47 @@ echo $this->getData('nav')->render(); ?>
-
getHtml('Attribute'); ?>
+
getHtml('Attribute', 'Attribute', 'Backend'); ?>
- +
- - + + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+
@@ -47,7 +80,7 @@ echo $this->getData('nav')->render(); ?> getHtml('Language', '0', '0'); ?> - getHtml('Title'); ?> + getHtml('Title', 'Attribute', 'Backend'); ?> $value) : ++$c; ?> diff --git a/Theme/Backend/item-profile.tpl.php b/Theme/Backend/item-profile.tpl.php index dae49b5..01b1f7e 100755 --- a/Theme/Backend/item-profile.tpl.php +++ b/Theme/Backend/item-profile.tpl.php @@ -14,6 +14,7 @@ declare(strict_types=1); use Modules\Media\Models\NullMedia; use phpOMS\Localization\ISO639Enum; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Localization\Money; use phpOMS\Localization\NullLocalization; use phpOMS\Message\Http\HttpHeader; @@ -57,9 +58,10 @@ echo $this->getData('nav')->render();
  • -
  • -
  • -
  • +
  • +
  • +
  • +
  • @@ -82,18 +84,18 @@ echo $this->getData('nav')->render();
    - + +
    -
    - <?= $this->printHtml($image->name); ?>printHtml($itemImage->name); ?>" width="100%" loading="lazy" class="item-image" + src="id === 0 ? 'Web/Backend/img/logo_grey.png' - : UriFactory::build($image->getPath()); ?>"> + : UriFactory::build($itemImage->getPath()); ?>">
    @@ -144,15 +146,15 @@ echo $this->getData('nav')->render();
    getHtml('SalesPrice'); ?>: - getCurrency($item->salesPrice); ?> + getCurrency($item->salesPrice, format: 'medium'); ?>
    getHtml('PurchasePrice'); ?>: getCurrency($item->purchasePrice); ?>
    getHtml('Margin'); ?>: - getNumeric( $item->salesPrice->getInt() === 0 ? 0 - : ($item->salesPrice->getInt() - $item->purchasePrice->getInt()) / $item->salesPrice->getInt() * 100, 2 - ); ?> % + : ($item->salesPrice->getInt() - $item->purchasePrice->getInt()) / $item->salesPrice->getInt() * 100 + , 'short'); ?> %
    getHtml('AvgPrice'); ?>: getCurrency($this->getData('avg')); ?>
    @@ -164,7 +166,10 @@ echo $this->getData('nav')->render();
    -
    getHtml('Notes'); ?>
    +
    + getHtml('Notes'); ?> +
    @@ -186,7 +191,10 @@ echo $this->getData('nav')->render();
    -
    getHtml('Files'); ?>
    +
    + getHtml('Files'); ?> +
    @@ -242,6 +250,7 @@ echo $this->getData('nav')->render();
    +
    getHtml('TopCustomers'); ?>
    @@ -265,7 +274,9 @@ echo $this->getData('nav')->render();
    + +
    getHtml('Sales'); ?>
    @@ -295,7 +306,7 @@ echo $this->getData('nav')->render(); ?> ], - "yAxisID": "axis-2", + "yAxisID": "axis2", "fill": false, "borderColor": "rgb(255, 99, 132)", "backgroundColor": "rgb(255, 99, 132)" @@ -312,47 +323,52 @@ echo $this->getData('nav')->render(); ?> ], - "yAxisID": "axis-1", + "yAxisID": "axis1", "backgroundColor": "rgb(54, 162, 235)" } ] }, "options": { + "responsive": true, "scales": { - "yAxes": [ - { - "id": "axis-1", - "display": true, - "position": "left" - }, - { - "id": "axis-2", - "display": true, - "position": "right", - "scaleLabel": { - "display": true, - "labelString": "getHtml('Margin'); ?> %" - }, - "gridLines": { - "display": false - }, - "beginAtZero": true, - "ticks": { - "min": 0, - "max": 100, - "stepSize": 10 - } + "axis1": { + "id": "axis1", + "display": true, + "position": "left", + "suggestedMin": 0, + "ticks": { + "stepSize": 1000 } - ] + }, + "axis2": { + "id": "axis2", + "display": true, + "position": "right", + "suggestedMin": 0, + "max": 100, + "title": { + "display": true, + "text": "getHtml('Margin'); ?> %" + }, + "grid": { + "display": false + }, + "beginAtZero": true, + "ticks": { + "stepSize": 10 + } + } } } }'>
    +
    +
    Regions
    @@ -386,7 +402,9 @@ echo $this->getData('nav')->render();
    + +
    getHtml('Countries'); ?>
    @@ -409,13 +427,30 @@ echo $this->getData('nav')->render(); ?> ], + "yAxisID": "axis1", "backgroundColor": "rgb(54, 162, 235)" }] + }, + "options": { + "responsive": true, + "scales": { + "axis1": { + "id": "axis1", + "display": true, + "position": "left", + "suggestedMin": 0, + "ticks": { + "stepSize": 1000 + } + } + } } }'>
    + + @@ -425,13 +460,21 @@ echo $this->getData('nav')->render();
    -
    +
    getHtml('Localization'); ?>
    +
    + + +
    + - + $language) : $code = ISO639x1Enum::getByName($code); ?>
    @@ -462,25 +509,54 @@ echo $this->getData('nav')->render();
    getHtml('Localizations'); ?>
    - +
    - + + + + + + + + getData('l11nValues'); - foreach ($itemL11n as $value) : ++$c; - $url = UriFactory::build('{/base}/admin/group/settings?{?}&id=' . $value->id); ?> - - + @@ -504,8 +580,8 @@ echo $this->getData('nav')->render();
    getHtml('Attribute'); ?>
    - - + +
    - getHtml('ID', '0', '0'); ?> + getHtml('ID', '0', '0'); ?> getHtml('Name'); ?> getHtml('Language'); ?> getHtml('Localization'); ?>
    + + + + + + + +
    - id; ?> - printHtml($value->type->title); ?> - printHtml($value->getLanguage()); ?> - printHtml($value->content); ?> + foreach ($itemL11n as $value) : ++$c; ?> +
    + + type->isRequired) : ?> + + + + + + + + id; ?> + printHtml($value->type->title); ?> + printHtml($value->getLanguage()); ?> + printHtml(\substr($value->content, 0, 100))); ?>