Is there an easy way to change name of 'addtocart' button for specific products?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 anni tempo fa
Hi,

Is there a way to change the caption of the add to cart button without modifying too much source? I see something on templates. Is that useful or is there another way?

J.


@if (!Model.DisableBuyButton)
            {
                var addToCartText = "";
                if (Model.UpdatedShoppingCartItemId > 0)
                {
                    addToCartText = T("ShoppingCart.AddToCart.Update").Text;
                }
                else
                {
                    addToCartText = Model.AvailableForPreOrder ? T("ShoppingCart.PreOrder").Text : T("ShoppingCart.AddToCart").Text;
                }
                <input type="button" id="[email protected]" class="button-1 add-to-cart-button" value="@addToCartText" data-productid="@Model.ProductId" onclick="AjaxCart.addproducttocart_details('@Url.RouteUrl("AddProductToCart-Details", new { productId = Model.ProductId, shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart })', '#product-details-form');return false;" />
            }
9 anni tempo fa
Quantis001 wrote:
Hi,

Is there a way to change the caption of the add to cart button without modifying too much source? I see something on templates. Is that useful or is there another way?
...


Hi You can update the value of the Language resource for "ShoppingCart.AddToCart" from admin panel.
9 anni tempo fa
Hi,
Sure, I need a different caption for a specific producttype. I see something like product templates/ catalog templates. Are they useful? I guess the catalog template will not allow to change caption per product since it is category aware and not product aware.
J.
8 anni tempo fa
How do you change the add to cart button text dynamically depending on some criteria?   Did this get solved?  If so how?
8 anni tempo fa
rlhilton13 wrote:
How do you change the add to cart button text dynamically depending on some criteria?   Did this get solved?  If so how?

There's already some code in the _AddToCart.cshtml partial view that determines what resource string value to use for the add to cart button:
@{
var addToCartText = "";
if (Model.UpdatedShoppingCartItemId > 0)
{
  addToCartText = T("ShoppingCart.AddToCart.Update").Text;
}
else
{
  addToCartText = T("ShoppingCart.AddToCart").Text;
  if (Model.IsRental)
  {
    addToCartText = T("ShoppingCart.Rent").Text;
  }
  if (Model.AvailableForPreOrder)
  {
    addToCartText = T("ShoppingCart.PreOrder").Text;
  }
}

You could extend that with additional criteria but it would depend on whether the properties that you need to base the logic on are exposed on the ProductDetailsModel.AddToCartModel that is passed to the view.
7 anni tempo fa
I'd like to revive this conversation. I'm guessing many others have had this same need. Any other thoughts on achieving this or confirmation that perhaps product templates are exposed here to key off of that?
7 anni tempo fa
anyone able to confirm if you can key off of the product template. My initial testing seems to indicate that it isn't possible.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.