Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('.add-to-cart').on('click', function () {
- quanlity = $(this).siblings().find('#qty').val();
- if (quanlity == undefined)
- quanlity = 1;
- productid = $(this).data('productid');
- $.ajax({
- url: '/cart/AddToCart/?productId=' + productid + '&quantity=' + quanlity,
- dataType: 'json',
- success: function (data) {
- GetFromCart();
- if (data.Code == 1)
- toastr.success(data.Msg + "<br/>Số lượng: " + data.Data.Quantity, { timeOut: 10, preventDuplicates: true });
- if (data.Error)
- toastr.error(data.Msg, { timeOut: 10, preventDuplicates: true });
- }
- });
- return false;
- });
- var AddToCart = function (item) {
- itemhtml = $('<li id="product-' + item.item.id + '"><a href="' + item.item.url + '"><img src="' + item.item.imageUrl + '" alt=""></a><button data-productid="' + item.item.id + '" type="button" class="close">×</button><div class="overflow-h"><span>' + item.item.name + '</span><small>' + item.quantity + ' x <span class="digits" style="display:inline">' + item.item.displayPrice + '</span></small></div></li>');
- itemhtml.find('.digits').digits();
- itemhtml.find('.close').on('click', function () {
- RemoveFromCart($(this).data('productid'));
- });
- $('.shop-badge li.subtotal').before(itemhtml);
- }
- var RemoveFromCart = function (id) {
- $.ajax({
- url: '/cart/RemoveFromCart/?productId=' + id,
- dataType: 'json',
- success: function (data) {
- $('.shop-badge div.mCSB_container li#product-' + id).remove();
- $('.shopping-cart table tr#cproduct-' + id).remove();
- }
- });
- };
- var GetFromCart = function () {
- $.ajax({
- url: '@Url.Action("GetFromCart", "Cart")',
- dataType: 'json',
- success: function (data) {
- $('.shop-badge div.mCSB_container li:not([class="subtotal"]').remove();
- for (i = 0; i < data.length; i++)
- AddToCart(data[i]);
- }
- });
- }
- $(document).ready(function () {
- GetFromCart();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement