aimeos / aimeos-core

Aimeos PHP e-commerce framework for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org
Other
3.4k stars 118 forks source link

Bug in fromArray() method of Base class of domain item #210

Closed dheerajcodes closed 3 years ago

dheerajcodes commented 3 years ago

Bug Report (aimeos-core)

Bug Definition

fromArray() method of Aimeos\MShop\Common\Item\Base.php does not call setModified() for custom column(s) of any domain table which as a result causes domain manager to skip saving the domain item in its saveItem() method when only custom column is modified because isModified() returns false in saveItem() method of domain manager.

Bug Reproducibility

  1. Create a new aimeos-laravel project.
  2. Create a custom aimeos extension in the project.
  3. Add a custom column in any domain table (e.g. mshop_stock) by creating a schema definition file in custom extension and run php artisan aimeos:setup command.
  4. Create a decorator for the domain manager of the modified domain table (e.g. 'stock' domain manager) and add that decorator in decorators list of manager configuration.
  5. Now executing the code of following type will reproduce the bug
$context = $this->getContext();
$manager = \Aimeos\MShop::create($context, '<your-domain>');
$data = [
    '<your-domain.key1>' => '<value1>',
    '<your-domain.key2>' => '<value2>',
        ...
    '<custom-column>' => '<value>',
        ...
];
$item = $manager->get('<item-id>');
$item = $item->fromArray($data);
// Now, calling saveItem() will not save modified item
// when the only difference between old item and
// modified item is value of <custom-column>.
$manager->saveItem($item);

Solution

At line number 391 in Aimeos\MShop\Common\Item\Base.php

Change this -

$this->bdata[$key] = $value;

to this -

$this->set($key, $value);

aimeos commented 3 years ago

Thanks a lot for your report! Can you please create a PR to fix the issue?

dheerajcodes commented 3 years ago

Thanks a lot for your report! Can you please create a PR to fix the issue?

Sure

dheerajcodes commented 3 years ago

Kindly merge the pull request

aimeos commented 3 years ago

Thanks, your fix is now available in dev-master and 2020.10.x-dev, it will be part of the next 2020.10.x release.