示例#1
0
        public void CreateAmazonOrder(SalesOrder order)
        {
            dynamic amazonOrder = new AmazonOrders();
            var existingOrder = amazonOrder.First(OrderNumber: order.OrderId);
            dynamic map = new ExpandoObject();

                                              	map.Store = "Amazon";
                                              	map.StoreEntityId = order.NativeId;
                                              	map.OrderNumber = order.OrderId;
                                              	map.StoreCreatedAt = order.StoreCreatedAt;
                                              	map.StoreUpdatedAt = order.StoreUpdatedAt;
                                              	map.StoreStatus = order.StoreStatus;
                                              	map.CustomerName = order.DeliveryCustomerName;
                                              	map.ShipStreet = order.DeliveryStreet;
                                              	map.ShipCity = order.DeliveryCity;
                                              	map.ShipState = order.DeliveryState;
                                              	map.ShipZip = order.DeliveryZip;
                                              	map.ShipCountry = order.DeliveryCountry;

            if(existingOrder == null)
            {
                NLog.LogManager.GetCurrentClassLogger().Warn("Create amazon order: {0}", order.OrderId);
                map.CreatedAt = DateTime.Now;
                var newId = amazonOrder.Insert(map);
            }
            else if(existingOrder.StoreStatus != order.StoreStatus)
            {
                NLog.LogManager.GetCurrentClassLogger().Warn("Update amazon order: {0}", order.OrderId);
                map.Updatedat = DateTime.Now;
                amazonOrder.Update(map,existingOrder.Id);
            }
        }
示例#2
0
        public void GetOrderItems(SalesOrder salesOrder)
        {
            salesOrder.DeliveryMode = "Standard";
            salesOrder.ShippingMethodDescription = "Standard";
            salesOrder.ShippingChargeCode = "FREIGHT";

            OrderFetcher fetcher = new OrderFetcher(service, merchantId, new string[] { marketplaceId });
            var orderService = new OrderService();
            fetcher.FetchOrderItems(salesOrder.NativeId, delegate(OrderItem item)
            {
                NLog.LogManager.GetCurrentClassLogger().Info(item.ToString());
                if(item.IsSetShippingPrice())
                    salesOrder.ShippingChargeAmount += Decimal.Parse(item.ShippingPrice.Amount);
                var quantityOrdered = item.IsSetQuantityOrdered() ? item.QuantityOrdered : 0;
                if(!item.IsSetItemPrice() && quantityOrdered == 0)
                    NLog.LogManager.GetCurrentClassLogger().Error("Amazon, Assuming Line is Cancelled.  Item Price and Quantity not set for Order {0} Item SKU {1} Quantity Ordered {2}",salesOrder.OrderId,item.SellerSKU, quantityOrdered);
                else
                    salesOrder.AddLineItem(item.SellerSKU,item.Title,item.QuantityOrdered,decimal.Parse(item.ItemPrice.Amount) /  item.QuantityOrdered,
                                          decimal.Parse(item.ItemPrice.Amount),
                                           orderService.GetItemSalesUoM(item.SellerSKU),
                                           orderService.GetItemPrice(item.SellerSKU));
            });
        }
示例#3
0
        public void SetBillingAddress(SalesOrder order, salesOrderEntity magentoOrder)
        {
            var billing = magentoOrder.billing_address;
            var shipping = magentoOrder.shipping_address;

            if( !billing.firstname.Equals(shipping.firstname, StringComparison.OrdinalIgnoreCase) ||
                !billing.lastname.Equals(shipping.lastname,StringComparison.OrdinalIgnoreCase) ||
                !billing.street.Equals(shipping.street,StringComparison.OrdinalIgnoreCase) ||
                !billing.city.Equals(shipping.city,StringComparison.OrdinalIgnoreCase) ||
                !billing.postcode.Equals(shipping.postcode,StringComparison.OrdinalIgnoreCase) ||
                !billing.region.Equals(shipping.region,StringComparison.OrdinalIgnoreCase)

            )
            {
                order.BillToCustomerName = billing.firstname + " " + billing.lastname;
                order.BillToStreet =  billing.street;
                order.BillToCity =  billing.city;
                order.BillToState =  billing.region;
                order.BillToZip =  billing.postcode;
                order.BillToCountry =  billing.country_id;
            }
        }
示例#4
0
        public SalesOrder MapOrderFromStore(salesOrderEntity magentoOrder)
        {
            var order = new SalesOrder();
            order.OrderId = magentoOrder.increment_id;
            order.NativeId = magentoOrder.order_id;
            order.CustomerEmail = magentoOrder.customer_email;
            order.BillToCustomerName = magentoOrder.customer_firstname + " " + magentoOrder.customer_lastname;
            if(string.IsNullOrWhiteSpace(order.BillToCustomerName) && magentoOrder.billing_address != null)
               order.BillToCustomerName = magentoOrder.billing_address.firstname + " " + magentoOrder.billing_address.lastname;

            order.DeliveryCustomerName = magentoOrder.shipping_address.firstname + " " + magentoOrder.shipping_address.lastname;
            order.DeliveryStreet = magentoOrder.shipping_address.street;
            order.DeliveryCity = magentoOrder.shipping_address.city;
            order.DeliveryState = magentoOrder.shipping_address.region;
            order.DeliveryZip = magentoOrder.shipping_address.postcode;
            order.DeliveryCountry = magentoOrder.shipping_address.country_id;
            SetBillingAddress(order, magentoOrder);
            DateTime utcSalesDate = DateTime.SpecifyKind(DateTime.Parse(magentoOrder.created_at), DateTimeKind.Utc);
            order.StoreCreatedAt =utcSalesDate.ToLocalTime();
            DateTime utcUpdateDate = DateTime.SpecifyKind(DateTime.Parse(magentoOrder.updated_at), DateTimeKind.Utc);
            order.StoreUpdatedAt = utcUpdateDate.ToLocalTime();
            order.StoreStatus = magentoOrder.status;

            var customFields = GetMagentoOrderCustomFields(int.Parse(magentoOrder.order_id));
            order.GiftMessageFrom = customFields.gift_message_sender;
            order.GiftMessageTo = customFields.gift_message_recipient;
            order.GiftMessageBody = customFields.gift_message;
            order.CustomerOrderComment = customFields.customer_comment;
            order.ShippingChargeCode = FreeShip(customFields.coupon_code,magentoOrder.shipping_method ) ? "FREESHIP" :"FREIGHT"; // or FREESHIP
            order.ShippingChargeAmount = FreeShip(customFields.coupon_code,magentoOrder.shipping_method) ? 0.0m : Decimal.Parse(magentoOrder.shipping_amount);

            order.EndDiscount = magentoOrder.customer_group_id.Trim() == "2" ? "RWC" : ""; // this is the whole sale group on magento
            order.PaymentMethod = MapPaymentMethod( magentoOrder);
            order.DeliveryMode = MapDeliveryMethod(magentoOrder);
            if(!string.IsNullOrWhiteSpace(magentoOrder.shipping_description))
                order.ShippingMethodDescription = ScrubShippingMethodDescription(magentoOrder.shipping_description);
            OrderService orderService = new OrderService();
            foreach(var line in magentoOrder.items)
            {
                order.AddLineItem(line.sku, line.name, Decimal.Parse(line.qty_ordered),
                                  Decimal.Parse(line.price),
                                  Decimal.Parse(line.row_total),
                                  orderService.GetItemSalesUoM(line.sku),
                                  orderService.GetItemPrice(line.sku),
                                  Decimal.Parse(line.discount_amount));
            }

            return order;
        }
示例#5
0
        public SalesOrder MapOrderFromStore(Order amazonOrder)
        {
            var order = new SalesOrder();
            order.OrderId = amazonOrder.AmazonOrderId;
            order.NativeId = amazonOrder.AmazonOrderId;
            order.StoreStatus = amazonOrder.OrderStatus.ToString();
            order.StoreCreatedAt = amazonOrder.PurchaseDate;
            order.StoreUpdatedAt = amazonOrder.LastUpdateDate;

            if(amazonOrder.IsSetShippingAddress())
            {
                order.DeliveryCustomerName = amazonOrder.ShippingAddress.Name;
                order.DeliveryStreet = amazonOrder.ShippingAddress.AddressLine1;
                if(!String.IsNullOrWhiteSpace(amazonOrder.ShippingAddress.AddressLine2))
                   order.DeliveryStreet += System.Environment.NewLine + amazonOrder.ShippingAddress.AddressLine2;
                if(!String.IsNullOrWhiteSpace(amazonOrder.ShippingAddress.AddressLine3))
                    order.DeliveryStreet += System.Environment.NewLine + amazonOrder.ShippingAddress.AddressLine3;
                order.DeliveryCity = amazonOrder.ShippingAddress.City;
                order.DeliveryState = amazonOrder.ShippingAddress.StateOrRegion;
                order.DeliveryZip = amazonOrder.ShippingAddress.PostalCode;
                order.DeliveryCountry = amazonOrder.ShippingAddress.CountryCode;
            }

            return order;
        }
