UltimateModuleCreator / umc

Magento 2 Ultimate Module Creator
MIT License
58 stars 10 forks source link

InlineEdit not saving data #16

Closed raulsinapsis closed 4 years ago

raulsinapsis commented 5 years ago

Hi there, I am not sure exactly why, but I noticed that this piece of code was not working in generated module InlineEdit.php controller

$store = $this->storeRepository->get((int)$storeId);
$storeData = $postItems[$storeId];
$this->dataObjectHelper->populateWithArray($store, $storeData, StoreInterface::class);
$this->storeResourceModel->saveAttribute($store, array_keys($storeData));

Both $store & $storeData are fine, data is fine & StoreInterface exists & has the right methods, so it should be some problem with populateWithArray call... but I have not debugged that

Changing to

$store = $this->storeRepository->get((int)$storeId);
$storeData = $postItems[$storeId];
$store->addData($storeData);
$this->storeResourceModel->saveAttribute($store, array_keys($storeData));

Then it works

raulsinapsis commented 5 years ago

Updating... vendor/magento/framework/Api/DataObjectHelper.php

Changing...

protected function _setDataValues($dataObject, array $data, $interfaceName)
{
    $dataObjectMethods = get_class_methods(get_class($dataObject));

To this...

protected function _setDataValues($dataObject, array $data, $interfaceName)
{
    $dataObjectMethods = get_class_methods($interfaceName);

If we get the methods from $interfaceName class instead of $dataObject class then your module original code works

$this->dataObjectHelper->populateWithArray($store, $storeData, StoreInterface::class);
UltimateModuleCreator commented 4 years ago

This should be fixed in version 4.0.0