App\Http\Controllers\OrdersController::removeFromOrder PHP Method

removeFromOrder() public method

Removes the selected item from the cart.
public removeFromOrder ( string $orderName, integer $productId, $idOrder = '' ) : Redirects
$orderName string type or order ('cart','later',etc)
$productId integer Product id to be removed from the order
return Redirects back to de cart
    public function removeFromOrder($orderName, $productId, $idOrder = '')
    {
        $product = Product::findOrFail($productId);
        $user = \Auth::user();
        if (!$user) {
            $cart_content = Session::get('user.cart_content');
            unset($cart_content[$productId]);
            Session::put('user.cart_content', $cart_content);
            return redirect()->route('orders.show_cart');
        }
        $basicCart = Order::ofType($orderName)->where('user_id', $user->id);
        if ($idOrder != '') {
            $basicCart = $basicCart->where('id', $idOrder);
        }
        $basicCart = $basicCart->first();
        if (!$basicCart) {
            Session::push('message', trans('store.productNotFound'));
        } else {
            if ($product->type != 'item') {
                switch ($product->type) {
                    case 'key':
                        $idVirtual = VirtualProduct::where('product_id', $product->id)->where('status', 'cancelled')->first();
                        VirtualProductOrder::where('virtual_product_id', $idVirtual->id)->where('order_id', $basicCart->id)->delete();
                        break;
                }
            }
            $orderDetail = OrderDetail::where('order_id', $basicCart->id)->where('product_id', $product->id)->first();
            $orderDetail->delete();
            Session::push('message', trans('store.productDeleted'));
        }
        if ($orderName == 'wishlist' || $orderName == 'later') {
            return redirect()->route('orders.show_wish_list');
        } else {
            return redirect()->route('orders.show_cart');
        }
    }