Skip to content

Commit 2bbda0a

Browse files
Fixed entity saving use case flow
1 parent f429534 commit 2bbda0a

File tree

7 files changed

+15
-3
lines changed

7 files changed

+15
-3
lines changed

resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS}
6666
try {
6767
/** @var ${ENTITY_DTO}|${DATA_OBJECT} $entityModel */
6868
$entityModel = $this->entityDataFactory->create();
69-
$entityModel->addData($params);
69+
$entityModel->addData($params['general']);
7070
$this->saveCommand->execute($entityModel);
7171
$this->messageManager->addSuccessMessage(
7272
__('The ${ENTITY_NAME} data was saved successfully')

resources/fileTemplates/internal/Magento Resource Model Class.php.ft

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen
2222
protected function _construct()
2323
{
2424
$this->_init('${DB_NAME}', '${ENTITY_ID_COLUMN}');
25+
$this->_useIsObjectNew = true;
2526
}
2627
}

resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class ${CLASS_NAME}
5757
/** @var ${MODEL} $model */
5858
$model = $this->modelFactory->create();
5959
$model->addData($${DTO_PROPERTY}->getData());
60+
$model->setHasDataChanges(true);
61+
62+
if (!$model->getId()) {
63+
$model->isObjectNew(true);
64+
}
6065
$this->resource->save($model);
6166
} catch (${EXCEPTION} $exception) {
6267
$this->logger->error(

testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ class TestResourceModel extends AbstractDb
1717
protected function _construct()
1818
{
1919
$this->_init('my_table', 'entity_id');
20+
$this->_useIsObjectNew = true;
2021
}
2122
}

testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function execute()
7373
try {
7474
/** @var CompanyInterface|DataObject $entityModel */
7575
$entityModel = $this->entityDataFactory->create();
76-
$entityModel->addData($params);
76+
$entityModel->addData($params['general']);
7777
$this->saveCommand->execute($entityModel);
7878
$this->messageManager->addSuccessMessage(
7979
__('The Company data was saved successfully')

testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function execute()
7373
try {
7474
/** @var CompanyModel|DataObject $entityModel */
7575
$entityModel = $this->entityDataFactory->create();
76-
$entityModel->addData($params);
76+
$entityModel->addData($params['general']);
7777
$this->saveCommand->execute($entityModel);
7878
$this->messageManager->addSuccessMessage(
7979
__('The Company data was saved successfully')

testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public function execute(BookData $book): int
6161
/** @var BookModel $model */
6262
$model = $this->modelFactory->create();
6363
$model->addData($book->getData());
64+
$model->setHasDataChanges(true);
65+
66+
if (!$model->getId()) {
67+
$model->isObjectNew(true);
68+
}
6469
$this->resource->save($model);
6570
} catch (Exception $exception) {
6671
$this->logger->error(

0 commit comments

Comments
 (0)