module_shop.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. package modules
  2. import (
  3. "html"
  4. "net/http"
  5. "strings"
  6. "golang-fave/assets"
  7. "golang-fave/consts"
  8. "golang-fave/engine/builder"
  9. "golang-fave/engine/fetdata"
  10. "golang-fave/engine/sqlw"
  11. "golang-fave/engine/wrapper"
  12. "golang-fave/utils"
  13. )
  14. func (this *Modules) shop_GetCurrencySelectOptions(wrap *wrapper.Wrapper, id int) string {
  15. result := ``
  16. rows, err := wrap.DB.Query(
  17. `SELECT
  18. id,
  19. code
  20. FROM
  21. shop_currencies
  22. ORDER BY
  23. id ASC
  24. ;`,
  25. )
  26. if err == nil {
  27. defer rows.Close()
  28. values := make([]string, 2)
  29. scan := make([]interface{}, len(values))
  30. for i := range values {
  31. scan[i] = &values[i]
  32. }
  33. idStr := utils.IntToStr(id)
  34. for rows.Next() {
  35. err = rows.Scan(scan...)
  36. if err == nil {
  37. selected := ""
  38. if string(values[0]) == idStr {
  39. selected = " selected"
  40. }
  41. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `"` + selected + `>` + html.EscapeString(string(values[1])) + `</option>`
  42. }
  43. }
  44. }
  45. return result
  46. }
  47. func (this *Modules) shop_GetProductValuesInputs(wrap *wrapper.Wrapper, product_id int) string {
  48. result := ``
  49. rows, err := wrap.DB.Query(
  50. `SELECT
  51. shop_filters.id,
  52. shop_filters.name,
  53. shop_filters_values.id,
  54. shop_filters_values.name,
  55. IF(shop_filter_product_values.filter_value_id > 0, 1, 0) as selected
  56. FROM
  57. shop_filters_values
  58. LEFT JOIN shop_filters ON shop_filters.id = shop_filters_values.filter_id
  59. LEFT JOIN shop_filter_product_values ON
  60. shop_filter_product_values.filter_value_id = shop_filters_values.id AND
  61. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
  62. LEFT JOIN (
  63. SELECT
  64. shop_filters_values.filter_id,
  65. shop_filter_product_values.product_id
  66. FROM
  67. shop_filter_product_values
  68. LEFT JOIN shop_filters_values ON shop_filters_values.id = shop_filter_product_values.filter_value_id
  69. WHERE
  70. shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
  71. GROUP BY
  72. shop_filters_values.filter_id
  73. ) as filter_used ON filter_used.filter_id = shop_filters.id
  74. WHERE
  75. filter_used.filter_id IS NOT NULL
  76. ORDER BY
  77. shop_filters.name ASC,
  78. shop_filters_values.name ASC
  79. ;`,
  80. )
  81. filter_ids := []int{}
  82. filter_names := map[int]string{}
  83. filter_values := map[int][]string{}
  84. if err == nil {
  85. defer rows.Close()
  86. values := make([]string, 5)
  87. scan := make([]interface{}, len(values))
  88. for i := range values {
  89. scan[i] = &values[i]
  90. }
  91. for rows.Next() {
  92. err = rows.Scan(scan...)
  93. if err == nil {
  94. filter_id := utils.StrToInt(string(values[0]))
  95. if !utils.InArrayInt(filter_ids, filter_id) {
  96. filter_ids = append(filter_ids, filter_id)
  97. }
  98. filter_names[filter_id] = html.EscapeString(string(values[1]))
  99. selected := ``
  100. if utils.StrToInt(string(values[4])) == 1 {
  101. selected = ` selected`
  102. }
  103. filter_values[filter_id] = append(filter_values[filter_id], `<option value="`+html.EscapeString(string(values[2]))+`"`+selected+`>`+html.EscapeString(string(values[3]))+`</option>`)
  104. }
  105. }
  106. }
  107. for _, filter_id := range filter_ids {
  108. result += `<div class="form-group" id="prod_attr_` + utils.IntToStr(filter_id) + `">` +
  109. `<div><b>` + filter_names[filter_id] + `</b></div>` +
  110. `<div class="position-relative">` +
  111. `<select class="selectpicker form-control" name="value.` + utils.IntToStr(filter_id) + `" autocomplete="off" required multiple>` +
  112. strings.Join(filter_values[filter_id], "") +
  113. `</select>` +
  114. `<button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopProductsRemove(this);">&times;</button>` +
  115. `</div>` +
  116. `</div>`
  117. }
  118. return result
  119. }
  120. func (this *Modules) shop_GetFilterValuesInputs(wrap *wrapper.Wrapper, filter_id int) string {
  121. result := ``
  122. rows, err := wrap.DB.Query(
  123. `SELECT
  124. id,
  125. name
  126. FROM
  127. shop_filters_values
  128. WHERE
  129. filter_id = ?
  130. ORDER BY
  131. name ASC
  132. ;`,
  133. filter_id,
  134. )
  135. if err == nil {
  136. defer rows.Close()
  137. values := make([]string, 2)
  138. scan := make([]interface{}, len(values))
  139. for i := range values {
  140. scan[i] = &values[i]
  141. }
  142. for rows.Next() {
  143. err = rows.Scan(scan...)
  144. if err == nil {
  145. result += `<div class="form-group position-relative"><input class="form-control" type="text" name="value.` + html.EscapeString(string(values[0])) + `" value="` + html.EscapeString(string(values[1])) + `" placeholder="" autocomplete="off" required><button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopAttributesRemove(this);">&times;</button></div>`
  146. }
  147. }
  148. }
  149. return result
  150. }
  151. func (this *Modules) shop_GetAllAttributesSelectOptions(wrap *wrapper.Wrapper) string {
  152. result := ``
  153. rows, err := wrap.DB.Query(
  154. `SELECT
  155. id,
  156. name,
  157. filter
  158. FROM
  159. shop_filters
  160. ORDER BY
  161. name ASC
  162. ;`,
  163. )
  164. result += `<option title="&mdash;" value="0">&mdash;</option>`
  165. if err == nil {
  166. defer rows.Close()
  167. values := make([]string, 3)
  168. scan := make([]interface{}, len(values))
  169. for i := range values {
  170. scan[i] = &values[i]
  171. }
  172. for rows.Next() {
  173. err = rows.Scan(scan...)
  174. if err == nil {
  175. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `">` + html.EscapeString(string(values[1])) + `</option>`
  176. }
  177. }
  178. }
  179. return result
  180. }
  181. func (this *Modules) shop_GetAllCurrencies(wrap *wrapper.Wrapper) map[int]string {
  182. result := map[int]string{}
  183. rows, err := wrap.DB.Query(
  184. `SELECT
  185. id,
  186. code
  187. FROM
  188. shop_currencies
  189. ORDER BY
  190. id ASC
  191. ;`,
  192. )
  193. if err == nil {
  194. defer rows.Close()
  195. values := make([]string, 2)
  196. scan := make([]interface{}, len(values))
  197. for i := range values {
  198. scan[i] = &values[i]
  199. }
  200. for rows.Next() {
  201. err = rows.Scan(scan...)
  202. if err == nil {
  203. result[utils.StrToInt(string(values[0]))] = html.EscapeString(string(values[1]))
  204. }
  205. }
  206. }
  207. return result
  208. }
  209. func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id int) string {
  210. result := ``
  211. rows, err := wrap.DB.Query(
  212. `SELECT
  213. id,
  214. product_id,
  215. filename
  216. FROM
  217. shop_product_images
  218. WHERE
  219. product_id = ?
  220. ORDER BY
  221. ord ASC
  222. ;`,
  223. product_id,
  224. )
  225. if err == nil {
  226. defer rows.Close()
  227. values := make([]string, 3)
  228. scan := make([]interface{}, len(values))
  229. for i := range values {
  230. scan[i] = &values[i]
  231. }
  232. for rows.Next() {
  233. err = rows.Scan(scan...)
  234. if err == nil {
  235. result += `<div class="attached-img" data-id="` + html.EscapeString(string(values[0])) + `"><a href="/products/images/` + html.EscapeString(string(values[1])) + `/` + html.EscapeString(string(values[2])) + `" title="` + html.EscapeString(string(values[2])) + `" target="_blank"><img id="pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `" src="/products/images/` + string(values[1]) + `/thumb-0-` + string(values[2]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, 'pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[1])) + `, '` + html.EscapeString(string(values[2])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
  236. }
  237. }
  238. }
  239. return result
  240. }
  241. func (this *Modules) RegisterModule_Shop() *Module {
  242. return this.newModule(MInfo{
  243. WantDB: true,
  244. Mount: "shop",
  245. Name: "Shop",
  246. Order: 2,
  247. System: false,
  248. Icon: assets.SysSvgIconList,
  249. Sub: &[]MISub{
  250. {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
  251. {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
  252. {Mount: "modify", Name: "Modify product", Show: false},
  253. {Sep: true, Show: true},
  254. {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
  255. {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
  256. {Mount: "categories-modify", Name: "Modify category", Show: false},
  257. {Sep: true, Show: true},
  258. {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
  259. {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
  260. {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
  261. {Sep: true, Show: true},
  262. {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
  263. {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
  264. {Mount: "currencies-modify", Name: "Modify currency", Show: false},
  265. },
  266. }, func(wrap *wrapper.Wrapper) {
  267. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  268. // Shop category
  269. row := &utils.MySql_shop_category{}
  270. rou := &utils.MySql_user{}
  271. err := wrap.DB.QueryRow(`
  272. SELECT
  273. main.id,
  274. main.user,
  275. main.name,
  276. main.alias,
  277. main.lft,
  278. main.rgt,
  279. main.depth,
  280. parent.id AS parent_id,
  281. users.id,
  282. users.first_name,
  283. users.last_name,
  284. users.email,
  285. users.admin,
  286. users.active
  287. FROM
  288. (
  289. SELECT
  290. node.id,
  291. node.user,
  292. node.name,
  293. node.alias,
  294. node.lft,
  295. node.rgt,
  296. (COUNT(parent.id) - 1) AS depth
  297. FROM
  298. shop_cats AS node,
  299. shop_cats AS parent
  300. WHERE
  301. node.lft BETWEEN parent.lft AND parent.rgt
  302. GROUP BY
  303. node.id
  304. ORDER BY
  305. node.lft ASC
  306. ) AS main
  307. LEFT JOIN (
  308. SELECT
  309. node.id,
  310. node.user,
  311. node.name,
  312. node.alias,
  313. node.lft,
  314. node.rgt,
  315. (COUNT(parent.id) - 0) AS depth
  316. FROM
  317. shop_cats AS node,
  318. shop_cats AS parent
  319. WHERE
  320. node.lft BETWEEN parent.lft AND parent.rgt
  321. GROUP BY
  322. node.id
  323. ORDER BY
  324. node.lft ASC
  325. ) AS parent ON
  326. parent.depth = main.depth AND
  327. main.lft > parent.lft AND
  328. main.rgt < parent.rgt
  329. LEFT JOIN users ON users.id = main.user
  330. WHERE
  331. main.id > 1 AND
  332. main.alias = ?
  333. ORDER BY
  334. main.lft ASC
  335. ;`,
  336. wrap.UrlArgs[2],
  337. ).Scan(
  338. &row.A_id,
  339. &row.A_user,
  340. &row.A_name,
  341. &row.A_alias,
  342. &row.A_lft,
  343. &row.A_rgt,
  344. &row.A_depth,
  345. &row.A_parent,
  346. &rou.A_id,
  347. &rou.A_first_name,
  348. &rou.A_last_name,
  349. &rou.A_email,
  350. &rou.A_admin,
  351. &rou.A_active,
  352. )
  353. if err != nil && err != wrapper.ErrNoRows {
  354. // System error 500
  355. utils.SystemErrorPageEngine(wrap.W, err)
  356. return
  357. } else if err == wrapper.ErrNoRows {
  358. // User error 404 page
  359. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  360. return
  361. }
  362. // Fix url
  363. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  364. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  365. return
  366. }
  367. // Render template
  368. wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
  369. return
  370. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  371. // Shop product
  372. row := &utils.MySql_shop_product{}
  373. rou := &utils.MySql_user{}
  374. err := wrap.DB.QueryRow(`
  375. SELECT
  376. shop_products.id,
  377. shop_products.user,
  378. shop_products.currency,
  379. shop_products.price,
  380. shop_products.name,
  381. shop_products.alias,
  382. shop_products.vendor,
  383. shop_products.quantity,
  384. shop_products.category,
  385. shop_products.briefly,
  386. shop_products.content,
  387. UNIX_TIMESTAMP(shop_products.datetime) as datetime,
  388. shop_products.active,
  389. users.id,
  390. users.first_name,
  391. users.last_name,
  392. users.email,
  393. users.admin,
  394. users.active
  395. FROM
  396. shop_products
  397. LEFT JOIN users ON users.id = shop_products.user
  398. WHERE
  399. shop_products.active = 1 and
  400. shop_products.alias = ?
  401. LIMIT 1;`,
  402. wrap.UrlArgs[1],
  403. ).Scan(
  404. &row.A_id,
  405. &row.A_user,
  406. &row.A_currency,
  407. &row.A_price,
  408. &row.A_name,
  409. &row.A_alias,
  410. &row.A_vendor,
  411. &row.A_quantity,
  412. &row.A_category,
  413. &row.A_briefly,
  414. &row.A_content,
  415. &row.A_datetime,
  416. &row.A_active,
  417. &rou.A_id,
  418. &rou.A_first_name,
  419. &rou.A_last_name,
  420. &rou.A_email,
  421. &rou.A_admin,
  422. &rou.A_active,
  423. )
  424. if err != nil && err != wrapper.ErrNoRows {
  425. // System error 500
  426. utils.SystemErrorPageEngine(wrap.W, err)
  427. return
  428. } else if err == wrapper.ErrNoRows {
  429. // User error 404 page
  430. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  431. return
  432. }
  433. // Fix url
  434. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  435. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  436. return
  437. }
  438. // Render template
  439. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
  440. return
  441. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  442. // Shop
  443. // Fix url
  444. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  445. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  446. return
  447. }
  448. // Render template
  449. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  450. return
  451. } else if (*wrap.Config).Engine.MainModule == 2 {
  452. // Render template
  453. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  454. return
  455. }
  456. // User error 404 page
  457. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  458. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  459. content := ""
  460. sidebar := ""
  461. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  462. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  463. {Name: "List of products"},
  464. })
  465. // Load currencies
  466. currencies := this.shop_GetAllCurrencies(wrap)
  467. content += builder.DataTable(
  468. wrap,
  469. "shop_products",
  470. "id",
  471. "DESC",
  472. &[]builder.DataTableRow{
  473. {
  474. DBField: "id",
  475. },
  476. {
  477. DBField: "name",
  478. NameInTable: "Product / URL",
  479. CallBack: func(values *[]string) string {
  480. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  481. alias := html.EscapeString((*values)[2])
  482. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>`
  483. },
  484. },
  485. {
  486. DBField: "alias",
  487. },
  488. {
  489. DBField: "currency",
  490. },
  491. {
  492. DBField: "price",
  493. NameInTable: "Price",
  494. Classes: "d-none d-md-table-cell",
  495. CallBack: func(values *[]string) string {
  496. return `<div>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  497. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  498. },
  499. },
  500. {
  501. DBField: "datetime",
  502. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  503. NameInTable: "Date / Time",
  504. Classes: "d-none d-lg-table-cell",
  505. CallBack: func(values *[]string) string {
  506. t := int64(utils.StrToInt((*values)[5]))
  507. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  508. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  509. },
  510. },
  511. {
  512. DBField: "active",
  513. NameInTable: "Active",
  514. Classes: "d-none d-sm-table-cell",
  515. CallBack: func(values *[]string) string {
  516. return builder.CheckBox(utils.StrToInt((*values)[6]))
  517. },
  518. },
  519. },
  520. func(values *[]string) string {
  521. return builder.DataTableAction(&[]builder.DataTableActionRow{
  522. {
  523. Icon: assets.SysSvgIconView,
  524. Href: `/shop/` + (*values)[2] + `/`,
  525. Hint: "View",
  526. Target: "_blank",
  527. },
  528. {
  529. Icon: assets.SysSvgIconEdit,
  530. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  531. Hint: "Edit",
  532. },
  533. {
  534. Icon: assets.SysSvgIconRemove,
  535. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  536. (*values)[0] + "','Are you sure want to delete product?');",
  537. Hint: "Delete",
  538. Classes: "delete",
  539. },
  540. })
  541. },
  542. "/cp/"+wrap.CurrModule+"/",
  543. nil,
  544. nil,
  545. true,
  546. )
  547. } else if wrap.CurrSubModule == "categories" {
  548. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  549. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  550. {Name: "List of categories"},
  551. })
  552. content += builder.DataTable(
  553. wrap,
  554. "shop_cats",
  555. "id",
  556. "ASC",
  557. &[]builder.DataTableRow{
  558. {
  559. DBField: "id",
  560. },
  561. {
  562. DBField: "user",
  563. },
  564. {
  565. DBField: "name",
  566. NameInTable: "Category",
  567. CallBack: func(values *[]string) string {
  568. depth := utils.StrToInt((*values)[4]) - 1
  569. if depth < 0 {
  570. depth = 0
  571. }
  572. sub := strings.Repeat("&mdash; ", depth)
  573. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  574. return `<div>` + name + `</div>`
  575. },
  576. },
  577. {
  578. DBField: "alias",
  579. },
  580. {
  581. DBField: "depth",
  582. },
  583. },
  584. func(values *[]string) string {
  585. return builder.DataTableAction(&[]builder.DataTableActionRow{
  586. {
  587. Icon: assets.SysSvgIconView,
  588. Href: `/shop/category/` + (*values)[3] + `/`,
  589. Hint: "View",
  590. Target: "_blank",
  591. },
  592. {
  593. Icon: assets.SysSvgIconEdit,
  594. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  595. Hint: "Edit",
  596. },
  597. {
  598. Icon: assets.SysSvgIconRemove,
  599. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  600. (*values)[0] + "','Are you sure want to delete category?');",
  601. Hint: "Delete",
  602. Classes: "delete",
  603. },
  604. })
  605. },
  606. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  607. nil,
  608. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  609. return wrap.DB.Query(
  610. `SELECT
  611. node.id,
  612. node.user,
  613. node.name,
  614. node.alias,
  615. (COUNT(parent.id) - 1) AS depth
  616. FROM
  617. shop_cats AS node,
  618. shop_cats AS parent
  619. WHERE
  620. node.lft BETWEEN parent.lft AND parent.rgt AND
  621. node.id > 1
  622. GROUP BY
  623. node.id
  624. ORDER BY
  625. node.lft ASC
  626. ;`,
  627. )
  628. },
  629. false,
  630. )
  631. } else if wrap.CurrSubModule == "attributes" {
  632. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  633. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  634. {Name: "List of attributes"},
  635. })
  636. content += builder.DataTable(
  637. wrap,
  638. "shop_filters",
  639. "id",
  640. "DESC",
  641. &[]builder.DataTableRow{
  642. {
  643. DBField: "id",
  644. },
  645. {
  646. DBField: "name",
  647. NameInTable: "Name",
  648. CallBack: func(values *[]string) string {
  649. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  650. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  651. },
  652. },
  653. {
  654. DBField: "filter",
  655. },
  656. },
  657. func(values *[]string) string {
  658. return builder.DataTableAction(&[]builder.DataTableActionRow{
  659. {
  660. Icon: assets.SysSvgIconEdit,
  661. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  662. Hint: "Edit",
  663. },
  664. {
  665. Icon: assets.SysSvgIconRemove,
  666. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  667. (*values)[0] + "','Are you sure want to delete attribute?');",
  668. Hint: "Delete",
  669. Classes: "delete",
  670. },
  671. })
  672. },
  673. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  674. nil,
  675. nil,
  676. true,
  677. )
  678. } else if wrap.CurrSubModule == "currencies" {
  679. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  680. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  681. {Name: "List of currencies"},
  682. })
  683. content += builder.DataTable(
  684. wrap,
  685. "shop_currencies",
  686. "id",
  687. "DESC",
  688. &[]builder.DataTableRow{
  689. {
  690. DBField: "id",
  691. },
  692. {
  693. DBField: "name",
  694. NameInTable: "Name",
  695. CallBack: func(values *[]string) string {
  696. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  697. return `<div>` + name + `</div>`
  698. },
  699. },
  700. {
  701. DBField: "coefficient",
  702. NameInTable: "Coefficient",
  703. Classes: "d-none d-md-table-cell",
  704. CallBack: func(values *[]string) string {
  705. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  706. },
  707. },
  708. {
  709. DBField: "code",
  710. },
  711. {
  712. DBField: "symbol",
  713. },
  714. },
  715. func(values *[]string) string {
  716. return builder.DataTableAction(&[]builder.DataTableActionRow{
  717. {
  718. Icon: assets.SysSvgIconEdit,
  719. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  720. Hint: "Edit",
  721. },
  722. {
  723. Icon: assets.SysSvgIconRemove,
  724. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  725. (*values)[0] + "','Are you sure want to delete currency?');",
  726. Hint: "Delete",
  727. Classes: "delete",
  728. },
  729. })
  730. },
  731. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  732. nil,
  733. nil,
  734. true,
  735. )
  736. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  737. if wrap.CurrSubModule == "add" {
  738. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  739. {Name: "Add new product"},
  740. })
  741. } else {
  742. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  743. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  744. }
  745. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  746. {Name: "Modify product"},
  747. })
  748. }
  749. data := utils.MySql_shop_product{
  750. A_id: 0,
  751. A_user: 0,
  752. A_currency: 0,
  753. A_price: 0,
  754. A_name: "",
  755. A_alias: "",
  756. A_vendor: "",
  757. A_quantity: 0,
  758. A_category: 0,
  759. A_briefly: "",
  760. A_content: "",
  761. A_datetime: 0,
  762. A_active: 0,
  763. }
  764. if wrap.CurrSubModule == "modify" {
  765. if len(wrap.UrlArgs) != 3 {
  766. return "", "", ""
  767. }
  768. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  769. return "", "", ""
  770. }
  771. err := wrap.DB.QueryRow(`
  772. SELECT
  773. id,
  774. user,
  775. currency,
  776. price,
  777. name,
  778. alias,
  779. vendor,
  780. quantity,
  781. category,
  782. briefly,
  783. content,
  784. active
  785. FROM
  786. shop_products
  787. WHERE
  788. id = ?
  789. LIMIT 1;`,
  790. utils.StrToInt(wrap.UrlArgs[2]),
  791. ).Scan(
  792. &data.A_id,
  793. &data.A_user,
  794. &data.A_currency,
  795. &data.A_price,
  796. &data.A_name,
  797. &data.A_alias,
  798. &data.A_vendor,
  799. &data.A_quantity,
  800. &data.A_category,
  801. &data.A_briefly,
  802. &data.A_content,
  803. &data.A_active,
  804. )
  805. if err != nil {
  806. return "", "", ""
  807. }
  808. }
  809. // All product current categories
  810. var selids []int
  811. if data.A_id > 0 {
  812. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  813. if err == nil {
  814. defer rows.Close()
  815. values := make([]int, 1)
  816. scan := make([]interface{}, len(values))
  817. for i := range values {
  818. scan[i] = &values[i]
  819. }
  820. for rows.Next() {
  821. err = rows.Scan(scan...)
  822. if err == nil {
  823. selids = append(selids, int(values[0]))
  824. }
  825. }
  826. }
  827. }
  828. btn_caption := "Add"
  829. if wrap.CurrSubModule == "modify" {
  830. btn_caption = "Save"
  831. }
  832. content += builder.DataForm(wrap, []builder.DataFormField{
  833. {
  834. Kind: builder.DFKHidden,
  835. Name: "action",
  836. Value: "shop-modify",
  837. },
  838. {
  839. Kind: builder.DFKHidden,
  840. Name: "id",
  841. Value: utils.IntToStr(data.A_id),
  842. },
  843. {
  844. Kind: builder.DFKText,
  845. Caption: "Product name",
  846. Name: "name",
  847. Value: data.A_name,
  848. Required: true,
  849. Min: "1",
  850. Max: "255",
  851. },
  852. {
  853. Kind: builder.DFKText,
  854. Caption: "Product price",
  855. Name: "price",
  856. Value: "0",
  857. CallBack: func(field *builder.DataFormField) string {
  858. return `<div class="form-group n3">` +
  859. `<div class="row">` +
  860. `<div class="col-md-3">` +
  861. `<label for="lbl_price">Product price</label>` +
  862. `</div>` +
  863. `<div class="col-md-9">` +
  864. `<div>` +
  865. `<div class="row">` +
  866. `<div class="col-md-8">` +
  867. `<div><input class="form-control" type="number" step="0.01" id="lbl_price" name="price" value="` + utils.Float64ToStr(data.A_price) + `" placeholder="" autocomplete="off" required></div>` +
  868. `<div class="d-md-none mb-3"></div>` +
  869. `</div>` +
  870. `<div class="col-md-4">` +
  871. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  872. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  873. `</select>` +
  874. `</div>` +
  875. `</div>` +
  876. `</div>` +
  877. `</div>` +
  878. `</div>` +
  879. `</div>`
  880. },
  881. },
  882. {
  883. Kind: builder.DFKText,
  884. Caption: "Product alias",
  885. Name: "alias",
  886. Value: data.A_alias,
  887. Hint: "Example: mobile-phone",
  888. Max: "255",
  889. },
  890. {
  891. Kind: builder.DFKText,
  892. Caption: "Vendor/Count",
  893. Name: "vendor",
  894. Value: "0",
  895. CallBack: func(field *builder.DataFormField) string {
  896. return `<div class="form-group n5">` +
  897. `<div class="row">` +
  898. `<div class="col-md-3">` +
  899. `<label for="lbl_vendor">Vendor/Count</label>` +
  900. `</div>` +
  901. `<div class="col-md-9">` +
  902. `<div>` +
  903. `<div class="row">` +
  904. `<div class="col-md-8">` +
  905. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  906. `<div class="d-md-none mb-3"></div>` +
  907. `</div>` +
  908. `<div class="col-md-4">` +
  909. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  910. `</div>` +
  911. `</div>` +
  912. `</div>` +
  913. `</div>` +
  914. `</div>` +
  915. `</div>`
  916. },
  917. },
  918. {
  919. Kind: builder.DFKText,
  920. Caption: "Category",
  921. Name: "category",
  922. Value: "0",
  923. CallBack: func(field *builder.DataFormField) string {
  924. return `<div class="form-group n6">` +
  925. `<div class="row">` +
  926. `<div class="col-md-3">` +
  927. `<label for="lbl_category">Category</label>` +
  928. `</div>` +
  929. `<div class="col-md-9">` +
  930. `<div>` +
  931. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  932. `<option title="Nothing selected" value="0">&mdash;</option>` +
  933. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  934. `</select>` +
  935. `</div>` +
  936. `</div>` +
  937. `</div>` +
  938. `</div>`
  939. },
  940. },
  941. {
  942. Kind: builder.DFKText,
  943. Caption: "Categories",
  944. Name: "cats",
  945. Value: "0",
  946. CallBack: func(field *builder.DataFormField) string {
  947. return `<div class="form-group n7">` +
  948. `<div class="row">` +
  949. `<div class="col-md-3">` +
  950. `<label for="lbl_cats">Categories</label>` +
  951. `</div>` +
  952. `<div class="col-md-9">` +
  953. `<div>` +
  954. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  955. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  956. `</select>` +
  957. `</div>` +
  958. `</div>` +
  959. `</div>` +
  960. `</div>`
  961. },
  962. },
  963. {
  964. Kind: builder.DFKText,
  965. Caption: "Attributes",
  966. Name: "",
  967. Value: "",
  968. CallBack: func(field *builder.DataFormField) string {
  969. return `<div class="form-group n8">` +
  970. `<div class="row">` +
  971. `<div class="col-md-3">` +
  972. `<label>Attributes</label>` +
  973. `</div>` +
  974. `<div class="col-md-9">` +
  975. `<div class="list-wrapper">` +
  976. `<div id="list">` +
  977. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  978. `</div>` +
  979. `<div class="list-button position-relative">` +
  980. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  981. this.shop_GetAllAttributesSelectOptions(wrap) +
  982. `</select>` +
  983. `</div>` +
  984. `</div>` +
  985. `</div>` +
  986. `</div>` +
  987. `</div>`
  988. },
  989. },
  990. {
  991. Kind: builder.DFKTextArea,
  992. Caption: "Briefly",
  993. Name: "briefly",
  994. Value: data.A_briefly,
  995. Classes: "briefly wysiwyg",
  996. },
  997. {
  998. Kind: builder.DFKTextArea,
  999. Caption: "Product content",
  1000. Name: "content",
  1001. Value: data.A_content,
  1002. Classes: "wysiwyg",
  1003. },
  1004. {
  1005. Kind: builder.DFKText,
  1006. Caption: "Product images",
  1007. Name: "",
  1008. Value: "",
  1009. CallBack: func(field *builder.DataFormField) string {
  1010. if data.A_id == 0 {
  1011. return ``
  1012. }
  1013. return `<div class="form-group n11">` +
  1014. `<div class="row">` +
  1015. `<div class="col-md-3">` +
  1016. `<label>Product images</label>` +
  1017. `</div>` +
  1018. `<div class="col-md-9">` +
  1019. `<div class="list-wrapper">` +
  1020. `<div id="list-images">` +
  1021. this.shop_GetAllProductImages(wrap, data.A_id) +
  1022. `</div>` +
  1023. `<div id="img-upload-block" class="list-button position-relative">` +
  1024. `<div id="upload-msg">Uploading...</div>` +
  1025. `<input class="form-control ignore-lost-data" type="file" id="file" name="file" onchange="fave.ShopProductsUploadImage('shop-upload-image', ` + utils.IntToStr(data.A_id) + `, 'file');" style="font-size:13px;" multiple />` +
  1026. `</div>` +
  1027. `</div>` +
  1028. `</div>` +
  1029. `</div>` +
  1030. `</div>` +
  1031. `<script>WaitForFave(function(){Sortable.create(document.getElementById('list-images'),{animation:0,onEnd:function(evt){var orderData=[];$('#list-images div.attached-img').each(function(i,v){orderData.push({Id:$(v).data('id'),Order:i});});fave.ShopProductsImageReorder('shop-images-reorder',{Items:orderData});},});});</script>`
  1032. },
  1033. },
  1034. {
  1035. Kind: builder.DFKCheckBox,
  1036. Caption: "Active",
  1037. Name: "active",
  1038. Value: utils.IntToStr(data.A_active),
  1039. },
  1040. {
  1041. Kind: builder.DFKSubmit,
  1042. Value: btn_caption,
  1043. Target: "add-edit-button",
  1044. },
  1045. })
  1046. if wrap.CurrSubModule == "add" {
  1047. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1048. } else {
  1049. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1050. }
  1051. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1052. if wrap.CurrSubModule == "categories-add" {
  1053. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1054. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1055. {Name: "Add new category"},
  1056. })
  1057. } else {
  1058. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1059. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1060. {Name: "Modify category"},
  1061. })
  1062. }
  1063. data := utils.MySql_shop_category{
  1064. A_id: 0,
  1065. A_user: 0,
  1066. A_name: "",
  1067. A_alias: "",
  1068. A_lft: 0,
  1069. A_rgt: 0,
  1070. }
  1071. if wrap.CurrSubModule == "categories-modify" {
  1072. if len(wrap.UrlArgs) != 3 {
  1073. return "", "", ""
  1074. }
  1075. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1076. return "", "", ""
  1077. }
  1078. err := wrap.DB.QueryRow(`
  1079. SELECT
  1080. id,
  1081. user,
  1082. name,
  1083. alias,
  1084. lft,
  1085. rgt
  1086. FROM
  1087. shop_cats
  1088. WHERE
  1089. id = ?
  1090. LIMIT 1;`,
  1091. utils.StrToInt(wrap.UrlArgs[2]),
  1092. ).Scan(
  1093. &data.A_id,
  1094. &data.A_user,
  1095. &data.A_name,
  1096. &data.A_alias,
  1097. &data.A_lft,
  1098. &data.A_rgt,
  1099. )
  1100. if err != nil {
  1101. return "", "", ""
  1102. }
  1103. }
  1104. btn_caption := "Add"
  1105. if wrap.CurrSubModule == "categories-modify" {
  1106. btn_caption = "Save"
  1107. }
  1108. parentId := 0
  1109. if wrap.CurrSubModule == "categories-modify" {
  1110. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1111. }
  1112. content += builder.DataForm(wrap, []builder.DataFormField{
  1113. {
  1114. Kind: builder.DFKHidden,
  1115. Name: "action",
  1116. Value: "shop-categories-modify",
  1117. },
  1118. {
  1119. Kind: builder.DFKHidden,
  1120. Name: "id",
  1121. Value: utils.IntToStr(data.A_id),
  1122. },
  1123. {
  1124. Kind: builder.DFKText,
  1125. Caption: "Parent",
  1126. Name: "parent",
  1127. Value: "0",
  1128. CallBack: func(field *builder.DataFormField) string {
  1129. return `<div class="form-group n2">` +
  1130. `<div class="row">` +
  1131. `<div class="col-md-3">` +
  1132. `<label for="lbl_parent">Parent</label>` +
  1133. `</div>` +
  1134. `<div class="col-md-9">` +
  1135. `<div>` +
  1136. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1137. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1138. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1139. `</select>` +
  1140. `</div>` +
  1141. `</div>` +
  1142. `</div>` +
  1143. `</div>`
  1144. },
  1145. },
  1146. {
  1147. Kind: builder.DFKText,
  1148. Caption: "Name",
  1149. Name: "name",
  1150. Value: data.A_name,
  1151. Required: true,
  1152. Min: "1",
  1153. Max: "255",
  1154. },
  1155. {
  1156. Kind: builder.DFKText,
  1157. Caption: "Alias",
  1158. Name: "alias",
  1159. Value: data.A_alias,
  1160. Hint: "Example: popular-products",
  1161. Max: "255",
  1162. },
  1163. {
  1164. Kind: builder.DFKSubmit,
  1165. Value: btn_caption,
  1166. Target: "add-edit-button",
  1167. },
  1168. })
  1169. if wrap.CurrSubModule == "categories-add" {
  1170. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1171. } else {
  1172. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1173. }
  1174. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1175. if wrap.CurrSubModule == "attributes-add" {
  1176. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1177. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1178. {Name: "Add new attribute"},
  1179. })
  1180. } else {
  1181. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1182. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1183. {Name: "Modify attribute"},
  1184. })
  1185. }
  1186. data := utils.MySql_shop_filter{
  1187. A_id: 0,
  1188. A_name: "",
  1189. A_filter: "",
  1190. }
  1191. if wrap.CurrSubModule == "attributes-modify" {
  1192. if len(wrap.UrlArgs) != 3 {
  1193. return "", "", ""
  1194. }
  1195. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1196. return "", "", ""
  1197. }
  1198. err := wrap.DB.QueryRow(`
  1199. SELECT
  1200. id,
  1201. name,
  1202. filter
  1203. FROM
  1204. shop_filters
  1205. WHERE
  1206. id = ?
  1207. LIMIT 1;`,
  1208. utils.StrToInt(wrap.UrlArgs[2]),
  1209. ).Scan(
  1210. &data.A_id,
  1211. &data.A_name,
  1212. &data.A_filter,
  1213. )
  1214. if err != nil {
  1215. return "", "", ""
  1216. }
  1217. }
  1218. btn_caption := "Add"
  1219. if wrap.CurrSubModule == "attributes-modify" {
  1220. btn_caption = "Save"
  1221. }
  1222. content += builder.DataForm(wrap, []builder.DataFormField{
  1223. {
  1224. Kind: builder.DFKHidden,
  1225. Name: "action",
  1226. Value: "shop-attributes-modify",
  1227. },
  1228. {
  1229. Kind: builder.DFKHidden,
  1230. Name: "id",
  1231. Value: utils.IntToStr(data.A_id),
  1232. },
  1233. {
  1234. Kind: builder.DFKText,
  1235. Caption: "Attribute name",
  1236. Name: "name",
  1237. Value: data.A_name,
  1238. Required: true,
  1239. Min: "1",
  1240. Max: "255",
  1241. },
  1242. {
  1243. Kind: builder.DFKText,
  1244. Caption: "Attribute in filter",
  1245. Name: "filter",
  1246. Value: data.A_filter,
  1247. Required: true,
  1248. Min: "1",
  1249. Max: "255",
  1250. },
  1251. {
  1252. Kind: builder.DFKText,
  1253. Caption: "Attribute values",
  1254. Name: "",
  1255. Value: "",
  1256. CallBack: func(field *builder.DataFormField) string {
  1257. return `<div class="form-group n4">` +
  1258. `<div class="row">` +
  1259. `<div class="col-md-3">` +
  1260. `<label>Attribute values</label>` +
  1261. `</div>` +
  1262. `<div class="col-md-9">` +
  1263. `<div class="list-wrapper">` +
  1264. `<div id="list">` +
  1265. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1266. `</div>` +
  1267. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1268. `</div>` +
  1269. `</div>` +
  1270. `</div>` +
  1271. `</div>`
  1272. },
  1273. },
  1274. {
  1275. Kind: builder.DFKSubmit,
  1276. Value: btn_caption,
  1277. Target: "add-edit-button",
  1278. },
  1279. })
  1280. if wrap.CurrSubModule == "attributes-add" {
  1281. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1282. } else {
  1283. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1284. }
  1285. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1286. if wrap.CurrSubModule == "currencies-add" {
  1287. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1288. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1289. {Name: "Add new currency"},
  1290. })
  1291. } else {
  1292. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1293. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1294. {Name: "Modify currency"},
  1295. })
  1296. }
  1297. data := utils.MySql_shop_currency{
  1298. A_id: 0,
  1299. A_name: "",
  1300. A_coefficient: 0,
  1301. A_code: "",
  1302. A_symbol: "",
  1303. }
  1304. if wrap.CurrSubModule == "currencies-modify" {
  1305. if len(wrap.UrlArgs) != 3 {
  1306. return "", "", ""
  1307. }
  1308. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1309. return "", "", ""
  1310. }
  1311. err := wrap.DB.QueryRow(`
  1312. SELECT
  1313. id,
  1314. name,
  1315. coefficient,
  1316. code,
  1317. symbol
  1318. FROM
  1319. shop_currencies
  1320. WHERE
  1321. id = ?
  1322. LIMIT 1;`,
  1323. utils.StrToInt(wrap.UrlArgs[2]),
  1324. ).Scan(
  1325. &data.A_id,
  1326. &data.A_name,
  1327. &data.A_coefficient,
  1328. &data.A_code,
  1329. &data.A_symbol,
  1330. )
  1331. if err != nil {
  1332. return "", "", ""
  1333. }
  1334. }
  1335. btn_caption := "Add"
  1336. if wrap.CurrSubModule == "currencies-modify" {
  1337. btn_caption = "Save"
  1338. }
  1339. content += builder.DataForm(wrap, []builder.DataFormField{
  1340. {
  1341. Kind: builder.DFKHidden,
  1342. Name: "action",
  1343. Value: "shop-currencies-modify",
  1344. },
  1345. {
  1346. Kind: builder.DFKHidden,
  1347. Name: "id",
  1348. Value: utils.IntToStr(data.A_id),
  1349. },
  1350. {
  1351. Kind: builder.DFKText,
  1352. Caption: "Currency name",
  1353. Name: "name",
  1354. Value: data.A_name,
  1355. Required: true,
  1356. Min: "1",
  1357. Max: "255",
  1358. },
  1359. {
  1360. Kind: builder.DFKText,
  1361. Caption: "Currency coefficient",
  1362. Name: "coefficient",
  1363. Value: "0",
  1364. CallBack: func(field *builder.DataFormField) string {
  1365. return `<div class="form-group n3">` +
  1366. `<div class="row">` +
  1367. `<div class="col-md-3">` +
  1368. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1369. `</div>` +
  1370. `<div class="col-md-9">` +
  1371. `<div><input class="form-control" type="number" step="0.0001" id="lbl_coefficient" name="coefficient" value="` + utils.Float64ToStrF(data.A_coefficient, "%.4f") + `" placeholder="" autocomplete="off" required></div>` +
  1372. `</div>` +
  1373. `</div>` +
  1374. `</div>`
  1375. },
  1376. },
  1377. {
  1378. Kind: builder.DFKText,
  1379. Caption: "Currency code",
  1380. Name: "code",
  1381. Value: data.A_code,
  1382. Required: true,
  1383. Min: "1",
  1384. Max: "10",
  1385. },
  1386. {
  1387. Kind: builder.DFKText,
  1388. Caption: "Currency symbol",
  1389. Name: "symbol",
  1390. Value: data.A_symbol,
  1391. Required: true,
  1392. Min: "1",
  1393. Max: "5",
  1394. },
  1395. {
  1396. Kind: builder.DFKSubmit,
  1397. Value: btn_caption,
  1398. Target: "add-edit-button",
  1399. },
  1400. })
  1401. if wrap.CurrSubModule == "currencies-add" {
  1402. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1403. } else {
  1404. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1405. }
  1406. }
  1407. return this.getSidebarModules(wrap), content, sidebar
  1408. })
  1409. }