示例#6
0
        public SalesOrder MapFromAmazonCache(dynamic amazonOrder)
        {
            var order = new SalesOrder();
            order.OrderId = amazonOrder.OrderNumber;
            order.NativeId = amazonOrder.StoreEntityId;
            order.StoreStatus = amazonOrder.StoreStatus;
            order.StoreCreatedAt = amazonOrder.StoreCreatedAt;
            order.StoreUpdatedAt = amazonOrder.StoreUpdatedAt;
            order.BillToCustomerName = amazonOrder.CustomerName;
            order.DeliveryCustomerName = amazonOrder.CustomerName;
            order.DeliveryStreet =amazonOrder.ShipStreet;
            order.DeliveryCity = amazonOrder.ShipCity;
            order.DeliveryState = amazonOrder.ShipState;
            order.DeliveryZip = amazonOrder.ShipZip;
            order.DeliveryCountry = amazonOrder.ShipCountry;

            return order;
        }
示例#7
0
        public void CreateAxSalesOrder(SalesOrder order,string storeName)
        {
            try
            {
                using(var ax = Login())
                {
                    ax.TTSBegin();

                    using (var rec = ax.CreateAxaptaRecord("SalesTable"))
                    {

                        // Provide values for each of the AddressState record fields.
                        AxSalesOrder.BuildDefaults(rec,storeName);

                        rec.set_Field(AxSalesOrder.SalesId, order.OrderId);
                        rec.set_Field(AxSalesOrder.SalesName, order.BillToCustomerName);
                        if(!string.IsNullOrWhiteSpace(order.CustomerEmail))
                            rec.set_Field(AxSalesOrder.Email, order.CustomerEmail);

                        rec.set_Field(AxSalesOrder.DeliveryAddress , order.DeliveryStreet + System.Environment.NewLine +
                                     order.DeliveryCity + ", " + order.DeliveryState + " " + order.DeliveryZip );
                        rec.set_Field(AxSalesOrder.DeliveryName,order.DeliveryCustomerName);
                        rec.set_Field(AxSalesOrder.DeliveryStreet, order.DeliveryStreet);
                        rec.set_Field(AxSalesOrder.DeliveryCity, order.DeliveryCity);
                        rec.set_Field(AxSalesOrder.DeliveryState, order.DeliveryState);
                        rec.set_Field(AxSalesOrder.DeliveryZipCode, order.DeliveryZip);
                        rec.set_Field(AxSalesOrder.DeliveryCountryRegionId, order.DeliveryCountry);
                        //newly added
                        rec.set_Field(AxSalesOrder.OrderDate, order.StoreCreatedAt);
                        if(!string.IsNullOrWhiteSpace(order.GiftMessageFrom))
                            rec.set_Field(AxSalesOrder.GiftMessageFrom, order.GiftMessageFrom);
                        if(!string.IsNullOrWhiteSpace(order.GiftMessageTo))
                            rec.set_Field(AxSalesOrder.GiftMessageTo, order.GiftMessageTo);
                        if(!string.IsNullOrWhiteSpace(order.GiftMessageBody))
                            rec.set_Field(AxSalesOrder.GiftMessageBody, order.GiftMessageBody);
                        if(!string.IsNullOrWhiteSpace(order.CustomerOrderComment))
                            rec.set_Field(AxSalesOrder.CustomerOrderComment, order.CustomerOrderComment);
                        if(!string.IsNullOrWhiteSpace(order.DeliveryMode))
                            rec.set_Field(AxSalesOrder.DeliveryMode, order.DeliveryMode);
                        if(!string.IsNullOrWhiteSpace(order.ShippingMethodDescription))
                            rec.set_Field(AxSalesOrder.ShippingMethodDescription, order.ShippingMethodDescription);
                        if(!string.IsNullOrWhiteSpace(order.EndDiscount))
                            rec.set_Field(AxSalesOrder.EndDiscount, order.EndDiscount);
                        if(PaymentMethodExists(order))
                            rec.set_Field(AxSalesOrder.PaymentMethod,order.PaymentMethod);

                        rec.Insert();

                    }
                    foreach (var line in order.LineItems)
                    {
                        using(var rec = ax.CreateAxaptaRecord("SalesLine"))
                        {
                            AxSalesOrder.LineBuildDefaults(rec, storeName);
                            // ToDo: need to verfiy what get from the store is the same in Ax or send alert
                            rec.set_Field(AxSalesOrder.SalesId, order.OrderId);
                            rec.set_Field(AxSalesOrder.LineNumber, line.LineNumber);
                            rec.set_Field(AxSalesOrder.LineItemId, line.ItemSku);
                            rec.set_Field(AxSalesOrder.LineItemName, line.ItemName);
                            rec.set_Field(AxSalesOrder.LineQuantityOrdered, line.Quantity);
                            rec.set_Field(AxSalesOrder.LineRemainSalesPhysical, line.Quantity);
                            rec.set_Field(AxSalesOrder.LineSalesQuantity, line.Quantity);
                            rec.set_Field(AxSalesOrder.LineRemainInventoryPhyscal, line.Quantity);
                            rec.set_Field(AxSalesOrder.LineSealesPrice, line.Price);
                            rec.set_Field(AxSalesOrder.LineAmount, line.StoreTotal);
                            rec.set_Field(AxSalesOrder.LineSalesMarkup, line.SalesMarkup);
                            if(!String.IsNullOrWhiteSpace(line.UnitOfMeasure))
                                rec.set_Field(AxSalesOrder.LineSalesUnit, line.UnitOfMeasure);

                            rec.set_Field(AxSalesOrder.LineDiscount,line.LineDiscount);

                            rec.Insert();
                        }
                    }

                    ax.TTSCommit();

                    ax.TTSBegin();

                    using(var rec = ax.CreateAxaptaRecord("MarkupTrans"))
                    {
                        AxSalesOrder.MarkupTransBuildDefaults(rec);
                        var recid = GetSalesOrderRecId(order.OrderId);
                        rec.set_Field(AxSalesOrder.TransRecId, recid);
                        rec.set_Field(AxSalesOrder.MarkUpCode, order.ShippingChargeCode);
                        var txt = order.ShippingChargeCode == "FREESHIP" ? "Free_Shipping_Now" : "Freight";
                        rec.set_Field(AxSalesOrder.MarkupTransTxt, txt );
                        rec.set_Field(AxSalesOrder.MarkupTransValue, order.ShippingChargeAmount);
                        rec.Insert();

                    }
                    ax.TTSCommit();

                    if(!string.IsNullOrWhiteSpace(order.BillToStreet))
                    {
                        ax.TTSBegin();
                        using(var rec = ax.CreateAxaptaRecord("Address"))
                        {
                            var recid = GetSalesOrderRecId(order.OrderId);
                            rec.set_Field(AxSalesOrder.AddrTableId,366);
                            rec.set_Field(AxSalesOrder.AddrRecId,recid);
                            rec.set_Field(AxSalesOrder.AddressType,1);

                            rec.set_Field(AxSalesOrder.AddressFullAddress , order.BillToStreet + System.Environment.NewLine +
                                         order.BillToCity + ", " + order.BillToState + " " + order.BillToZip );

                            rec.set_Field(AxSalesOrder.AddressName,order.BillToCustomerName);
                            rec.set_Field(AxSalesOrder.AddressStreet, order.BillToStreet);
                            rec.set_Field(AxSalesOrder.AddressCity, order.BillToCity);
                            rec.set_Field(AxSalesOrder.AddressState, order.BillToState);
                            rec.set_Field(AxSalesOrder.AddressZipCode, order.BillToZip);
                            rec.set_Field(AxSalesOrder.AddressCountryRegionId, order.BillToCountry);

                            rec.Insert();
                        }
                        ax.TTSCommit();
                    }

                }

                CreateProcessedOrder(order, storeName);

            }

            catch (Exception e)
            {
                NLog.LogManager.GetCurrentClassLogger().Error(e);
            }
        }
