Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- update();
- $(".quant").change(function() {
- update();
- });
- function update() {
- var id = $('.quant').attr('data-id');
- var sum = 0.0;
- var quantity;
- $('#myTable > tbody > tr').each(function () {
- quantity = $(this).find('.quant').val();
- var price = parseFloat($(this).find('.price').attr('data-price').replace(',', '.'));
- var amount = (quantity * price);
- sum += amount;
- $(this).find('.amount').text('' + amount + ' грн');
- });
- $('.total').text(sum + ' грн');
- $.get(
- '/Cart/AddTocart',
- {
- id: id,
- returnUrl: '',
- quantity: quantity
- }
- );
- }
- });
- var id = $(this).attr('data-id');
- var quantity;
- $('#myTable > tbody > tr').each(function () {
- quantity = $(this).find('.quant').val();
- ...
- }
- <thead>
- <tr>
- <th class="text-center">Товар</th>
- <th class="text-center">К-сть</th>
- <th>Назва Товару</th>
- <th class="text-right">Ціна</th>
- <th class="text-right">Загальна ціна</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var line in Model.Cart.Lines)
- {
- IEnumerable<FurnitureImages> images = line.Furniture.Images;
- FurnitureImages mainImage = images.Where(x => x.IsMainImage).FirstOrDefault();
- <tr>
- <td class="text-center">
- @if (mainImage != null)
- {
- <img src="@Url.Content(mainImage.Path)" style="width:110px; height:70px" />
- }
- </td>
- <td class="text-center">
- <input type="text" data-id="@line.Furniture.FurnitureId" data-price="@line.Furniture.Price" value="@line.Quantity" class="quant" />
- </td>
- <td class="text-left">@line.Furniture.Name</td>
- <td class="text-right price" data-price="@line.Furniture.Price">@((line.Furniture.Price).ToString("#.## грн"))</td>
- <td class="text-right amount">@((line.Quantity * line.Furniture.Price).ToString("#.## грн"))</td>
- <td>
- @using (Html.BeginForm("RemoveFromCart", "Cart", new { Id = line.Furniture.FurnitureId }))
- {
- @Html.Hidden("Id", line.Furniture.FurnitureId)
- @Html.HiddenFor(x => x.ReturnUrl)
- <input class="btn btn-sm btn-warning" type="submit" value="Видалити з кошику" />
- }
- </td>
- </tr>
- }
- </tbody>
- <tfoot>
- <tr>
- <td colspan="4" class="text-right"><b>Всього до оплати:</b></td>
- <td id="test" class="text-right total">@Model.Cart.ComputeTotalValue().ToString("#.## грн")</td>
- </tr>
- </tfoot>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement