Esempio n. 1
0
            public bool ApplyFilter(IFilterRow row)
            {
                bool result = false;

                if (row != null)
                {
                    String sku            = row.GetColumn(Sku).Value;
                    String weightAsString = row.GetColumn(Weight).Value;
                    String volumeAsString = row.GetColumn(Volume).Value;

                    if (String.IsNullOrWhiteSpace(weightAsString) == false && String.IsNullOrWhiteSpace(volumeAsString) == false)
                    {
                        if (decimal.TryParse(weightAsString, out decimal weightAsLBS) &&
                            decimal.TryParse(volumeAsString, out decimal volumeAsCubicFeet))
                        {
                            decimal gramConversionFactor = (decimal)453.59237;

                            decimal weight = gramConversionFactor * weightAsLBS;

                            WeightCubicVolumeInformation wi = new WeightCubicVolumeInformation(weight, weightAsLBS, volumeAsCubicFeet);

                            MatchingRowIds.Add(sku, wi);

                            result = true;
                        }
                    }
                }
                return(result);
            }
Esempio n. 2
0
            public void RemoveExcludedRows(CsvFile products)
            {
                if (MatchingRowIds == null || MatchingRowIds.Count == 0)
                {
                    return;
                }

                foreach (CsvRow row in products.Rows.Where(r => r.ExcludeMe))
                {
                    IFilterValue value = row.GetColumn(Sku);
                    if (value == null)
                    {
                        value = row.GetColumn(Sku.ToLower());
                    }

                    if (value == null)
                    {
                    }
                    else
                    {
                        if (MatchingRowIds.Contains(value.Value) == true)
                        {
                            MatchingRowIds.Remove(value.Value);
                        }
                    }
                }
            }
 public bool?HasBeenFiltered(IFilterRow row)
 {
     if (ShouldFilter == false)
     {
         return(true);
     }
     return(MatchingRowIds.Contains(row?.Handle.Value));
 }
Esempio n. 4
0
            public bool?HasBeenFiltered(IFilterRow row)
            {
                if (ShouldFilter == false)
                {
                    return(null);
                }
                IFilterValue handle = row.GetColumn("Handle");

                return(MatchingRowIds.Contains(handle?.Value));
            }
 public void RemoveExcludedRows(CsvFile products)
 {
     foreach (CsvRow row in products.Rows.Where(r => r.ExcludeMe))
     {
         IFilterValue value = row.GetColumn(Sku);
         if (MatchingRowIds.Contains(value.Value) == true)
         {
             MatchingRowIds.Remove(value.Value);
         }
     }
 }
            public bool ApplyFilter(IFilterRow row)
            {
                bool result = false;

                if (row != null)
                {
                    row.Handle = row.GetColumn(VariantSku);
                    MatchingRowIds.Add(row.Handle.Value);
                    result = true;
                }
                return(result);
            }
Esempio n. 7
0
            public void Update(CsvRow row)
            {
                String?sku = row?.GetColumn(Sku).Value;

                if (MatchingRowIds.ContainsKey(sku))
                {
                    WeightCubicVolumeInformation wi = MatchingRowIds[sku];
                    if (wi != null)
                    {
                        row?.SetColumn("Variant Grams", wi.Grams.ToString(CultureInfo.InvariantCulture));
                        row?.SetColumn(Weight, wi.Weight.ToString());
                    }
                }
            }
Esempio n. 8
0
            public bool ApplyFilter(IFilterRow row)
            {
                bool result = false;



                IFilterValue weightString = row.GetColumn(Weight);
                IFilterValue lengthString = row.GetColumn(Length);
                IFilterValue widthString  = row.GetColumn(Width);
                IFilterValue heightString = row.GetColumn(Height);
                IFilterValue handle       = row.GetColumn("Handle");

                bool we = decimal.TryParse(weightString?.Value, out decimal weight);
                bool le = decimal.TryParse(lengthString?.Value, out decimal length);
                bool wi = decimal.TryParse(widthString?.Value, out decimal width);
                bool he = decimal.TryParse(heightString?.Value, out decimal height);

                if (le && wi && he)
                {
                    decimal cubicVolumeLength = Math.Round(length);
                    decimal cubicVolumeWidth  = Math.Round(width);
                    decimal cubicVolumeHeight = Math.Round(height);

                    decimal dimWeight = cubicVolumeLength * cubicVolumeWidth * cubicVolumeHeight / DimWeightDivisor;

                    if (dimWeight > weight)
                    {
                        weight = dimWeight;
                    }
                }

                if (we)
                {
                    result = (weight < 1);
                    if (result)
                    {
                        row.Handle        = handle;
                        row.UnderOnePound = true;
                        MatchingRowIds.Add(handle.Value);
                    }
                    else
                    {
                        row.Handle       = handle;
                        row.OverOnePound = true;
                        Console.WriteLine($"Product with Handle={handle?.Value} and weight={weight} exceeds threshold=0.23");
                    }
                }
                return(result);
            }
Esempio n. 9
0
            public bool ApplyFilter(IFilterRow row)
            {
                bool result = false;

                IFilterValue inventoryString = row.GetColumn(Inventory);
                IFilterValue handle          = row.Handle ?? row.GetColumn("Handle");


                if (handle == null || inventoryString == null)
                {
                    return(result);
                }

                int  inventory = -1;
                bool i         = int.TryParse(inventoryString.Value, out inventory);

                if (i && String.IsNullOrEmpty(handle.Value) == false)
                {
                    if (MinimumInventoryThreshold > 0 && MaximumInventoryThreshold > MinimumInventoryThreshold)
                    {
                        result = inventory >= MinimumInventoryThreshold && inventory <= MaximumInventoryThreshold;
                    }
                    else if (MinimumInventoryThreshold == MaximumInventoryThreshold)
                    {
                        result = inventory > MinimumInventoryThreshold;
                    }

                    if (result)
                    {
                        row.Handle = handle;
                        MatchingRowIds.Add(handle.Value);
                    }
                    else
                    {
                        row.Handle = handle;
                        Console.WriteLine($"Product with Handle={handle} and no inventory.");
                    }
                }
                return(result);
            }
            public void Update(CsvRow row)
            {
                if (row != null)
                {
                    String sku = row.GetColumn(Sku).Value;

                    if (MatchingRowIds.ContainsKey(sku))
                    {
                        PriceInformation pi = MatchingRowIds[sku];
                        if (pi != null)
                        {
                            row.SetColumn(VariantCompareToPrice, pi.Msrp);
                            row.SetColumn(Option1Value, "Default Title");
                            row.SetColumn(CostPerItem, pi.CostPerItem);
                            row.SetColumn(VariantPrice, pi.Price);
                            row.SetColumn(Price, pi.Price);
                            row.SetColumn(Msrp, pi.Msrp);
                            row.SetColumn(Option1Name, "Title");
                        }
                    }
                }
            }
            public bool ApplyFilter(IFilterRow row)
            {
                bool result = false;


                if (row != null)
                {
                    String volumeAsString = row.GetColumn("cubic_volume (in.)").Value;

                    String weightAsString           = row.GetColumn(Weight).Value;
                    String priceAsString            = row.GetColumn(Price).Value;
                    String msrpAsString             = row.GetColumn(Msrp).Value;
                    String mapAsString              = row.GetColumn(Map).Value;
                    String sku                      = row.GetColumn(Sku).Value;
                    WeightCubicVolumeInformation wi = null;

                    decimal.TryParse(msrpAsString, out decimal msrp);
                    decimal.TryParse(weightAsString, out decimal weight);
                    decimal.TryParse(volumeAsString, out decimal volume);
                    decimal.TryParse(mapAsString, out decimal map);

                    if (String.IsNullOrWhiteSpace(weightAsString) == false &&
                        String.IsNullOrWhiteSpace(volumeAsString) == false)
                    {
                        if (decimal.TryParse(weightAsString, out decimal weightAsLBS) &&
                            decimal.TryParse(volumeAsString, out decimal volumeAsCubicFeet))
                        {
                            decimal gramConversionFactor = (decimal)453.59237;

                            weight = gramConversionFactor * weightAsLBS;

                            wi = new WeightCubicVolumeInformation(weight, weightAsLBS, volumeAsCubicFeet);
                        }
                    }

                    decimal.TryParse(priceAsString, out decimal price);

                    decimal costPerItem = price;

                    price = (price * (decimal)ProfitMargin);
                    if (price > (decimal)3.0)
                    {
                        price = (Math.Floor(price) + (decimal)0.47);
                    }

                    if (price < costPerItem)
                    {
                        price = (costPerItem * (decimal)ProfitMargin);
                    }

                    if (String.IsNullOrWhiteSpace(mapAsString) == false)
                    {
                        if (price < map)
                        {
                            price = Math.Floor(map) + (decimal)0.49;
                        }
                    }

                    if (msrp > 0)
                    {
                        if (price > msrp)
                        {
                            price = msrp;
                        }
                    }
                    else
                    {
                        msrp = price + (price * (decimal)0.20);
                    }

                    IFilterValue storage = row.GetColumn("storage");
                    if (storage != null && string.IsNullOrWhiteSpace(storage.Value) == false &&
                        (storage.Value == Refrigerated || storage.Value == Frozen))
                    {
                        price += (decimal)ShippingSurcharge;
                    }

                    decimal volumeShippingCost = 0;
                    decimal weightShippingCost = 0;
                    if (wi != null && ShouldAddShipping)
                    {
                        (volumeShippingCost, weightShippingCost) = ShippingCost.Get(wi);

                        if (volumeShippingCost < weightShippingCost)
                        {
                            price += weightShippingCost;
                        }
                        else
                        {
                            price += volumeShippingCost;
                        }
                    }

                    PriceInformation pi = new PriceInformation(msrp.ToString("C2"), msrp.ToString("C2"), costPerItem.ToString("C2"), price.ToString("C2"));

                    MatchingRowIds.Add(row.GetColumn(Sku).Value, pi);

                    result = true;
                }
                return(result);
            }
 public bool?HasBeenFiltered(IFilterRow row)
 {
     return(MatchingRowIds.ContainsKey(row?.Handle.Value));
 }
Esempio n. 13
0
            public bool?HasBeenFiltered(IFilterRow row)
            {
                IFilterValue?handle = row?.Handle;

                return(MatchingRowIds.ContainsKey(handle?.Value));
            }