示例#8
0
 public void ProcessOrderChange(SalesOrder salesOrder)
 {
     NLog.LogManager.GetLogger("CanceledOrder").Info("Order : {0}   Just came in that replaces the original in AX, please verify for correctness.", salesOrder.OrderId);
     CreateProcessedOrder(salesOrder, "Magento");
 }
示例#9
0
        public bool PaymentMethodExists(SalesOrder order)
        {
            if(string.IsNullOrWhiteSpace(order.PaymentMethod))
                return false;

            var table = new CustPaymModeTable();
            if(table.All(where: "where PAYMMODE = @0", args: order.PaymentMethod, limit: 1).Any())
                return true;

            NLog.LogManager.GetCurrentClassLogger().Error("Payment method not foud Order: {0} Method: {1}", order.OrderId, order.PaymentMethod);
            return false;
        }
示例#10
0
 public void CreateProcessedOrder(SalesOrder order, string store)
 {
     var processedOrder = new ProcessedOrders();
     var newId = processedOrder.Insert(new {
                                       	Store = store,
                                       	StoreEntityId = order.NativeId,
                                       	OrderNumber = order.OrderId,
                                       	CreatedAt = DateTime.Now,
                                       	StoreCreatedAt = order.StoreCreatedAt,
                                       	StoreStatus = order.StoreStatus,
                                       	ShipStreet = order.DeliveryStreet,
                                       	StoreUpdatedAt = order.StoreUpdatedAt
                                       });
 }