Batch updating products does not update the ElasticSearch index.

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: 208
Joined: 26 Aug 2022, 12:17

Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 10 Aug 2023, 15:53

Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux

How to reproduce:
1) Have ai-elastic installed and working.
2) Go to product listing in the admin and make a batch change, for example increasing the product price with 10% by typing "10" in the field.
3) The product price is not updated in the frontend when the frontend is refreshed.

Are you able to reproduce this?

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

Re: Batch updating products does not update the ElasticSearch index.

Post by aimeos » 14 Aug 2023, 10:49

We've updated the aimeos/ai-admin-jqadm:2023.07.x-dev package to use the index manager in the batch() method instead of the product manager. That should work for index-only setups too. Can you give it a try?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 14 Aug 2023, 11:44

Due to breaking changes in the newer jqadm versions (more elements converted to use vue js), I have to stick to 2023.04.*.
Otherwise it breaks templates I've already changed in the backend.
How can I fix it without updating to 2023.07 ?

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

Re: Batch updating products does not update the ElasticSearch index.

Post by aimeos » 14 Aug 2023, 11:51

Temporarily, you can replace the batch() method with these lines:
https://github.com/aimeos/ai-admin-jqad ... p#L80-L106

Keep in mind that you have to update to 2023.10 LTS nevertheless because 2023.0x versions won't be supported any more if the LTS version is available.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 14 Aug 2023, 12:16

It's working when I made the changes you suggested.
Can I make a pull request that adds this change to 2023.04.*?

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

Re: Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 14 Aug 2023, 12:24

Update: An error is showing

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '<ID>-product/property-default--1.' for key 'unq_msproli_pid_dm_ty_rid_sid': INSERT INTO "mshop_product_list" ( "parentid", "key", "type", "domain", "refid", "start", "end", "config", "pos", "status", "mtime", "editor", "siteid", "ctime" ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ["139525","product\/property|default|","default","product\/property","",null,null,"[]",0,1,"2023-08-14 15:21:47","<EMAIL>","1.","2023-08-14 15:21:47"]

The error occurs in the newly added batch() method on this row:

Code: Select all

$manager->save( $items );

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

Re: Batch updating products does not update the ElasticSearch index.

Post by aimeos » 14 Aug 2023, 12:47

Did you customize the batch section of the product list template?
Properties are not part of the batch update by default and in your setup, they are tried to be saved as list entries.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 14 Aug 2023, 13:23

I think that the only change to the batches I've done is here:

Code: Select all

Aimeos\Admin\JQAdm\Product\Price\Decorator
This changes it so that the percent discount is set based on the current price.

Code: Select all

   /**
	 * Batch update of a resource
	 *
	 * @return string|null Output to display
	 */
	public function batch() : ?string
    {
        $view = $this->view();
		$data = $view->param( 'price', [] );

		foreach( $view->get( 'items', [] ) as $item )
		{
			foreach( $item->getRefItems( 'price' ) as $price )
			{
				$temp = $data;
                $price->fromArray( $temp, true );

				if( isset( $data['valuepercent'] ) ) {
					$price->setValue( $price->getValue() + $price->getValue() * $data['valuepercent'] / 100 );
				}

                if( isset( $data['rebatepercent'] ) ) {
                    $current_price_value = (float) $price->getValue(); // Get the current price value
                    $original_price_value = (float) $current_price_value + $price->getRebate(); // Calculate the original price value
                    $rebatepercent = abs( (float) $data['rebatepercent'] ); // Get the new rebate percent
                    $new_rebate = $original_price_value * $rebatepercent / 100; // Calculate the new rebate value
                    $new_price = $original_price_value - $new_rebate; // Calculate the new price value

                    if( $new_price < 0 ) {
                        throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Price value "%s" with a discount of "%s" percent is invalid', $new_price, $rebatepercent ) );
                    }

                    $price->setValue( $new_price ); // Set the new price value
                    $price->setRebate( $new_rebate ); // Set the new rebate value
                }

                if( isset( $data['costspercent'] ) ) {
					$price->setCosts( $price->getCosts() + $price->getCosts() * $data['costspercent'] / 100 );
				}
			}
		}

		return null;
    }

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

Re: Batch updating products does not update the ElasticSearch index.

Post by aimeos » 15 Aug 2023, 06:32

But we can't reproduce it in a test setup
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Batch updating products does not update the ElasticSearch index.

Post by kdim95 » 15 Aug 2023, 12:59

I will keep investigating why it's happening, thank you

Post Reply