"setLocale.after" event not working for my plugin
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- РоманАндрейчук
- Posts: 18
- Joined: 13 Jan 2022, 15:08
"setLocale.after" event not working for my plugin
Aimeos 2021.x, php7.4
Hello. I'm create new plugin for basket. It changes the amount according to the client's logic.
The plugin fires in all necessary events. But if I change the language or currency, the cart amount is not recalculated. Can you help me figure it out?
Hello. I'm create new plugin for basket. It changes the amount according to the client's logic.
Code: Select all
class TenthFree
extends \Aimeos\MShop\Plugin\Provider\Factory\Base
implements \Aimeos\MShop\Plugin\Provider\Iface, \Aimeos\MShop\Plugin\Provider\Factory\Iface
{
public function register( \Aimeos\MW\Observer\Publisher\Iface $p ) : \Aimeos\MW\Observer\Listener\Iface
{
$plugin = $this->getObject();
$p->attach( $plugin, 'addProduct.after' );
$p->attach( $plugin, 'deleteProduct.after' );
$p->attach( $plugin, 'setProducts.after' );
$p->attach( $plugin, 'addCoupon.after' );
$p->attach( $plugin, 'deleteCoupon.after' );
$p->attach( $plugin, 'setOrder.before' );
$p->attach( $plugin, 'setLocale.before' );
$p->attach( $plugin, 'setLocale.after' );
return $this;
}
......
}
Re: "setLocale.after" event not working for my plugin
If you change the language or currency, the basket is migrated in the basket frontend controller:
https://github.com/aimeos/ai-controller ... #L124-L162
In that case, setLocale() of the basket is never used because the basket object is created with a new locale object passed to its constructor directly:
https://github.com/aimeos/aimeos-core/b ... hp#L42-L49
Not sure if we can simply call Basket::setLocale() at the end of the migration:
https://github.com/aimeos/ai-controller ... #L154-L156
Can you test if that has negative consequences elsewhere?
https://github.com/aimeos/ai-controller ... #L124-L162
In that case, setLocale() of the basket is never used because the basket object is created with a new locale object passed to its constructor directly:
https://github.com/aimeos/aimeos-core/b ... hp#L42-L49
Not sure if we can simply call Basket::setLocale() at the end of the migration:
https://github.com/aimeos/ai-controller ... #L154-L156
Can you test if that has negative consequences elsewhere?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- РоманАндрейчук
- Posts: 18
- Joined: 13 Jan 2022, 15:08
Re: "setLocale.after" event not working for my plugin
Thank you! This method works. Can you add this code to your repository?
Found some more problems:
1)Sometimes a variable is not stored in the session. Because of this, there is an unnecessary initialization of the basket object.
https://github.com/aimeos/ai-controller ... e.php#L161
2) https://github.com/aimeos/ai-controller ... d.php#L514
This method does not check for the uniqueness of the added service. And many same delivery or payment services can be added to the basket object.
Found some more problems:
1)Sometimes a variable is not stored in the session. Because of this, there is an unnecessary initialization of the basket object.
https://github.com/aimeos/ai-controller ... e.php#L161
2) https://github.com/aimeos/ai-controller ... d.php#L514
This method does not check for the uniqueness of the added service. And many same delivery or payment services can be added to the basket object.
Re: "setLocale.after" event not working for my plugin
Thanks, the setLocale method is no called in dev-master and 2022.07.x-dev versions.РоманАндрейчук wrote: ↑24 Sep 2022, 16:24 Thank you! This method works. Can you add this code to your repository?
Can you find out why the variable isn't stored?РоманАндрейчук wrote: ↑24 Sep 2022, 16:24 1)Sometimes a variable is not stored in the session. Because of this, there is an unnecessary initialization of the basket object.
https://github.com/aimeos/ai-controller ... e.php#L161
That's true. We've added checks in addService() and copyServices() now to avoid duplicate services. The new code is also available in dev-master and 2022.07.x-dev.РоманАндрейчук wrote: ↑24 Sep 2022, 16:24 2) https://github.com/aimeos/ai-controller ... d.php#L514
This method does not check for the uniqueness of the added service. And many same delivery or payment services can be added to the basket object.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- РоманАндрейчук
- Posts: 18
- Joined: 13 Jan 2022, 15:08
Re: "setLocale.after" event not working for my plugin
Is version 2021.x no longer supported?
Re: "setLocale.after" event not working for my plugin
We are hesitating a bit porting back bigger changes to LTS versions.
But we've made the changes also available in aimeos/ai-controller-frontend:2021.10.x-dev now.
But we've made the changes also available in aimeos/ai-controller-frontend:2021.10.x-dev now.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star