コード例 #1
0
        private static ProductVariantImportDataTransferObject GetProductVariant(Dictionary<string, List<string>> parseErrors, ExcelWorksheet worksheet,
            int rowId, string handle)
        {
            var productVariant = new ProductVariantImportDataTransferObject
            {
                Name = worksheet.GetValue<string>(rowId, 11)
            };

            if (!GeneralHelper.IsValidInput<decimal>(worksheet.GetValue<string>(rowId, 12)))
                parseErrors[handle].Add("Price value is not a valid decimal number.");
            else if (worksheet.GetValue<string>(rowId, 12).HasValue())
                productVariant.Price =
                    GeneralHelper.GetValue<decimal>(worksheet.GetValue<string>(rowId, 12));
            else
                parseErrors[handle].Add("Price is required.");

            if (!GeneralHelper.IsValidInput<decimal>(worksheet.GetValue<string>(rowId, 13)))
                parseErrors[handle].Add(
                    "Previous Price value is not a valid decimal number.");
            else
                productVariant.PreviousPrice =
                    GeneralHelper.GetValue<decimal>(worksheet.GetValue<string>(rowId, 13));

            if (!GeneralHelper.IsValidInput<int>(worksheet.GetValue<string>(rowId, 14)))
                parseErrors[handle].Add("Tax Rate Id value is not a valid number.");
            else
                productVariant.TaxRate =
                    GeneralHelper.GetValue<int>(worksheet.GetValue<string>(rowId, 14));

            if (!GeneralHelper.IsValidInput<decimal>(worksheet.GetValue<string>(rowId, 15)))
                parseErrors[handle].Add("Weight value is not a valid decimal number.");
            else
                productVariant.Weight =
                    GeneralHelper.GetValue<decimal>(worksheet.GetValue<string>(rowId, 15));

            if (!GeneralHelper.IsValidInput<int>(worksheet.GetValue<string>(rowId, 16)))
                parseErrors[handle].Add("Stock value is not a valid decimal number.");
            else
                productVariant.Stock = worksheet.HasValue(rowId, 16)
                    ? GeneralHelper.GetValue<int>(
                        worksheet.GetValue<string>(rowId, 16))
                    : (int?) null;

            if (!worksheet.GetValue<string>(rowId, 17).HasValue() ||
                (worksheet.GetValue<string>(rowId, 17) != "Track" &&
                 worksheet.GetValue<string>(rowId, 17) != "DontTrack"))
                parseErrors[handle].Add(
                    "Tracking Policy must have either 'Track' or 'DontTrack' value.");
            else
            {
                productVariant.TrackingPolicy = worksheet.GetValue<string>(rowId, 17) == "Track"
                    ? TrackingPolicy.Track
                    : TrackingPolicy.DontTrack;
            }
            if (worksheet.GetValue<string>(rowId, 18).HasValue())
                productVariant.SKU = worksheet.GetValue<string>(rowId, 18);
            else
                parseErrors[handle].Add("SKU is required.");
            productVariant.Barcode = worksheet.GetValue<string>(rowId, 19);

            productVariant.ManufacturerPartNumber = worksheet.GetValue<string>(rowId, 20);

            productVariant.ETag = worksheet.GetValue<string>(rowId, 33);
            
            return productVariant;
        }