Get url to continue cart session #1032
-
It would be incredibly useful to be able to generate a link from a particular cart in order to resume the session with that shopping cart. This link, for example, could be used to easily retrieve an abandonent cart. One click and the customer has their old cart back and can continue with the checkout. I am not sure if this is even possible, and maybe already possible somehow? Otherwise a nice feature request :D |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Simple Commerce doesn't have anything built-in for this. However, you could achieve this with a custom route. Assuming you're using the cookie cart driver, you could do something like this: // routes/web.php
use DuncanMcClean\SimpleCommerce\Facades\Order;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Route;
use Statamic\Facades\Blink;
use Statamic\Facades\Site;
Route::get('/back-to-cart/{orderId}', function (Request $request, $orderId) {
$order = Order::find($orderId);
if (! $order) {
return redirect('/');
}
$key = config('simple-commerce.cart.key', 'simple-commerce-cart');
$site = $this->guessSiteFromRequest();
if (Site::hasMultiple() && ! config('simple-commerce.cart.single_cart')) {
$key = $key.'-'.$site->handle();
}
Cookie::queue($key, $order->id);
Blink::put($key, $order->id);
return redirect('/cart');
}); Then, customers would be able to resume their cart by going to |
Beta Was this translation helpful? Give feedback.
-
Thanks for this code example, works great! The method Is it also possible to redirect the customer to the /cart on the same site as the order was originally created? For example the order is created on example.de, and the route example.com/back-to-cart/1234 will redirect to example.de/cart instead of example.com/cart. |
Beta Was this translation helpful? Give feedback.
Simple Commerce doesn't have anything built-in for this. However, you could achieve this with a custom route.
Assuming you're using the cookie cart driver, you could do something like this: