SUGGESTION: Override price adjustment in product attribute values with associated product

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 8 ans
In the case of product attribute values with associated product, the price adjustment is the price of the product, but when building kits/bundles it is very common to make a discount in the products or accessories included in the kit. There is the feature to override prices product attributes combinations, but it can become very complex when you have several attributes or when some are accessories (non-combinable attributes) of the product. For instance for the case of Build Your Own Computer there are 0ver 200 possible combinations.

So the proposal is to let the user establish the price adjustment for each attribute value that has an associated product. It could be established in 2 ways (it would be great that both could be available):
1) As a percentage of the associated product price, where 100% would be exactly as it is now. <100% renders a discount (80%= 20% discount) and >100% can be used to charge for assembly services or alike (110% means that there is a 10% extra charge.

2) As an $ amount.

It would also be useful that when the resulting price adjustment is less than the associated product value in the value selection text the amount of the discount is displayed: product_name [+$xx.xx (Y% discount)] so if the associated product price is $200 and in option (1) 75% was selected; the text will be product_name [+$150.00 (25% discount)]

This feature lets to built very complex bundles and also lets use tier (or per store/customer role) prices in the main product of the bundle.
Il y a 8 ans
Thanks a lot, Eduardo! Please vote for this work item here
Il y a 8 ans
Good suggestion, voted.

I've previously implemented the percentage discount part of your suggestion on our site for AssociatedToProduct attributes and the code change required is minimal. There's already a decimal field available for the price adjustment which is used for non-AssociatedToProduct attributes so I just reused this field to hold the percentage adjustment. This field gets hidden in the admin GUI by javascript when the associated to product option is selected but the field still exists and gets saved to the database so it's just a case of commenting out the code that hides it in the admin view:

_CreateOrUpdateProductAttributeValue.cshtml (changes in bold)

function toggleProductType() {
        var selectedProductTypeId = $("#@Html.FieldIdFor(model => model.AttributeValueTypeId)").val();
        if (selectedProductTypeId == @(((int)AttributeValueType.Simple).ToString())) {
            $('#group-associated-product').hide();
            $('#group-quantity').hide();
            $('#group-price-adjustment').show();
            $('#group-weight-adjustment').show();
            $('#group-cost').show();
        } else if (selectedProductTypeId == @(((int)AttributeValueType.AssociatedToProduct).ToString())) {
            $('#group-associated-product').show();
            $('#group-quantity').show();
            //$('#group-price-adjustment').hide();  //Support percentage discounts on AssociatedToProduct product attributes
            $('#group-weight-adjustment').hide();
            $('#group-cost').hide();
        }
    }

and then using the value in the GetProductAttributeValuePriceAdjustment funtion of the price calculation service:

PriceCalculationService.cs (addition in bold)

/// <summary>
/// Get a price adjustment of a product attribute value
/// </summary>
/// <param name="value">Product attribute value</param>
/// <returns>Price adjustment</returns>
public virtual decimal GetProductAttributeValuePriceAdjustment(ProductAttributeValue value)
{
    if (value == null)
        throw new ArgumentNullException("value");

    var adjustment = decimal.Zero;
    switch (value.AttributeValueType)
    {
        case AttributeValueType.Simple:
            {
                //simple attribute
                adjustment = value.PriceAdjustment;
            }
            break;
        case AttributeValueType.AssociatedToProduct:
            {
                //bundled product
                var associatedProduct = _productService.GetProductById(value.AssociatedProductId);
                if (associatedProduct != null)
                {
                    adjustment = GetFinalPrice(associatedProduct, _workContext.CurrentCustomer, includeDiscounts: true) * value.Quantity;

                    //Allow percentage based price adjustments on AssociatedToProduct product attributes!
                    adjustment = adjustment + (adjustment * value.PriceAdjustment / 100);
                    //rounding
                    if (_shoppingCartSettings.RoundPricesDuringCalculation)
                        adjustment = RoundingHelper.RoundPrice(adjustment);
                    //---------------------------------------------------------------//

                }
            }
            break;
        default:
            break;
    }

    return adjustment;
}

Just these 2 changes allow the functionality you mention in point 1 above, and as you say it allows positive or negative adjustments and is calculated after tier prices are applied so supports some advanced pricing and discounting scenarios like "buy X get Y half price" which aren't possible with the standard discount implementation.

To support point 2 above I think an extra check box would be required to specify whether the discount is a fixed value or a percentage similar to how it currently works for discounts.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.