Hi,
I have added the following code in OpcConfirmOrder()
var ordersToExport = new List<Order>() ;
ordersToExport.AddRange(_orderService.GetOrdersByIds(new int[] { placeOrderResult.PlacedOrder.Id }).Where(HasAccessToOrder));
ICacheManager cacheManager = EngineContext.Current.ContainerManager.Resolve<ICacheManager>("nop_cache_static");
IStoreService _storeService = EngineContext.Current.Resolve<IStoreService>();
ICategoryService _categoryService = EngineContext.Current.Resolve<ICategoryService>();
IManufacturerService _manufacturerService = MockRepository.GenerateMock<IManufacturerService>();
ICustomerService _customerService = EngineContext.Current.Resolve<ICustomerService>();
IProductAttributeService _productAttributeService = EngineContext.Current.Resolve<IProductAttributeService>();
IPictureService _pictureService = EngineContext.Current.Resolve<IPictureService>();
INewsLetterSubscriptionService _newsLetterSubscriptionService = EngineContext.Current.Resolve<INewsLetterSubscriptionService>();
ProductEditorSettings _productEditorSettings = new ProductEditorSettings();
IVendorService _vendorService = EngineContext.Current.Resolve<IVendorService>();
IProductTemplateService _productTemplateService = EngineContext.Current.Resolve<IProductTemplateService>();
IDateRangeService _dateRangeService = EngineContext.Current.Resolve<IDateRangeService>();
ITaxCategoryService _taxCategoryService = EngineContext.Current.Resolve<ITaxCategoryService>();
IMeasureService _measureService = EngineContext.Current.Resolve<IMeasureService>();
CatalogSettings _catalogSettings = new CatalogSettings();
IGenericAttributeService _genericAttributeService = EngineContext.Current.Resolve<IGenericAttributeService>();
ICustomerAttributeFormatter _customerAttributeFormatter = EngineContext.Current.Resolve<ICustomerAttributeFormatter>();
ExportManager exportManager = new ExportManager(_categoryService, _manufacturerService, _customerService,
_productAttributeService,
_pictureService, _newsLetterSubscriptionService,
_storeService, _workContext, _productEditorSettings,
_vendorService, _productTemplateService, _dateRangeService,
_taxCategoryService, _measureService, _catalogSettings,
_genericAttributeService, _customerAttributeFormatter,
_orderSettings);
try {
var xml = exportManager.ExportOrdersToXml(ordersToExport);
XmlDownloadResult xmlResult = new XmlDownloadResult(xml, "orders.xml");
xmlResult.ExecuteResult(this.ControllerContext);
}
catch (Exception exc) {
ErrorNotification(exc);
}
I have added the above code immediately after:
var placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest);
if (placeOrderResult.Success)
{
_httpContext.Session["OrderPaymentInfo"] = null;
var postProcessPaymentRequest = new PostProcessPaymentRequest
{
Order = placeOrderResult.PlacedOrder
};
The code runs through but there is no orders.xml file. Also, I have noticed that when this code is executed from the Export Selected Orders to Xml Menu item in Administration,
[HttpPost]
public virtual ActionResult ExportXmlSelected(string selectedIds)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();
var orders = new List<Order>();
if (selectedIds != null)
{
var ids = selectedIds
.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => Convert.ToInt32(x))
.ToArray();
orders.AddRange(_orderService.GetOrdersByIds(ids).Where(HasAccessToOrder));
}
var xml = _exportManager.ExportOrdersToXml(orders);
return new XmlDownloadResult(xml, "orders.xml");
}
the orders list that is passed to _exportManager.ExportOrdersToXml(orders) ; has the type:
System.Data.Entity.DynamicProxies.Order where as the code I have put in OpcConfirmOrder() , the ordersToExport list passed to exportManager.ExportOrdersToXml(orders) has the type Nop.Core.Domain.Orders.Order .
Does this make a difference?
Also, I was not sure how to instantiate _manufacturerService so I instantiated it with MockRepository. I don't know if this makes a difference or not.
Saad