Tier Prices & Product Variant Attributes [code snippet]

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I recently did a site that had a product with 4 attributes, each incrementing by £1, but needing a discount for 2 or more of any attribute combination.

If you create attributes for variants, then ad one of each to the cart, you'll notice they sit in seperate rows in the cart, meaning a tier price isn't calculated, because they are treated as different selections. So essentially, tier prices only seem to calculate for variants with none or the same attribute.

Here's a quick snippet to work around this.

In PriceHelper.cs, add this to the GetFinalPrice() method, around line 298.

//##########################

IShoppingCartService scs = IoC.Resolve<IShoppingCartService>();

var cart = scs.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);

int countof = 0;

foreach (ShoppingCartItem sci in cart)
{
        if (sci.ProductVariantId == productVariant.ProductVariantId)
        {
             countof = countof + sci.Quantity;
         }
}

Then on about line 339, pass the var countof instead of quantity to the GetTierPrice() method, like:

decimal tierPrice = GetTierPrice(productVariant, countof /*quantity*/);

As the tier price returns a single item price, irrespective of quantity, we don't need to add anything else.

What this does is simply check the cart for any other shoppingcartitems that have the same productvariant and uses this as the quantity when calculating tier price. Note it uses the shpoppingcartitem.Quantity value to increment countof, so it preserves any multiple selections of any variant attributes in different rows of the basket and will honour multiple tier prices as designed by nop.

Please test your implementation throughly before adding it to live.

ed/
12 years ago
That's exactly what I am looking for thank you.   Anyone take a stab at this with 2.0?  I'd like to make that MVC leap, but this is a deal breaker as I need the capability to have tier pricing apply to any variant that is associated with the same Product ID.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.