No value for key "item" found

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 213
Joined: 26 Aug 2022, 12:17

No value for key "item" found

Post by kdim95 » 26 Aug 2022, 12:29

Laravel framework version: 9.26.1
Aimeos Laravel version: * 2022.07.2
PHP Version: 8.1.9
Environment: Linux

Following the example here, I created a decorator named "Mydecorator" inside
<MY PLUGIN>/src/Admin/JQAdm/Common/Decorator/Mydecorator.php
https://aimeos.org/docs/latest/admin/jq ... nd-panels/

I overrode the save() method like in the example:

Code: Select all

public function save() : ?string
{
	$item = $this->view()->item;
	// notifiy the 3rd party system
	return $this->getClient()->save();
}
I configured <MY PLUGIN>/config/admin.php like this:

Code: Select all

return [
	'jqadm' => [
		'product' => [
			'decorators' => [
				'global' => [ 'Mydecorator' ]
			]
		]
	],
	'jsonadm' => [
	],
];
When attempting to test saving the product, I get the following error:
"No value for key 'item' found"

The error occurs on this line:
$item = $this->view()->item;

I want to implement an audit log for tracking who changed what in every module.
I have tried the package "owen-it/laravel-auditing", but it does not work, as Aimeos does not use Eloquent models.

Help would be appreciated, thank you.

User avatar
aimeos
Administrator
Posts: 7951
Joined: 01 Jan 1970, 00:00

Re: No value for key "item" found

Post by aimeos » 26 Aug 2022, 13:38

This is a mistake in the docs. Can you please try this instead:

Code: Select all

    public function save() : ?string
    {
        $result = $this->getClient()->save();
        $item = $this->view()->item; // assigned by inner objects
        // notify the 3rd party system
        return $result;
    }
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 213
Joined: 26 Aug 2022, 12:17

Re: No value for key "item" found

Post by kdim95 » 26 Aug 2022, 14:00

Thank you, this removes the error, but there is another problem.

Now that this line is above everything, I can't reach the state of the item before the change.
$result = $this->getClient()->save();

After save() is called, the item is already changed, right?
How can I get the attributes of the item before the actual change?

User avatar
aimeos
Administrator
Posts: 7951
Joined: 01 Jan 1970, 00:00

Re: No value for key "item" found

Post by aimeos » 26 Aug 2022, 14:09

You can only get the POST parameters using "$this->view()->param()" or "$this->view()->param( '<name>' )" but not set them and the item is assigned by the inner object so the options are limited for your use case.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 213
Joined: 26 Aug 2022, 12:17

Re: No value for key "item" found

Post by kdim95 » 26 Aug 2022, 14:18

Thank you, the best thing I can think of is:
1) Getting the product ID from the $_POST parameters
2) Querying the product to get the original values
3) While we are at it with the $_POST parameters, get the new values as well
4) Save the previous and changed values as JSONs in the database
4) Execute $this->getClient()->save();

I don't know how practical of a solution this is, I thought I could find a cleaner solution in the docs, thank you.

User avatar
aimeos
Administrator
Posts: 7951
Joined: 01 Jan 1970, 00:00

Re: No value for key "item" found

Post by aimeos » 26 Aug 2022, 14:25

The Changelog manager decorator in the aimeos-core package is much better suited for that:
https://github.com/aimeos/aimeos-core/b ... ngelog.php

You can create your own decorator that does something similar.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply