Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

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!
Ashley23
Posts: 4
Joined: 10 Nov 2023, 08:08

Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by Ashley23 » 21 Dec 2023, 18:53

Laravel framework version: 10.8.0
Aimeos Laravel version: 2023.04.*
PHP Version: 8.1.18 (cli)
Environment: Linux (Ubuntu)

Every product contains a minimum of 6 different attribute values, and overall there are over 300 attributes and each has min 5 value. But in the catalog page shows up just 9 attributes with their values. Then I've searched a bit in the codes and found out that the js automatically gives disabled class when none of the products contain that attribute. And thought that's the problem, but that wasn't the problem. I've dumped all the attributes that is got, they were 12 ((.

Eventually, I've tried to index them. And got this error:

Code: Select all

TypeError: Aimeos\Admin\JsonAdm\Base::saveEntry(): Argument #2 ($entry) must be of type stdClass, string given, called in /var/www/project/vendor/aimeos/ai-admin-jsonadm/src/Admin/JsonAdm/Base.php on line 286 in file /var/www/project/vendor/aimeos/ai-admin-jsonadm/src/Admin/JsonAdm/Base.php on line 301
And this is my '/ai-admin-jsonadm/src/Admin/JsonAdm/Base.php' file:

Code: Select all


	/**
	 * Creates of updates several items at once
	 *
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items
	 * @param \stdClass $request Object with request body data
	 * @return \Aimeos\Map List of items
	 */
	protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request ) : \Aimeos\Map
	{
		$data = [];

		if( isset( $request->data ) )
		{
			foreach( (array) $request->data as $entry ) {
				$data[] = $this->saveEntry( $manager, $entry );  // this is the line 286
			}
		}

		return map( $data );
	}


	/**
	 * Saves and returns the new or updated item
	 *
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items
	 * @param \stdClass $entry Object including "id" and "attributes" elements
	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
	 */
	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry ) : \Aimeos\MShop\Common\Item\Iface // this is the line 301
	{
		if( isset( $entry->id ) ) {
			$item = $manager->get( $entry->id );
		} else {
			$item = $manager->create();
		}

		if( isset( $entry->attributes ) && ( $attr = (array) $entry->attributes ) )
		{
			if( $item instanceof \Aimeos\MShop\Common\Item\Config\Iface )
			{
				$key = str_replace( '/', '.', $this->path ) . '.config';
				$attr[$key] = (array) ( $attr[$key] ?? [] );
			}

			$item = $item->fromArray( $attr, true );
		}

		$item = $manager->save( $item );

		if( isset( $entry->relationships ) ) {
			$this->saveRelationships( $manager, $item, $entry->relationships );
		}

		return $manager->get( $item->getId() );
	}

Last edited by Ashley23 on 22 Dec 2023, 12:03, edited 1 time in total.

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

Re: Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by aimeos » 22 Dec 2023, 09:42

Seems like you've sent a request with wrong data in the body.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ashley23
Posts: 4
Joined: 10 Nov 2023, 08:08

Re: Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by Ashley23 » 22 Dec 2023, 12:02

aimeos wrote: 22 Dec 2023, 09:42 Seems like you've sent a request with wrong data in the body.
Thanks for the response !

In the request body, there was:

Code: Select all

{"data": ["172"]}
And exact data works with "admin/default/jsonadm/index"

And even I've tried with this:

Code: Select all

{"data": [172]}
And when I try without square brackets, it gives this error:
Error: Attempt to assign property "id" on string in file ...aimeos/ai-admin-jsonadm/src/Admin/JsonAdm/Standard.php on line 653

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

Re: Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by aimeos » 22 Dec 2023, 13:36

Do you use an endpoint different from admin/default/jsonadm/index for your request?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Ashley23
Posts: 4
Joined: 10 Nov 2023, 08:08

Re: Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by Ashley23 » 22 Dec 2023, 16:30

aimeos wrote: 22 Dec 2023, 13:36 Do you use an endpoint different from admin/default/jsonadm/index for your request?
I've tried with this request (I think it's for indexing attributes?) which gives error:

Code: Select all

/admin/default/jsonadm/index/attribute?_token=.....
But it's working properly when I try with this request (which I believe it's for products):

Code: Select all

/admin/default/jsonadm/index?_token=.....

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

Re: Doesn't indexing the attribute or category models through this url: admin/default/jsonadm/index/catalog

Post by aimeos » 23 Dec 2023, 18:07

There is no specialized endpoint for indexing attributes and thus, the fallback to the standard endpoint is used. If you want to index a product attribute, you have to pass the product instead to the /index endpoint.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply