how pricee
, size_name
table product_options
?
product_options table
-id -product_id -pricee -size_name
controller :
function addtocart() { $product_id = input::get('product_id'); $quantity = 1; $product = product::find($product_id); if ($product) { $item = new cart($product_id, $quantity); session::push('cart', serialize($item)); return response::json(1); } return response::json(0); } function mycart() { $cart_items = []; $session_items; if (session::has('cart') && !empty(session::get('cart'))) { $session_items = session::get('cart'); foreach($session_items $key => $item) { $unserialized_item = unserialize($item); $product = product::find($unserialized_item - > productid); $cart_item = new stdclass; $cart_item - > cart_id = $key; $cart_item - > productid = $product - > id; $cart_item - > seller_id = $product - > seller_id; $cart_item - > category_id = $product - > category_id; $cart_item - > product_name = $product - > product_name; $cart_item - > description = $product - > description; $cart_item - > price = $product - > price; $cart_item - > image = $product - > image; $cart_item - > quantity = $unserialized_item - > quantity; $cart_item - > total = ($cart_item - > price * $cart_item - > quantity); $counter = 0; $found = false; $index = null; foreach($cart_items $it) { if ($it - > productid == $product - > id) { $index = $counter; $found = true; } $counter++; } if ($found) { $cart_items[$index] - > quantity = $cart_items[$index] - > quantity + $cart_item - > quantity; $cart_items[$index] - > total = ($cart_items[$index] - > quantity * $cart_item - > price); } else { $cart_items[] = $cart_item; } } if (request::ajax()) return $cart_items; else return view::make('cart', ['cart_items' => $cart_items]); } if (request::ajax()) return $cart_items; else return view::make('cart', ['cart_items' => $cart_items]); } }
home :
cartlist(); function cartlist() { $.get("{{ url::route('mycart') }}").done(function(data) { $(".dropdown-cartlist").html(""); if (data.length == 0) { $(".dropdown-cartlist").html("<li><span class='item'><h4>no items on cart.</h4></span></li>"); } else { (var = 0; < data.length; i++) { var cart_items = "<li>" + "<span class='item'>" + "<span class='item-left'>" + "<img width='50px' height='50px' src='{{ url::asset('assets/images/uploads/') }}/" + data[i].image + "' alt='' />" + "<span class='item-info'>" + "<span>" + data[i].product_name + " x " + data[i].quantity + "($" + data[i].pricee + ")</span>" + "<span>$" + data[i].total + "</span>" + "</span>" + "</span>" + "<span class='item-right'>" + "<button data-id='" + data[i].cart_id + "' class='removeproduct btn btn-xs btn-danger pull-right'>x</button>" + "</span>" + "</span>" + "</li>"; $(".dropdown-cartlist").append(cart_items); }; } }); }
Comments
Post a Comment