How to automatically save baskets in 2022.10
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!
How to automatically save baskets in 2022.10
Hi,
we are using Aimeos as a B2B shop, where all customers have to register / login first. (So there are no anonymous baskets)
We are looking for a solution to automatically saves customer baskets during their visits:
Is it possible to extend this function so that baskets are automatically stored? eg. using the customer-Id as basket name?
How would you suggest an implementation?
Thank you!
we are using Aimeos as a B2B shop, where all customers have to register / login first. (So there are no anonymous baskets)
We are looking for a solution to automatically saves customer baskets during their visits:
- customer login
- customer adds items to basket
- customer logs out and (some days later) logs in again
- previously added items (from step 2) should still be present in the basket
Is it possible to extend this function so that baskets are automatically stored? eg. using the customer-Id as basket name?
How would you suggest an implementation?
Thank you!
Re: How to automatically save baskets in 2022.10
There are two solutions for that:
1.) The easiest one is to extend the PHP session lifetime to 30, 90 or more days but this only works if the customer doesn't log out
2.) You can create a Basket Plugin that stores the basket to the mshop_order_basket table whenever the basket is updated using it's manager and repopulate the basket at login:
- https://aimeos.org/docs/latest/provider ... t-plugins/
- https://github.com/aimeos/aimeos/blob/m ... roller.php
1.) The easiest one is to extend the PHP session lifetime to 30, 90 or more days but this only works if the customer doesn't log out
2.) You can create a Basket Plugin that stores the basket to the mshop_order_basket table whenever the basket is updated using it's manager and repopulate the basket at login:
- https://aimeos.org/docs/latest/provider ... t-plugins/
- https://github.com/aimeos/aimeos/blob/m ... roller.php
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: How to automatically save baskets in 2022.10
Thank you. I made a few tests and it seems as table mshop_order_basket gets already update with every basket change - either a new entry added or the existing one update (already without a Basket Plugin)
But I'm still wondering how to repopulate the stored baskets from mshop_order_basket back to the frontend basket? I searched for an already extising implementation or code example (eg. in ai-client-html/src/Client/Html/Account/Basket or
History) but without any success.
Could you provide some guidance or reference code please?
But I'm still wondering how to repopulate the stored baskets from mshop_order_basket back to the frontend basket? I searched for an already extising implementation or code example (eg. in ai-client-html/src/Client/Html/Account/Basket or
History) but without any success.
Could you provide some guidance or reference code please?
Re: How to automatically save baskets in 2022.10
We haven't done that before too but the posted link should be the right place to load the basket as soon as the customer logs in: https://github.com/aimeos/aimeos/blob/m ... roller.php
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: How to automatically save baskets in 2022.10
I'm using Laravel Fortify, I don't have AuthenticatedSessionController.php in /app/Http/Controllers/Auth (only in /vendor/laravel/fortify/src/Http/Controllers)
After some research I found Laravel Fortify LoginResponse and I'm now trying to repopulate the basket there
https://laravel.com/docs/9.x/fortify#cu ... -redirects
by using this code:
After some research I found Laravel Fortify LoginResponse and I'm now trying to repopulate the basket there
https://laravel.com/docs/9.x/fortify#cu ... -redirects
by using this code:
Code: Select all
<?php
namespace App\Http\Responses;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
class LoginResponse
implements LoginResponseContract
{
public function toResponse($request)
{
$context = $this->context();
$manager = \Aimeos\MShop::create( $context, 'order/basket' );
$filter = $manager->filter()
->add( 'order.basket.customerid', '==', $context->user())
->add( 'order.basket.name', '==', 'default' );;
$basketItems = $manager->search( $filter );
$domain = ['attribute', 'catalog', 'media', 'price', 'product', 'text', 'locale/site'];
$basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' );
$productCntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domain );
foreach( $basketItems as $basketItem ) {
if( $basket = $basketItem->getItem() ) {
foreach( $basket->getProducts() as $pos => $orderProduct ){
$basketCntl->addProduct( $productCntl->get( $orderProduct->getProductId()),
$orderProduct->getQuantity()
);
}
}
}
return redirect()->intended($dashboard);
}
}
- How can I get $view, $context etc. and return the updated view?
- Are there any other methods or better solutions to load products from order/basket the frontend basket?
Re: How to automatically save baskets in 2022.10
Read here how to get the Aimeos context which also contains the view:
https://aimeos.org/docs/latest/laravel/ ... os-objects
Up to now it's not possible to inject your own basket into the basket controller, which then would create a new entry in the mshop_order_basket table. We could add a inject() method in the next version if you create a pull request in the Github repo.
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