lundi 11 septembre 2017

update shopping cart using ajax and laravel

Im using the package Crinsane/LaravelShoppingcart

and i want to update the cart items with ajax, im using Laravel 5.4 and Jquery. I cant update the cart with ajax.

If i use without jquery i just have to pass the id of the product like this:

/cart/add-item/{id}

this is my code:

the route: Web.php

Route::get('/cart/add-item/{id}', 'CartController@addItem')->name('cart.addItem');

the controller: CartController.php

public function addItem($id){

 $productos = DB::connection('oracle_db')->select("SELECT ID,DESCRIPTION, 
 PRICE 
 FROM inv.pwv_articulos where id = '$id'");
    foreach($products as $product){
        $products_id = $product->id;
        $products_descripcion = $product->description;
        $products_price = $product->precio;
    }
 Cart::add($products_id, $products_description , 1 , $products_price, 
 ['size'=> 'medium']);

 return back();
}

my js with Jquery:

            formData = $('#color_black').serializeArray();
            var value_color = formData[0]['value'];
            //alert(value_color);

            $.ajax({ 
                type: "GET",
                url: "cart/add-item/".value_color, 
                success: function(response){ 
                        console.log(""); 
                } 
            });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire