Update cart problem

1 year ago
Cart is not update after adding products.When i refresh page added products appear.


My code is


@model IList<ProductOverviewModel>
@using Nop.Core.Infrastructure
@using Nop.Services.Catalog
@using Nop.Services.Media
@using Nop.Core.Domain.Orders

@inject IProductService c
@inject IPictureService picService

@{
    var pictureService = EngineContext.Current.Resolve<IPictureService>();
    var media = new Nop.Core.Domain.Media.MediaSettings();
    var addtocartlink = "";
    var shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart;
    addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.FirstOrDefault().Id, shoppingCartTypeId = shoppingCartTypeId, quantity = 1 });
}


addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.FirstOrDefault().Id, shoppingCartTypeId = shoppingCartTypeId, quantity = 1 });

<input type="button" value="ekle" class="button-2 product-box-add-to-cart-button" onclick="AjaxCart.addproducttocart_catalog('@addtocartlink');return false;" />
1 year ago
Hello kazmirci,
Please go to "Presentation\Nop.Web\Controllers\ShoppingCartController" and debug "AddProductToCart_Catalog" action.
I think "updateflyoutcartsectionhtml" not returning the expected html.

Hope it will help.
1 year ago
ferdous0905 wrote:
Hello kazmirci,
Please go to "Presentation\Nop.Web\Controllers\ShoppingCartController" and debug "AddProductToCart_Catalog" action.
I think "updateflyoutcartsectionhtml" not returning the expected html.

Hope it will help.


Thank you.You are right i debuged and it returns below code.But my product dont have any attributes.
How can i fix it?

//allow a product to be added to the cart when all attributes are with "read-only checkboxes" type
            var productAttributes = _productAttributeService.GetProductAttributeMappingsByProductId(product.Id);
            if (productAttributes.Any(pam => pam.AttributeControlType != AttributeControlType.ReadonlyCheckboxes))
            {
                //product has some attributes. let a customer see them
                return Json(new
                {
                    redirect = Url.RouteUrl("Product", new { SeName = _urlRecordService.GetSeName(product) })
                });
            }
1 year ago
Hello kazmirci,
Its good to know you found your problem. that specific loop won't work if the product doesn't have any attribute.
so please go to product edit page and check for product attribute.
You can take this product as an example "http://admin-demo.nopcommerce.com/Admin/Product/Edit/1".

There is a another action in "ShoppingCartController" called "AddProductToCart_Details" you may also want to study that. it normally use in product details page.

i hope you will solve your problem.Thanks.