Ejemplo n.º 1
0
        public int Execute(object pdispOrder, object pdispContext, int lFlags)
        {
            IDictionary order   = null;
            IDictionary context = null;

            try
            {
                order   = (IDictionary)pdispOrder;
                context = (IDictionary)pdispContext;
                ISimpleList lineItems = (ISimpleList)order["items"];

                var url = ConfigurationManager.AppSettings.Get("PricingServiceUrl");

                if (lineItems != null && lineItems.Count > 0)
                {
                    var prices = PipelineServiceHelper.CreateWebServiceInstance(url).GetPrices(order["BranchId"].ToString(),
                                                                                               order["CustomerId"].ToString(),
                                                                                               DateTime.Parse(order["RequestedShipDate"].ToString()),
                                                                                               lineItems.Cast <IDictionary>().Select(
                                                                                                   p => new product()
                    {
                        itemnumber = p["product_id"].ToString(),
                        catalog_id = p["product_catalog"].ToString()
                    }).ToArray());

                    foreach (object lineItem in lineItems)
                    {
                        IDictionary Item = (IDictionary)lineItem;

                        // Only price new items, filled/subbed/replacement items get their pricing from the mainframe
                        if (Item["MainFrameStatus"].ToString().Length == 0)
                        {
                            var itemPrice = ((KeithLink.Ext.Pipeline.ItemPrice.PipelineService.PriceReturn)prices).Prices.Where(p => p.ItemNumber.Equals(Item["product_id"].ToString()));

                            if (itemPrice.Any())
                            {
                                var price = Item["Each"].ToString().ToLower() == "true" ? itemPrice.First().PackagePrice : itemPrice.First().CasePrice;

                                if (price == 0) //TODO: Enable this check once we are using a real customer. For now there are far too many products without a price.
                                {
                                    throw new Exception("Price Not Found");
                                }

                                Item["_cy_iadjust_regularprice"] = (decimal)price;

                                Item["cy_placed_price"] = (decimal)price;
                            }
                            else
                            {
                                throw new Exception("Price Not Found");
                            }
                        }
                    }
                }

                //Taxes? Shipping Cost?


                order["_cy_oadjust_subtotal"] = lineItems.Cast <IDictionary>().Sum(l => (int)l["quantity"] * (decimal)l["cy_placed_price"]);
                order["_cy_total_total"]      = lineItems.Cast <IDictionary>().Sum(l => (int)l["quantity"] * (decimal)l["cy_placed_price"]);

                return(StatusSuccess);
            }
            catch (Exception ex)
            {
                Object errorMsg = ex.Message;
                LogErrorMessage(ex);
                ((ISimpleList)order["_Basket_Errors"]).Add(ref errorMsg);
                return(StatusError);
            }
        }