Skip to content

Commit

Permalink
Vat Rounding: GetUnitPrice fix for attribute combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Falk committed Mar 11, 2017
1 parent a1fd7d5 commit 97197a2
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/Libraries/Nop.Services/Catalog/PriceCalculationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,33 +537,31 @@ public virtual decimal GetUnitPrice(Product product,
//needed for VAT calculation of product bundles
//taxrate comes from associated product and not from product
decimal attributesTotalPrice = decimal.Zero;
if (combination != null)
var attributeValues = _productAttributeParser.ParseProductAttributeValues(attributesXml);
if (attributeValues != null)
{
var attributeValues = _productAttributeParser.ParseProductAttributeValues(attributesXml);
if (attributeValues != null)
decimal taxRate;
foreach (var attributeValue in attributeValues)
{
decimal taxRate;
foreach (var attributeValue in attributeValues)
{
var attributePrice = GetProductAttributeValuePriceAdjustment(attributeValue);
attributesTotalPrice += attributePrice;
var attributePrice = GetProductAttributeValuePriceAdjustment(attributeValue);
attributesTotalPrice += attributePrice;

if (attributeValue.AttributeValueType == AttributeValueType.AssociatedToProduct)
if (attributeValue.AttributeValueType == AttributeValueType.AssociatedToProduct)
{
//bundled product
var associatedProduct = _productService.GetProductById(attributeValue.AssociatedProductId);
if (associatedProduct != null)
{
//bundled product
var associatedProduct = _productService.GetProductById(attributeValue.AssociatedProductId);
if (associatedProduct != null)
{
//get only the taxrate of associate product, price is not needed
var attributePriceTax = _taxService.GetProductPrice(associatedProduct, 0, customer, out taxRate);
//build taxSummary for tax subdivision
taxWeightSummary.AddRate(taxRate, attributePrice);
}
//get only the taxrate of associate product, price is not needed
var attributePriceTax = _taxService.GetProductPrice(associatedProduct, 0, customer, out taxRate);
//build taxSummary for tax subdivision
taxWeightSummary.AddRate(taxRate, attributePrice);
}
}
}
}


if (combination != null && combination.OverriddenPrice.HasValue)
{
finalPrice = GetFinalPrice(product,
Expand Down Expand Up @@ -618,17 +616,17 @@ public virtual decimal GetUnitPrice(Product product,
if (_shoppingCartSettings.RoundPricesDuringCalculation)
finalPrice = RoundingHelper.RoundPrice(finalPrice);

//add tax attributes
//add tax attributes if needed
if (taxWeightSummary != null && taxWeightSummary.TaxRates.Any())
{
decimal prodcutTaxRate;
//get taxrate, no price needed
var itemAmount = _taxService.GetProductPrice(product, 0, customer, out prodcutTaxRate);
//get taxrate and product price
var productPrice = _taxService.GetProductPrice(product, product.Price, customer, out prodcutTaxRate);

//price is overridden or it is product price + attributes price
if (combination != null && !combination.OverriddenPrice.HasValue)
if (combination == null || combination != null && !combination.OverriddenPrice.HasValue)
{
var baseProductPrice = finalPrice - attributesTotalPrice;
var baseProductPrice = productPrice; // finalPrice - attributesTotalPrice;
//add product price if exists
if (baseProductPrice > decimal.Zero)
taxWeightSummary.AddRate(prodcutTaxRate, baseProductPrice);
Expand Down

0 comments on commit 97197a2

Please sign in to comment.