public ActionResult MergeProductPopup(int Id, string btnIdToRefresh, string frmIdToRefresh, MergeProductModel model) //hidden variable on form as well as model { //TODO: permissions to copy product //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) // return AccessDeniedView(); //As yet don;t need config settings to decide onything for copyproduct //var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); //var AUConsignorSettings = _settings.LoadSetting<AUConsignorSettings>(storeScope); //if AUConsignorSettings.StoreTypeId = AUStoreTypeEnum.InternetAuction {.....} try { if (model.NewSku == "") { ErrorNotification("Products could not be merged because a new SKU was not provided. Please try again and provide a New SKU"); return RedirectToAction("ListLots", "AUConsignor"); } //check to make sure the New Sku does not already exist as this is the promary key for the client var targetProduct = _productService.GetProductBySku(model.NewSku); if (targetProduct == null) { ErrorNotification("Product could not be merged because the target Product does not already exist - try again with a New SKU"); return RedirectToAction("ListLots", "AUConsignor"); } var targetLot = _consignorService.GetLotBySku(model.NewSku); if (targetLot == null) { ErrorNotification("Product could not be merged because the target Lot does not already exist - try again with a New SKU"); return RedirectToAction("ListLots", "AUConsignor"); } string ProductsIdsToMerge = model.ProductsIdsToMerge; int[] fromIds = Array.ConvertAll(ProductsIdsToMerge.Split(','), int.Parse); string returnMessage = ""; foreach(int fromId in fromIds) { //see if from-to junction already created because they might inadvertantly select a product already merged to this product var lotlot = _lotService.CheckIfLotAlreadyCopied(fromId, targetProduct.Id); if (lotlot != null) { var originalProduct = _productService.GetProductById(fromId); if (originalProduct == null) throw new ArgumentException("Source product id not found: " + fromId.ToString() + " Please notify Admin"); var originalLot = _consignorService.GetLotByProductId(fromId); if (originalLot == null) throw new ArgumentException("Source lot not found for product id : " + fromId.ToString() + " Please notify Admin"); //TODO: a vendor should have access only to his products. Need to bring in workcontext //if (_workContext.CurrentVendor != null && originalProduct.VendorId != _workContext.CurrentVendor.Id) // return RedirectToAction("ManageProducts", "AUConsignor"); //---> make this ManageProducts? // you won't copy a lot if it's a retail store - you don't need to check the store config though because a lot will only be alloed // to exist in in Internet Auction Bidding, Internet Auction and Live Bidding, and Mixed Retail stores. Lots are not allowed in // "Original Retail " stores. The check for a null lot will also avoid if somehow lot is missing in a corrunt lot situation //TODO: this should not be null as currently manage products only showing lots. When you change it to show mixed products & lots, you need to make sure //that Merge can only happen for lots if (originalLot != null) { _lotService.CreateLotLot(originalProduct.Id, targetProduct.Id, originalLot.AULotID, targetLot.AULotID); } //else //{ // returnMessage = returnMessage + "- there was no associated lot/consignor information to copy. "; //} if (model.UnPublishOld && originalProduct.Published == true) //Unpublishold will be true for Merge Product phase I { originalProduct.Published = false; _productService.UpdateProduct(originalProduct); returnMessage = returnMessage + "The original product was unpublished. "; } } } SuccessNotification("The products have been merged into the new sku and unpublished"); //This will cause the popup to force a refresh of the originating page and close the popup ViewBag.RefreshPage = true; ViewBag.newProductId = targetProduct.Id; ViewBag.btnId = btnIdToRefresh; ViewBag.formId = frmIdToRefresh; //TODO: ADD TEST TO SEE IF COPYPRODUCT OR SPLITPRODUCT (FROM PARM) ALSO DETERMIN IF SOURCE PRODUCT SHOULD BE INACTIVATED return View("MergeProduct", model); } catch (Exception exc) { ErrorNotification(exc.Message); return RedirectToAction("List", "Product", new { id = model.Id }); } }
public ActionResult MergeProductPopup(int Id, string Name, string btnId, string SelectedIds, bool Published = true, bool CopyImages = false, string formId = null) { //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) // return View("~/Administration/Views/Security/AccessDenied.cshtml"); //var originalProduct = _productService.GetProductById(Id); //if (originalProduct == null) //{ // ErrorNotification("Fatal error - product id passed into copyproduct not found - please notify Administrator"); // return RedirectToAction("List", "Product"); //} var model = new MergeProductModel(); //using same search model as ManageSales - Note no constructor //a vendor should have access only to his products. Set the indicator in the model //model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; model.Id = Id; model.Name = Name; model.Published = Published; model.CopyImages = CopyImages; model.UnPublishOld = true; model.ProductsIdsToMerge = SelectedIds; //model.OriginalProductPublished = originalProduct.Published; return View("MergeProduct", model); }