I have managed to add a remove button and also a change quantity button to the fly-out cart. Everything in the back end is working and also the fly-out cart displays the correct numbers.
The only issue i have is that the top link always displays the last total amount, if i refresh page it shows correct amount.
For example if i change quantity to 5 the cart shows 5 and correct amount, but the top link shows 1. Then i select 1 again cart recalculates works but the top link now shows 5. I am wondering if this is a bug or i am doing something wrong.
I added this to the cart html
<div class="quantity">@T("ShoppingCart.Mini.Quantity"): <input style="width:35px;" type="number" id="[email protected]" min="1" max="99" onchange="update_cart_quantity(@item.Id)" required value="@item.Quantity" /></div>
My java script is as followed. I don't think this is the issue as if i do an alert it shows the correct amount in new quantity.
function update_cart_quantity(id)
{
var newquantity = document.getElementById("cart_item_quantity-" + id.toString()).value;
if (AjaxCart.loadWaiting !== false) {
return;
}
AjaxCart.setLoadWaiting(true);
$.ajax({
url: '/AlternativewellbeingExtensions/UpdateCartItemQuantity',
data: { id: id, quantity: newquantity },
type: "POST",
success: AjaxCart.success_process,
complete: AjaxCart.resetLoadWaiting,
error: AjaxCart.ajaxFailure
});
My custom action code is
[HttpPost]
[IgnoreAntiforgeryToken]
public IActionResult UpdateCartItemQuantity(int id,int Quantity)
{
//display notification message and update appropriate blocks
var shoppingCarts = _shoppingCartService.GetShoppingCart(_workContext.CurrentCustomer, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id);
var updatecartitem = shoppingCarts.FirstOrDefault(item => item.Id == id);
_shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer,
updatecartitem.Id, updatecartitem.AttributesXml, updatecartitem.CustomerEnteredPrice,
updatecartitem.RentalStartDateUtc, updatecartitem.RentalEndDateUtc, Quantity, true);
var updatetopcartsectionhtml = string.Format(_localizationService.GetResource("ShoppingCart.HeaderQuantity"),
shoppingCarts.Sum(items => items.Quantity));
var updateflyoutcartsectionhtml = RenderViewComponentToString("FlyoutShoppingCart");
//Console.WriteLine(Quantity);
return Json(new
{
success = true,
message = string.Format("Product quantity updated!", Url.RouteUrl("ShoppingCart")),
updatetopcartsectionhtml,
updateflyoutcartsectionhtml
});
}
I don't usually do this but it has been driving me a bit barmy for a day, i was just wondering if anybody could maybe spot what i have done wrong.
I am using 4.3 beta as i know it will be released soon and i wanted to update my custom plugin to work with the new version.
Any help is much appreciated.
Thanks