public static fromGuestToUser ( $ordersController ) |
public static function fromGuestToUser($ordersController)
{
/**
* $cart_content contains the guest shopping cart information.
*
* @var [array]
*/
$cart_content = Session::get('user.cart_content');
//dd($cart_content, Session::get('user.cart'));
foreach (Session::get('user.cart_content') as $product => $value) {
$ordersController->addToOrder('cart', $product, new Request(['quantity' => $cart_content[$product] != '' ? $cart_content[$product] : 1, 'guestToUser' => 1]));
}
Session::forget('user.cart');
Session::forget('user.cart_content');
Session::save();
}
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * * @return mixed */ public function handle($request, Closure $next, $guard = null) { /* * If there is products into the guest cart, its content is transferred * to a logged user 'cart' order. */ if (\Illuminate\Support\Facades\Session::has('user.cart_content')) { $ordersController = new OrdersController(); $ordersController->fromGuestToUser($ordersController); unset($ordersController); } return $next($request); }