Change basket data in basket plugin
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Change basket data in basket plugin
Hi Aimeos-Team,
we change some custom data at the "setOrder.before"-event to the basket. That works fine so far, but for example we have paypal as the payment provider and we cancel the payment (backlink to our website ) the order is also canceled in aimeos - new order-(base)-id etc. is created if we checkout again.
But now the custom data from the previous checkout try is missing. It seems the data is not persited in the "session basket", it works only for the "save-the-order-to-database"-way. How can I change/add the custom data in this event to the "session basket" also?
Thank you!
Ralf
we change some custom data at the "setOrder.before"-event to the basket. That works fine so far, but for example we have paypal as the payment provider and we cancel the payment (backlink to our website ) the order is also canceled in aimeos - new order-(base)-id etc. is created if we checkout again.
But now the custom data from the previous checkout try is missing. It seems the data is not persited in the "session basket", it works only for the "save-the-order-to-database"-way. How can I change/add the custom data in this event to the "session basket" also?
Code: Select all
public function update( \Aimeos\MW\Observer\Publisher\Iface $basket, $event, $value = null )
{
if ($event == 'setOrder.before') {
$external_userid = <user-has-external-user-id>
foreach($basket->getProducts() as $pos => $product) {
$product->setProjectUser($external_userid);
$basket->deleteProduct($pos);
$basket->addProduct($product);
}
}
Ralf
Re: Change basket data in basket plugin
That's true, the "setOrder.before" event is only published in the store() method of the basket frontend controller:
https://github.com/aimeos/ai-controller ... d.php#L289
Thus, the changes are not persisted into the session but only in the database.
There are two options now:
1.) Use another event like "addProduct.before/setProducts.before" to change the product when they are added
2.) Call save() of the basket controller in the HTML client to store the basket in the session too:
https://github.com/aimeos/ai-client-htm ... d.php#L211
https://github.com/aimeos/ai-controller ... d.php#L289
Thus, the changes are not persisted into the session but only in the database.
There are two options now:
1.) Use another event like "addProduct.before/setProducts.before" to change the product when they are added
2.) Call save() of the basket controller in the HTML client to store the basket in the session too:
https://github.com/aimeos/ai-client-htm ... d.php#L211
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
Re: Change basket data in basket plugin
Thank you!
I have another solution found, getting the session-basket and and set the data there:
I have another solution found, getting the session-basket and and set the data there:
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'order/base' );
$sessionBasket = $manager->getSession( 'default' );
foreach($sessionBasket->getProducts() as $pos => $product) {
$product->setProjectUser($external_userid);
$sessionBasket->deleteProduct($pos);
$sessionBasket->addProduct($product);
}