public AmazonListing UpdateAmazonListing(AmazonListing amazonListing)
        {
            var productVariant = _productVariantService.GetProductVariantBySKU(amazonListing.ProductVariant.SKU);

            amazonListing.ProductVariant = productVariant;
            amazonListing.Brand          = productVariant.Product.Brand != null ? productVariant.Product.Brand.Name : String.Empty;
            amazonListing.Condition      = ConditionType.New;
            var currency = _ecommerceSettings.Currency();

            amazonListing.Currency      = (currency != null && !String.IsNullOrWhiteSpace(currency.Code))?currency.Code:CurrencyCode.GBP.GetDescription();
            amazonListing.Manafacturer  = productVariant.Product.Brand != null ? productVariant.Product.Brand.Name : String.Empty;
            amazonListing.MfrPartNumber = productVariant.ManufacturerPartNumber;
            amazonListing.Quantity      = productVariant.TrackingPolicy == TrackingPolicy.Track
                                          ? _getStockRemainingQuantity.Get(productVariant)
                                          : 1000;
            amazonListing.Price                 = _productPricingMethod.GetUnitPrice(productVariant, 0m, 0m);
            amazonListing.SellerSKU             = productVariant.SKU;
            amazonListing.Title                 = productVariant.DisplayName;
            amazonListing.StandardProductIDType = _amazonSellerSettings.BarcodeIsOfType;
            amazonListing.StandardProductId     = productVariant.Barcode.Trim();

            amazonListing.FulfillmentChannel = amazonListing.AmazonListingGroup.FulfillmentChannel ?? AmazonFulfillmentChannel.MFN;

            _amazonListingService.Save(amazonListing);

            return(amazonListing);
        }
        public void PrepareForSyncAmazonListingService_UpdateAmazonListing_ShouldReturnAmazonListingType()
        {
            var mockingKernel = new MockingKernel();

            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind <ISession>().ToMethod(context => A.Fake <ISession>());

            var product        = new Product();
            var productVariant = new ProductVariant()
            {
                Product = product, SKU = "S1", Barcode = ""
            };
            var model = new AmazonListing()
            {
                ProductVariant = productVariant, AmazonListingGroup = new AmazonListingGroup()
                {
                    FulfillmentChannel = AmazonFulfillmentChannel.MFN
                }
            };

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.UpdateAmazonListing(model);

            results.Should().BeOfType <AmazonListing>();
        }
        public void SetOrderLinesTaxes(ref Order order)
        {
            foreach (var orderLine in order.OrderLines)
            {
                var productVariant = _productVariantService.GetProductVariantBySKU(orderLine.SKU);

                var getDefaultTaxRate    = new GetDefaultTaxRate(_session);
                var productPricingMethod = new ProductPricingMethod(new TaxSettings
                {
                    PriceLoadingMethod   = PriceLoadingMethod.IncludingTax,
                    TaxCalculationMethod = TaxCalculationMethod.Individual,
                    TaxesEnabled         = true
                }, getDefaultTaxRate);

                var taxRate = productVariant == null || productVariant.TaxRate == null
                    ? getDefaultTaxRate.Get()
                    : productVariant.TaxRate;

                var taxRatePercentage = taxRate == null ? 0 : taxRate.Percentage;
                var tax = productPricingMethod.GetTax(orderLine.UnitPrice, taxRatePercentage, 0m, 0m);

                orderLine.UnitPricePreTax = orderLine.UnitPrice - tax;
                orderLine.PricePreTax     = orderLine.UnitPricePreTax * orderLine.Quantity;
                orderLine.Tax             = orderLine.Price - orderLine.PricePreTax;
                orderLine.TaxRate         = _getProductVariantTaxRatePercentage.GetTaxRatePercentage(productVariant);
            }
            order.Subtotal = order.OrderLines.Sum(line => line.UnitPricePreTax * line.Quantity);
            order.Tax      = order.OrderLines.Sum(line => line.Tax);
        }
        public void SetOrderLinesTaxes(ref Order order)
        {
            foreach (var orderLine in order.OrderLines)
            {
                var productVariant = _productVariantService.GetProductVariantBySKU(orderLine.SKU);
                if (productVariant == null)
                {
                    continue;
                }

                var tax = _productPricingMethod.GetUnitTax(productVariant, 0m, 0m);

                //new TaxSettings
                //    {
                //        TaxesEnabled = true,
                //        LoadedPricesIncludeTax =true
                //    });
                //var tax = taxAwareProductPrice.Tax.GetValueOrDefault();
                orderLine.UnitPricePreTax = orderLine.UnitPrice - tax;
                orderLine.PricePreTax     = orderLine.UnitPricePreTax * orderLine.Quantity;
                orderLine.Tax             = orderLine.Price - orderLine.PricePreTax;
                orderLine.TaxRate         = _getProductVariantTaxRatePercentage.GetTaxRatePercentage(productVariant);
            }
            order.Subtotal = order.OrderLines.Sum(line => line.UnitPricePreTax * line.Quantity);
            order.Tax      = order.OrderLines.Sum(line => line.Tax);
        }
Exemple #5
0
        TaxRateManager_GetDefaultRateForOrderLine_ShouldReturnDefaultTaxRateIfProductVariantTaxRateNotSpecified()
        {
            var taxRate = new TaxRate {
                Percentage = 10, IsDefault = true, Name = "GLOBAL", Code = "GL"
            };

            A.CallTo(() => _getDefaultTaxRate.Get()).Returns(taxRate);

            var orderLine = new OrderLine {
                ProductVariant = new ProductVariant(), SKU = "123"
            };

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(orderLine.SKU)).Returns(null);

            TaxRate result = _taxRateManager.GetRateForOrderLine(orderLine);

            result.Should().NotBeNull();
            result.Should().Be(taxRate);
        }
Exemple #6
0
        public TaxRate GetRateForOrderLine(OrderLine orderLine)
        {
            TaxRate        taxRate = null;
            ProductVariant pv      = _productVariantService.GetProductVariantBySKU(orderLine.SKU);

            if (pv != null && pv.TaxRate != null)
            {
                taxRate = pv.TaxRate;
            }
            return(taxRate ?? GetDefaultRate());
        }
Exemple #7
0
        public IEnumerable <string> GetErrors(ProductImportDataTransferObject product)
        {
            var errors       = new List <string>();
            var mrCmsProduct = _productService.GetByUrl(product.UrlSegment);

            foreach (var pv in product.ProductVariants)
            {
                var mrCmsVariant = _productVariantService.GetProductVariantBySKU(pv.SKU);

                if (mrCmsVariant != null)
                {
                    if (mrCmsProduct == null || (mrCmsVariant.Product.Id != mrCmsProduct.Id))
                    {
                        errors.Add(string.Format("Product Variant with SKU {0} already exists on product with Url Segment {1}", pv.SKU, mrCmsVariant.Product.UrlSegment));
                    }
                }
            }

            return(errors);
        }