Price rules don't work when using product manager

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!
User avatar
VadimSaratov
Posts: 2
Joined: 09 May 2022, 15:27

Price rules don't work when using product manager

Post by VadimSaratov » 17 May 2022, 10:09

I am using aimeos laravel 2021.10.5 and laravel 8.42.1 I created price rules as described in the documentation https://aimeos.org/docs/2021.x/providers/rules/ and the rules work for the JSON API, when displayed in the store, etc. but when I request a product with a price using the manager, the rules do not apply to the price.

should the price rules be applied automatically when requesting through the manager, or should I apply the decorator manually in this case?

my code using manager looks like this:

Code: Select all

        $manager = MShop::create(app('aimeos.context')->get(), 'product');

        $product = $manager->get($product_id,
            [
                'attribute',
                'media',
                'price',
                'product',
                'product/property',
                'text',
                'catalog',
                'supplier',
                'stock'
            ]

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

Re: Price rules don't work when using product manager

Post by aimeos » 18 May 2022, 06:19

Price rules are only applied to the frontend, otherwise managing product prices would not be possible. Use the frontend controller instead, which applies the price rules automatically:
https://github.com/aimeos/ai-controller ... d.php#L202

An equivalent example is:

Code: Select all

\Aimeos\Controller\Frontend::create(app('aimeos.context')->get(), 'product')
	->uses( [
                'attribute',
                'media',
                'price',
                'product',
                'product/property',
                'text',
                'catalog',
                'supplier',
                'stock'
            ] )
        ->get( $product_id );
For the available methods, have alook into the interface:
https://github.com/aimeos/ai-controller ... /Iface.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
VadimSaratov
Posts: 2
Joined: 09 May 2022, 15:27

Re: Price rules don't work when using product manager

Post by VadimSaratov » 18 May 2022, 07:13

Ok, thanks

Post Reply