parametric quantity view _ProductBoxList 3.80

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi, I am editing the _Productboxlist view, I would like to add a text box field to the view to make the value of the quantity parameter (fixed to 1 in the standard).

 Because the parameter prepares it first
// prepare "Add to cart" AJAX link

do you think I should go to make this parametric?

{@
    // prepare "Add to cart" AJAX link
    string addtocartlink = "";
    var shoppingCartTypeId = (int) ShoppingCartType.ShoppingCart;

    var quantity = 1; // make parametric (input text box)
   
    if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
    {
        addtocartlink = Url.RouteUrl ("AddProductToCart-Catalog", new {productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart});
    }
    else
    {
        addtocartlink = Url.RouteUrl ("AddProductToCart-Catalog", new {productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity,});
    }
}




  <input type="button" value="@(Model.ProductPrice.AvailableForPreOrder ? T("ShoppingCart.PreOrder") : T("ShoppingCart.AddToCart"))" class="button-2 product-box-add-to-cart-button" onclick="AjaxCart.addproducttocart_catalog('@addtocartlink');return false;" />
6 years ago
Try with the following js function  and call it from button click

function callAjaxLink(productId,addtocartlink) {
        var defaultLink =addtocartlink;
        var l = defaultLink.length;
        var slice = defaultLink.slice(0, (l - 1));
        var q = $('#itemquantity_' + productId).val(); // get quantiy value
        if (q == "")
            q = "1";
        var newLink = slice.concat(q);
       AjaxCart.addproducttocart_catalog(newLink);
    }
6 years ago
fantastic, it works perfectly
5 years ago
if I wanted the quantity to be decimal?
how does the script become?
I modified the variable

 public ActionResult AddProductToCart_Catalog (int productId, int shoppingCartTypeId,
            decimal quantity, bool forceredirection = false)


and modified the Provider wheels in


routes.MapLocalizedRoute ( "AddProductToCart-Catalog"
"Addproducttocart / catalog / {productId} / {shoppingCartTypeId} / {quantity}",
new {controller = "ShoppingCart", action = "AddProductToCart_Catalog"},
new {productId = @ "\ d +", shoppingCartTypeId = @ "\ d +"},
new [] {"Nop.Web.Controllers"});


removing the restriction of the quantity = @"\d+" only integers


when I insert 1.5 or 1.5 the public.ajaxcart.js


 
addproducttocart_catalog: function (urladd) {
        if (this.loadWaiting! = false) {
            return;
        }
        this.setLoadWaiting (true);

        $ .Ajax ({
            cache: false,
            url: urladd,
            type: 'post',
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },


returns an error message

    ajaxFailure: function () {
        alert ('Failed to add the product.');
    }


What should you do? insert a restriction in the route provider so that it accepts not only the integer values?

thank you so much
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.