コード例 #1
0
        /// <summary>
        /// Handle the order placed event
        /// </summary>
        /// <param name="eventMessage">The event message.</param>
        public void HandleEvent(OrderPlacedEvent eventMessage)
        {
            var order = eventMessage.Order;

            var customer    = _customerService.GetCustomerById(order.CustomerId);
            var shipAddress = _addressService.GetAddressById((int)order.ShippingAddressId);

            var model = new SAPOrderModel()
            {
                OrderNumber          = order.Id,
                CustFName            = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FirstNameAttribute),
                CustLName            = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.LastNameAttribute),
                ShipAddress          = shipAddress?.Address1 + "," + shipAddress?.Address2,
                ShipCity             = shipAddress?.City,
                ShippingStatusId     = order.ShippingStatusId,
                OrderStatusId        = order.OrderStatusId,
                PaymentMetod         = order.PaymentMethodSystemName,
                OrderSubtotalInclTax = order.OrderSubtotalInclTax,
                OrderSubtotalExclTax = order.OrderSubtotalExclTax,
                OrderTotal           = order.OrderTotal,
                ShippingMethod       = order.ShippingMethod
            };
            var orderItem = _orderService.GetOrderItems(order.Id);

            foreach (var item in orderItem)
            {
                var product = _productService.GetProductById(item.ProductId);
                model.OrderItem.Add(new SAPOrderItemModel()
                {
                    OrderNumber = order.Id,
                    ProductName = product?.Name,
                    Quantity    = item.Quantity,
                    Price       = item.UnitPriceInclTax,
                    ItemWeight  = (decimal)item.ItemWeight
                });
            }

            _sAPIntegrationService.SyncOrderToSAP(model);
        }
コード例 #2
0
        public void SyncOrderToSAP(SAPOrderModel model)
        {
            var token = GetToken(model.OrderNumber);

            var client = new RestClient($"{_sAPSettings.SapAPI}User/OrderSubmit");

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", $"Bearer {token}");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JsonConvert.SerializeObject(model), ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            if (response.IsSuccessful)
            {
                _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, $"Order Synced {model.OrderNumber}", response.Content);
            }
            else
            {
                _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, $"Order not Synced {model.OrderNumber}", response.Content);
            }
        }