Browse Source

Product duplication with attaching to parent

Vova Tkach 5 years ago
parent
commit
65805c199c
4 changed files with 18 additions and 3 deletions
  1. 10 1
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go
  3. 1 1
      modules/module_shop.go
  4. 7 1
      modules/module_shop_act_duplicate.go

+ 10 - 1
assets/cp.scripts.js

@@ -7525,7 +7525,7 @@
 				});
 			},
 
-			ShopProductsDuplicate: function(button, product_id) {
+			ShopProductsDuplicateBase: function(button, product_id, attach) {
 				if($(button).hasClass('in-progress')) return;
 				if(FormDataIsChanged()) {
 					fave.ShowMsgError('Warning!', 'Something was changed, save changes before duplicate product', true);
@@ -7538,6 +7538,7 @@
 					data: {
 						action: 'shop-duplicate',
 						id: product_id,
+						attach: attach,
 					}
 				}).done(function(data) {
 					try {
@@ -7562,6 +7563,14 @@
 				});
 			},
 
+			ShopProductsDuplicate: function(button, product_id) {
+				fave.ShopProductsDuplicateBase(button, product_id, 0);
+			},
+
+			ShopProductsDuplicateWithAttach: function(button, product_id) {
+				fave.ShopProductsDuplicateBase(button, product_id, 1);
+			},
+
 			ShopProductsRetryImage: function(img, id) {
 				var target = $('#' + id);
 				var src = target.attr('src');

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 1 - 1
modules/module_shop.go

@@ -802,7 +802,7 @@ func (this *Modules) RegisterModule_Shop() *Module {
 			} else {
 				if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
 					content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
-					content += `<div class="product-another"><a title="The same with another attributes" href="javascript:fave.ShopProductsAnother(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
+					content += `<div class="product-another"><a title="Duplicate product and attach to this" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
 				}
 				content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
 					{Name: "Modify product"},

+ 7 - 1
modules/module_shop_act_duplicate.go

@@ -14,6 +14,7 @@ func (this *Modules) RegisterAction_ShopDuplicate() *Action {
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_id := wrap.R.FormValue("id")
+		pf_attach := wrap.R.FormValue("attach")
 
 		if !utils.IsNumeric(pf_id) {
 			wrap.MsgError(`Inner system error`)
@@ -33,6 +34,11 @@ func (this *Modules) RegisterAction_ShopDuplicate() *Action {
 				return err
 			}
 
+			parent_id := "parent_id"
+			if pf_attach == "1" {
+				parent_id = pf_id
+			}
+
 			// Duplicate product
 			res, err := tx.Exec(
 				`INSERT INTO shop_products (
@@ -50,7 +56,7 @@ func (this *Modules) RegisterAction_ShopDuplicate() *Action {
 					datetime,
 					active
 				) SELECT
-					parent_id,
+					`+parent_id+`,
 					user,
 					currency,
 					price,

Some files were not shown because too many files changed in this diff