public override Money CalculateTax(EntitiesV2.Product product, EntitiesV2.PriceGroup priceGroup, Money unitPrice)
        {
            var productProperty = product.GetProperties()
                                  .FirstOrDefault(x => x.GetDefinitionField().DataType.DefinitionName == "PriceGroup");

            if (productProperty == null && product.ParentProduct != null)
            {
                // check variant
                productProperty = product.ParentProduct
                                  .GetProperties()
                                  .FirstOrDefault(x => x.GetDefinitionField().DataType.DefinitionName == "PriceGroup");
            }

            if (productProperty == null)
            {
                return(base.CalculateTax(product, priceGroup, unitPrice));
            }

            int priceGroupId = -1;

            if (int.TryParse(productProperty.GetValue().ToString(), out priceGroupId))
            {
                var overridenPriceGroup = _priceGroupRepository.SingleOrDefault(x => x.PriceGroupId == priceGroupId);
                if (priceGroup != null)
                {
                    return(CalculateTax(overridenPriceGroup, unitPrice));
                }
            }

            return(base.CalculateTax(product, priceGroup, unitPrice));
        }
Esempio n. 2
0
        private ProductDetailsModel MapProduct(EntitiesV2.Product currentproduct)
        {
            var model = new ProductDetailsModel();

            model.Sku              = currentproduct.Sku;
            model.Name             = currentproduct.DisplayName();
            model.LongDescription  = currentproduct.LongDescription();
            model.Url              = $"/Product?product={currentproduct.Id}";
            model.PriceCalculation = UCommerce.Api.CatalogLibrary.CalculatePrice(currentproduct);
            model.VariantSku       = currentproduct.VariantSku;

            model.IsVariant = currentproduct.IsVariant;
            foreach (EntitiesV2.Product currentProductVariant in currentproduct.Variants)
            {
                model.Variants.Add(MapProduct(currentProductVariant));
            }
            return(model);
        }