public async Task <IActionResult> SetAsDelivered(string id) { var shipment = await _shipmentService.GetShipmentById(id); if (shipment == null) { //No shipment found with the specified id return(RedirectToAction("List")); } if (_workContext.CurrentCustomer.IsStaff() && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId) { return(RedirectToAction("List")); } var order = await _orderService.GetOrderById(shipment.OrderId); if (order == null) { //No order found with the specified id return(RedirectToAction("List")); } //a vendor should have access only to his products if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !_workContext.CurrentCustomer.IsStaff()) { return(RedirectToAction("List")); } try { await _orderProcessingService.Deliver(shipment, true); return(RedirectToAction("ShipmentDetails", new { id = shipment.Id })); } catch (Exception exc) { //error ErrorNotification(exc, true); return(RedirectToAction("ShipmentDetails", new { id = shipment.Id })); } }
/// <summary> /// Marks a shipment as delivered /// </summary> /// <param name="shipment">Shipment</param> /// <param name="notifyCustomer">True to notify customer</param> public void Deliver(Shipment shipment, bool notifyCustomer) { _orderProcessingService.Deliver(shipment, notifyCustomer); }
/// <summary> /// ScheduleTask Execute Method /// </summary> public void Execute() { var storeScope = _storeContext.ActiveStoreScopeConfiguration; var ShipRocketSettings = _settingService.LoadSetting <ShipRocketSetting>(storeScope); if (ShipRocketSettings.Enable) { var ShiprocketUserName = _ShipRocketSeting.UserEmail; var ShipRocketBaseUrl = _ShipRocketSeting.BaseURL; var ShipRocketPassword = _ShipRocketSeting.Password; if (ShiprocketUserName != null && ShipRocketBaseUrl != null && ShipRocketPassword != null) { try { var allOrder = _ShipRocketService.GetAllShiprocketOrder(); if (allOrder.Count() > 0) { ShipRocketApiConfiguration rocket = new ShipRocketApiConfiguration(); var token = rocket.GetTocket(ShipRocketBaseUrl, ShiprocketUserName, ShipRocketPassword); if (token.Contains("token")) { ShipRocketTokenResponse Responses = JsonConvert.DeserializeObject <ShipRocketTokenResponse>(token); if (Responses != null) { if (!string.IsNullOrEmpty(Responses.token)) { foreach (var a in allOrder) { var order = _OrderService.GetOrderById(a.OrderId); if (!order.Deleted) { if (order.PaymentMethodSystemName == "Payments.CashOnDelivery") { ProccedShiprocket(order, Responses.token.Trim(), ShipRocketBaseUrl, a, true); } else { ProccedShiprocket(order, Responses.token.Trim(), ShipRocketBaseUrl, a); } } } } } } else { _LoggerService.InsertLog(LogLevel.Error, "There was a problem for getting token" + token); } } } catch (Exception Ex) { _LoggerService.InsertLog(LogLevel.Error, "Getting Exception in shiprocket scheduletask" + Ex.Message, Ex.InnerException.ToString()); } } else { _LoggerService.InsertLog(LogLevel.Error, "Can not get Ship rocket credential please enter this credential in all setting", "ShipRocketSeting.UserName, ShipRocketSeting.UserName,ShipRocketSeting.Password"); } List <int> ssid = new List <int>(); ssid.Add(30); var pendingOrder = _OrderService.SearchOrders(ssIds: ssid); ShipRocketApiConfiguration rocket1 = new ShipRocketApiConfiguration(); var token1 = rocket1.GetTocket(ShipRocketBaseUrl, ShiprocketUserName, ShipRocketPassword); if (token1.Contains("token")) { ShipRocketTokenResponse Responses = JsonConvert.DeserializeObject <ShipRocketTokenResponse>(token1); foreach (var p in pendingOrder) { var orderShiprocketMap = _ShipRocketService.GetShiprocketOrderByOrderId(p.Id); if (orderShiprocketMap != null) { var orderStatus = rocket1.GetShiprocketOrderStatus(Responses.token.Trim(), ShipRocketBaseUrl, Convert.ToInt32(orderShiprocketMap.ShiprocketOrderId)); if (!string.IsNullOrEmpty(orderStatus)) { if (orderStatus == "DELIVERED") { var Shipments = _shipmentService.GetShipmentsByOrderId(p.Id); foreach (var shipment in Shipments) { try { if (!shipment.DeliveryDateUtc.HasValue) { _orderProcessingService.Deliver(Shipments.FirstOrDefault(), true); _customerActivityService.InsertActivity("EditOrder", string.Format(_localizationService.GetResource("ActivityLog.EditOrder"), p.CustomOrderNumber), p); } } catch (Exception exc) { var customer = workContext.CurrentCustomer; _logger.Error(exc.Message, exc, customer); } } } } } } } } }