module_shop.go 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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 *wrap.LogCpError(&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) shop_GetSubProducts(wrap *wrapper.Wrapper, id int) string {
  242. result := ``
  243. rows, err := wrap.DB.Query(
  244. `SELECT
  245. id,
  246. name
  247. FROM
  248. shop_products
  249. WHERE
  250. parent_id = ?
  251. ORDER BY
  252. id DESC
  253. ;`,
  254. id,
  255. )
  256. if err == nil {
  257. defer rows.Close()
  258. values := make([]string, 2)
  259. scan := make([]interface{}, len(values))
  260. for i := range values {
  261. scan[i] = &values[i]
  262. }
  263. for rows.Next() {
  264. err = rows.Scan(scan...)
  265. if *wrap.LogCpError(&err) == nil {
  266. result += `<div><a href="/cp/` + wrap.CurrModule + `/modify/` + html.EscapeString(string(values[0])) + `/">` + html.EscapeString(string(values[1])) + `</a> <a class="ico delete" title="Delete" href="javascript:fave.ActionDataTableDelete(this,'shop-detach','` + html.EscapeString(string(values[0])) + `','Are you sure want to detach product?');"><svg viewBox="0 0 16 16" width="16" height="16" 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>`
  267. }
  268. }
  269. }
  270. return result
  271. }
  272. func (this *Modules) RegisterModule_Shop() *Module {
  273. return this.newModule(MInfo{
  274. WantDB: true,
  275. Mount: "shop",
  276. Name: "Shop",
  277. Order: 2,
  278. System: false,
  279. Icon: assets.SysSvgIconShop,
  280. Sub: &[]MISub{
  281. {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
  282. {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
  283. {Mount: "modify", Name: "Modify product", Show: false},
  284. {Sep: true, Show: true},
  285. {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
  286. {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
  287. {Mount: "categories-modify", Name: "Modify category", Show: false},
  288. {Sep: true, Show: true},
  289. {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
  290. {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
  291. {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
  292. {Sep: true, Show: true},
  293. {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
  294. {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
  295. {Mount: "currencies-modify", Name: "Modify currency", Show: false},
  296. },
  297. }, func(wrap *wrapper.Wrapper) {
  298. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  299. // Shop category
  300. row := &utils.MySql_shop_category{}
  301. rou := &utils.MySql_user{}
  302. err := wrap.DB.QueryRow(`
  303. SELECT
  304. main.id,
  305. main.user,
  306. main.name,
  307. main.alias,
  308. main.lft,
  309. main.rgt,
  310. main.depth,
  311. parent.id AS parent_id,
  312. users.id,
  313. users.first_name,
  314. users.last_name,
  315. users.email,
  316. users.admin,
  317. users.active
  318. FROM
  319. (
  320. SELECT
  321. node.id,
  322. node.user,
  323. node.name,
  324. node.alias,
  325. node.lft,
  326. node.rgt,
  327. (COUNT(parent.id) - 1) AS depth
  328. FROM
  329. shop_cats AS node,
  330. shop_cats AS parent
  331. WHERE
  332. node.lft BETWEEN parent.lft AND parent.rgt
  333. GROUP BY
  334. node.id
  335. ORDER BY
  336. node.lft ASC
  337. ) AS main
  338. LEFT JOIN (
  339. SELECT
  340. node.id,
  341. node.user,
  342. node.name,
  343. node.alias,
  344. node.lft,
  345. node.rgt,
  346. (COUNT(parent.id) - 0) AS depth
  347. FROM
  348. shop_cats AS node,
  349. shop_cats AS parent
  350. WHERE
  351. node.lft BETWEEN parent.lft AND parent.rgt
  352. GROUP BY
  353. node.id
  354. ORDER BY
  355. node.lft ASC
  356. ) AS parent ON
  357. parent.depth = main.depth AND
  358. main.lft > parent.lft AND
  359. main.rgt < parent.rgt
  360. LEFT JOIN users ON users.id = main.user
  361. WHERE
  362. main.id > 1 AND
  363. main.alias = ?
  364. ORDER BY
  365. main.lft ASC
  366. ;`,
  367. wrap.UrlArgs[2],
  368. ).Scan(
  369. &row.A_id,
  370. &row.A_user,
  371. &row.A_name,
  372. &row.A_alias,
  373. &row.A_lft,
  374. &row.A_rgt,
  375. &row.A_depth,
  376. &row.A_parent,
  377. &rou.A_id,
  378. &rou.A_first_name,
  379. &rou.A_last_name,
  380. &rou.A_email,
  381. &rou.A_admin,
  382. &rou.A_active,
  383. )
  384. if err != nil && err != wrapper.ErrNoRows {
  385. // System error 500
  386. wrap.LogCpError(&err)
  387. utils.SystemErrorPageEngine(wrap.W, err)
  388. return
  389. } else if err == wrapper.ErrNoRows {
  390. // User error 404 page
  391. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  392. return
  393. }
  394. // Fix url
  395. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  396. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  397. return
  398. }
  399. // Render template
  400. wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
  401. return
  402. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  403. // Shop product
  404. row := &utils.MySql_shop_product{}
  405. rou := &utils.MySql_user{}
  406. err := wrap.DB.QueryRow(`
  407. SELECT
  408. shop_products.id,
  409. shop_products.user,
  410. shop_products.currency,
  411. shop_products.price,
  412. shop_products.name,
  413. shop_products.alias,
  414. shop_products.vendor,
  415. shop_products.quantity,
  416. shop_products.category,
  417. shop_products.briefly,
  418. shop_products.content,
  419. UNIX_TIMESTAMP(shop_products.datetime) as datetime,
  420. shop_products.active,
  421. users.id,
  422. users.first_name,
  423. users.last_name,
  424. users.email,
  425. users.admin,
  426. users.active
  427. FROM
  428. shop_products
  429. LEFT JOIN users ON users.id = shop_products.user
  430. WHERE
  431. shop_products.active = 1 and
  432. shop_products.alias = ?
  433. LIMIT 1;`,
  434. wrap.UrlArgs[1],
  435. ).Scan(
  436. &row.A_id,
  437. &row.A_user,
  438. &row.A_currency,
  439. &row.A_price,
  440. &row.A_name,
  441. &row.A_alias,
  442. &row.A_vendor,
  443. &row.A_quantity,
  444. &row.A_category,
  445. &row.A_briefly,
  446. &row.A_content,
  447. &row.A_datetime,
  448. &row.A_active,
  449. &rou.A_id,
  450. &rou.A_first_name,
  451. &rou.A_last_name,
  452. &rou.A_email,
  453. &rou.A_admin,
  454. &rou.A_active,
  455. )
  456. if err != nil && err != wrapper.ErrNoRows {
  457. // System error 500
  458. wrap.LogCpError(&err)
  459. utils.SystemErrorPageEngine(wrap.W, err)
  460. return
  461. } else if err == wrapper.ErrNoRows {
  462. // User error 404 page
  463. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  464. return
  465. }
  466. // Fix url
  467. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  468. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  469. return
  470. }
  471. // Render template
  472. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
  473. return
  474. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  475. // Shop
  476. // Fix url
  477. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  478. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  479. return
  480. }
  481. // Render template
  482. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  483. return
  484. } else if (*wrap.Config).Engine.MainModule == 2 {
  485. // Render template
  486. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  487. return
  488. }
  489. // User error 404 page
  490. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  491. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  492. content := ""
  493. sidebar := ""
  494. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  495. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  496. {Name: "List of products"},
  497. })
  498. // Load currencies
  499. currencies := this.shop_GetAllCurrencies(wrap)
  500. content += builder.DataTable(
  501. wrap,
  502. "shop_products",
  503. "id",
  504. "DESC",
  505. &[]builder.DataTableRow{
  506. {
  507. DBField: "id",
  508. },
  509. {
  510. DBField: "name",
  511. NameInTable: "Product / URL",
  512. CallBack: func(values *[]string) string {
  513. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  514. alias := html.EscapeString((*values)[2])
  515. parent := ``
  516. if (*values)[7] != "" {
  517. parent = `<div class="parent">&uarr;<small><a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[7] + `/">` + html.EscapeString((*values)[8]) + `</a></small></div>`
  518. }
  519. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>` + parent
  520. },
  521. },
  522. {
  523. DBField: "alias",
  524. },
  525. {
  526. DBField: "currency",
  527. },
  528. {
  529. DBField: "price",
  530. NameInTable: "Price",
  531. Classes: "d-none d-md-table-cell",
  532. CallBack: func(values *[]string) string {
  533. return `<div>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  534. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  535. },
  536. },
  537. {
  538. DBField: "datetime",
  539. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  540. NameInTable: "Date / Time",
  541. Classes: "d-none d-lg-table-cell",
  542. CallBack: func(values *[]string) string {
  543. t := int64(utils.StrToInt((*values)[5]))
  544. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  545. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  546. },
  547. },
  548. {
  549. DBField: "active",
  550. NameInTable: "Active",
  551. Classes: "d-none d-sm-table-cell",
  552. CallBack: func(values *[]string) string {
  553. return builder.CheckBox(utils.StrToInt((*values)[6]))
  554. },
  555. },
  556. {
  557. DBField: "parent_id",
  558. },
  559. {
  560. DBField: "pname",
  561. DBExp: "spp.name",
  562. },
  563. },
  564. func(values *[]string) string {
  565. return builder.DataTableAction(&[]builder.DataTableActionRow{
  566. {
  567. Icon: assets.SysSvgIconView,
  568. Href: `/shop/` + (*values)[2] + `/`,
  569. Hint: "View",
  570. Target: "_blank",
  571. },
  572. {
  573. Icon: assets.SysSvgIconEdit,
  574. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  575. Hint: "Edit",
  576. },
  577. {
  578. Icon: assets.SysSvgIconRemove,
  579. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  580. (*values)[0] + "','Are you sure want to delete product?');",
  581. Hint: "Delete",
  582. Classes: "delete",
  583. },
  584. })
  585. },
  586. "/cp/"+wrap.CurrModule+"/",
  587. func() (int, error) {
  588. var count int
  589. return count, wrap.DB.QueryRow(
  590. "SELECT COUNT(*) FROM `shop_products`;",
  591. ).Scan(&count)
  592. },
  593. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  594. return wrap.DB.Query(
  595. `SELECT
  596. shop_products.id,
  597. shop_products.name,
  598. shop_products.alias,
  599. shop_products.currency,
  600. shop_products.price,
  601. UNIX_TIMESTAMP(`+"`shop_products`.`datetime`"+`) AS datetime,
  602. shop_products.active,
  603. shop_products.parent_id,
  604. spp.name AS pname
  605. FROM
  606. shop_products
  607. LEFT JOIN shop_products AS spp ON spp.id = shop_products.parent_id
  608. ORDER BY
  609. shop_products.id DESC
  610. LIMIT ?, ?;`,
  611. limit_offset,
  612. pear_page,
  613. )
  614. },
  615. true,
  616. )
  617. } else if wrap.CurrSubModule == "categories" {
  618. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  619. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  620. {Name: "List of categories"},
  621. })
  622. content += builder.DataTable(
  623. wrap,
  624. "shop_cats",
  625. "id",
  626. "ASC",
  627. &[]builder.DataTableRow{
  628. {
  629. DBField: "id",
  630. },
  631. {
  632. DBField: "user",
  633. },
  634. {
  635. DBField: "name",
  636. NameInTable: "Category",
  637. CallBack: func(values *[]string) string {
  638. depth := utils.StrToInt((*values)[4]) - 1
  639. if depth < 0 {
  640. depth = 0
  641. }
  642. sub := strings.Repeat("&mdash; ", depth)
  643. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  644. return `<div>` + name + `</div>`
  645. },
  646. },
  647. {
  648. DBField: "alias",
  649. },
  650. {
  651. DBField: "depth",
  652. },
  653. },
  654. func(values *[]string) string {
  655. return builder.DataTableAction(&[]builder.DataTableActionRow{
  656. {
  657. Icon: assets.SysSvgIconView,
  658. Href: `/shop/category/` + (*values)[3] + `/`,
  659. Hint: "View",
  660. Target: "_blank",
  661. },
  662. {
  663. Icon: assets.SysSvgIconEdit,
  664. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  665. Hint: "Edit",
  666. },
  667. {
  668. Icon: assets.SysSvgIconRemove,
  669. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  670. (*values)[0] + "','Are you sure want to delete category?');",
  671. Hint: "Delete",
  672. Classes: "delete",
  673. },
  674. })
  675. },
  676. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  677. nil,
  678. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  679. return wrap.DB.Query(
  680. `SELECT
  681. node.id,
  682. node.user,
  683. node.name,
  684. node.alias,
  685. (COUNT(parent.id) - 1) AS depth
  686. FROM
  687. shop_cats AS node,
  688. shop_cats AS parent
  689. WHERE
  690. node.lft BETWEEN parent.lft AND parent.rgt AND
  691. node.id > 1
  692. GROUP BY
  693. node.id
  694. ORDER BY
  695. node.lft ASC
  696. ;`,
  697. )
  698. },
  699. false,
  700. )
  701. } else if wrap.CurrSubModule == "attributes" {
  702. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  703. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  704. {Name: "List of attributes"},
  705. })
  706. content += builder.DataTable(
  707. wrap,
  708. "shop_filters",
  709. "id",
  710. "DESC",
  711. &[]builder.DataTableRow{
  712. {
  713. DBField: "id",
  714. },
  715. {
  716. DBField: "name",
  717. NameInTable: "Name",
  718. CallBack: func(values *[]string) string {
  719. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  720. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  721. },
  722. },
  723. {
  724. DBField: "filter",
  725. },
  726. },
  727. func(values *[]string) string {
  728. return builder.DataTableAction(&[]builder.DataTableActionRow{
  729. {
  730. Icon: assets.SysSvgIconEdit,
  731. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  732. Hint: "Edit",
  733. },
  734. {
  735. Icon: assets.SysSvgIconRemove,
  736. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  737. (*values)[0] + "','Are you sure want to delete attribute?');",
  738. Hint: "Delete",
  739. Classes: "delete",
  740. },
  741. })
  742. },
  743. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  744. nil,
  745. nil,
  746. true,
  747. )
  748. } else if wrap.CurrSubModule == "currencies" {
  749. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  750. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  751. {Name: "List of currencies"},
  752. })
  753. content += builder.DataTable(
  754. wrap,
  755. "shop_currencies",
  756. "id",
  757. "DESC",
  758. &[]builder.DataTableRow{
  759. {
  760. DBField: "id",
  761. },
  762. {
  763. DBField: "name",
  764. NameInTable: "Name",
  765. CallBack: func(values *[]string) string {
  766. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  767. return `<div>` + name + `</div>`
  768. },
  769. },
  770. {
  771. DBField: "coefficient",
  772. NameInTable: "Coefficient",
  773. Classes: "d-none d-md-table-cell",
  774. CallBack: func(values *[]string) string {
  775. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  776. },
  777. },
  778. {
  779. DBField: "code",
  780. },
  781. {
  782. DBField: "symbol",
  783. },
  784. },
  785. func(values *[]string) string {
  786. return builder.DataTableAction(&[]builder.DataTableActionRow{
  787. {
  788. Icon: assets.SysSvgIconEdit,
  789. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  790. Hint: "Edit",
  791. },
  792. {
  793. Icon: assets.SysSvgIconRemove,
  794. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  795. (*values)[0] + "','Are you sure want to delete currency?');",
  796. Hint: "Delete",
  797. Classes: "delete",
  798. },
  799. })
  800. },
  801. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  802. nil,
  803. nil,
  804. true,
  805. )
  806. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  807. if wrap.CurrSubModule == "add" {
  808. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  809. {Name: "Add new product"},
  810. })
  811. } else {
  812. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  813. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  814. content += `<div class="product-another"><a title="Duplicate product and attach" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
  815. }
  816. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  817. {Name: "Modify product"},
  818. })
  819. }
  820. data := utils.MySql_shop_product{
  821. A_id: 0,
  822. A_user: 0,
  823. A_currency: 0,
  824. A_price: 0,
  825. A_name: "",
  826. A_alias: "",
  827. A_vendor: "",
  828. A_quantity: 0,
  829. A_category: 0,
  830. A_briefly: "",
  831. A_content: "",
  832. A_datetime: 0,
  833. A_active: 0,
  834. }
  835. if wrap.CurrSubModule == "modify" {
  836. if len(wrap.UrlArgs) != 3 {
  837. return "", "", ""
  838. }
  839. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  840. return "", "", ""
  841. }
  842. err := wrap.DB.QueryRow(`
  843. SELECT
  844. id,
  845. parent_id,
  846. user,
  847. currency,
  848. price,
  849. name,
  850. alias,
  851. vendor,
  852. quantity,
  853. category,
  854. briefly,
  855. content,
  856. active
  857. FROM
  858. shop_products
  859. WHERE
  860. id = ?
  861. LIMIT 1;`,
  862. utils.StrToInt(wrap.UrlArgs[2]),
  863. ).Scan(
  864. &data.A_id,
  865. &data.A_parent,
  866. &data.A_user,
  867. &data.A_currency,
  868. &data.A_price,
  869. &data.A_name,
  870. &data.A_alias,
  871. &data.A_vendor,
  872. &data.A_quantity,
  873. &data.A_category,
  874. &data.A_briefly,
  875. &data.A_content,
  876. &data.A_active,
  877. )
  878. if *wrap.LogCpError(&err) != nil {
  879. return "", "", ""
  880. }
  881. }
  882. if data.A_parent_id() > 0 {
  883. content += `<style>.product-another{display:none}</style>`
  884. }
  885. // All product current categories
  886. var selids []int
  887. if data.A_id > 0 {
  888. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  889. if err == nil {
  890. defer rows.Close()
  891. values := make([]int, 1)
  892. scan := make([]interface{}, len(values))
  893. for i := range values {
  894. scan[i] = &values[i]
  895. }
  896. for rows.Next() {
  897. err = rows.Scan(scan...)
  898. if *wrap.LogCpError(&err) == nil {
  899. selids = append(selids, int(values[0]))
  900. }
  901. }
  902. }
  903. }
  904. btn_caption := "Add"
  905. if wrap.CurrSubModule == "modify" {
  906. btn_caption = "Save"
  907. }
  908. content += builder.DataForm(wrap, []builder.DataFormField{
  909. {
  910. Kind: builder.DFKHidden,
  911. Name: "action",
  912. Value: "shop-modify",
  913. },
  914. {
  915. Kind: builder.DFKHidden,
  916. Name: "id",
  917. Value: utils.IntToStr(data.A_id),
  918. },
  919. {
  920. Kind: builder.DFKText,
  921. CallBack: func(field *builder.DataFormField) string {
  922. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  923. return `<div class="form-group nf">` +
  924. `<div class="row">` +
  925. `<div class="col-md-3">` +
  926. `<label>Sub products</label>` +
  927. `</div>` +
  928. `<div class="col-md-9">` +
  929. `<div class="list-wrapper">` +
  930. this.shop_GetSubProducts(wrap, data.A_id) +
  931. `<div><a href="javascript:fave.ShopAttachProduct(` + utils.IntToStr(data.A_id) + `);"><b>Attach product</b></a></div>` +
  932. `</div>` +
  933. `</div>` +
  934. `</div>` +
  935. `</div>`
  936. }
  937. return ""
  938. },
  939. },
  940. {
  941. Kind: builder.DFKText,
  942. Caption: "Product name",
  943. Name: "name",
  944. Value: data.A_name,
  945. Required: true,
  946. Min: "1",
  947. Max: "255",
  948. },
  949. {
  950. Kind: builder.DFKText,
  951. Caption: "Product price",
  952. Name: "price",
  953. Value: "0",
  954. CallBack: func(field *builder.DataFormField) string {
  955. return `<div class="form-group n3">` +
  956. `<div class="row">` +
  957. `<div class="col-md-3">` +
  958. `<label for="lbl_price">Product price</label>` +
  959. `</div>` +
  960. `<div class="col-md-9">` +
  961. `<div>` +
  962. `<div class="row">` +
  963. `<div class="col-md-8">` +
  964. `<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>` +
  965. `<div class="d-md-none mb-3"></div>` +
  966. `</div>` +
  967. `<div class="col-md-4">` +
  968. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  969. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  970. `</select>` +
  971. `</div>` +
  972. `</div>` +
  973. `</div>` +
  974. `</div>` +
  975. `</div>` +
  976. `</div>`
  977. },
  978. },
  979. {
  980. Kind: builder.DFKText,
  981. Caption: "Product alias",
  982. Name: "alias",
  983. Value: data.A_alias,
  984. Hint: "Example: mobile-phone",
  985. Max: "255",
  986. },
  987. {
  988. Kind: builder.DFKText,
  989. Caption: "Vendor/Count",
  990. Name: "vendor",
  991. Value: "0",
  992. CallBack: func(field *builder.DataFormField) string {
  993. return `<div class="form-group n5">` +
  994. `<div class="row">` +
  995. `<div class="col-md-3">` +
  996. `<label for="lbl_vendor">Vendor/Count</label>` +
  997. `</div>` +
  998. `<div class="col-md-9">` +
  999. `<div>` +
  1000. `<div class="row">` +
  1001. `<div class="col-md-8">` +
  1002. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  1003. `<div class="d-md-none mb-3"></div>` +
  1004. `</div>` +
  1005. `<div class="col-md-4">` +
  1006. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  1007. `</div>` +
  1008. `</div>` +
  1009. `</div>` +
  1010. `</div>` +
  1011. `</div>` +
  1012. `</div>`
  1013. },
  1014. },
  1015. {
  1016. Kind: builder.DFKText,
  1017. Caption: "Category",
  1018. Name: "category",
  1019. Value: "0",
  1020. CallBack: func(field *builder.DataFormField) string {
  1021. return `<div class="form-group n6">` +
  1022. `<div class="row">` +
  1023. `<div class="col-md-3">` +
  1024. `<label for="lbl_category">Category</label>` +
  1025. `</div>` +
  1026. `<div class="col-md-9">` +
  1027. `<div>` +
  1028. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  1029. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1030. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  1031. `</select>` +
  1032. `</div>` +
  1033. `</div>` +
  1034. `</div>` +
  1035. `</div>`
  1036. },
  1037. },
  1038. {
  1039. Kind: builder.DFKText,
  1040. Caption: "Categories",
  1041. Name: "cats",
  1042. Value: "0",
  1043. CallBack: func(field *builder.DataFormField) string {
  1044. return `<div class="form-group n7">` +
  1045. `<div class="row">` +
  1046. `<div class="col-md-3">` +
  1047. `<label for="lbl_cats">Categories</label>` +
  1048. `</div>` +
  1049. `<div class="col-md-9">` +
  1050. `<div>` +
  1051. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  1052. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  1053. `</select>` +
  1054. `</div>` +
  1055. `</div>` +
  1056. `</div>` +
  1057. `</div>`
  1058. },
  1059. },
  1060. {
  1061. Kind: builder.DFKText,
  1062. Caption: "Attributes",
  1063. Name: "",
  1064. Value: "",
  1065. CallBack: func(field *builder.DataFormField) string {
  1066. return `<div class="form-group n8">` +
  1067. `<div class="row">` +
  1068. `<div class="col-md-3">` +
  1069. `<label>Attributes</label>` +
  1070. `</div>` +
  1071. `<div class="col-md-9">` +
  1072. `<div class="list-wrapper">` +
  1073. `<div id="list">` +
  1074. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  1075. `</div>` +
  1076. `<div class="list-button position-relative">` +
  1077. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  1078. this.shop_GetAllAttributesSelectOptions(wrap) +
  1079. `</select>` +
  1080. `</div>` +
  1081. `</div>` +
  1082. `</div>` +
  1083. `</div>` +
  1084. `</div>`
  1085. },
  1086. },
  1087. {
  1088. Kind: builder.DFKTextArea,
  1089. Caption: "Briefly",
  1090. Name: "briefly",
  1091. Value: data.A_briefly,
  1092. Classes: "briefly wysiwyg",
  1093. },
  1094. {
  1095. Kind: builder.DFKTextArea,
  1096. Caption: "Product content",
  1097. Name: "content",
  1098. Value: data.A_content,
  1099. Classes: "wysiwyg",
  1100. },
  1101. {
  1102. Kind: builder.DFKText,
  1103. Caption: "Product images",
  1104. Name: "",
  1105. Value: "",
  1106. CallBack: func(field *builder.DataFormField) string {
  1107. if data.A_id == 0 {
  1108. return ``
  1109. }
  1110. return `<div class="form-group n11">` +
  1111. `<div class="row">` +
  1112. `<div class="col-md-3">` +
  1113. `<label>Product images</label>` +
  1114. `</div>` +
  1115. `<div class="col-md-9">` +
  1116. `<div class="list-wrapper">` +
  1117. `<div id="list-images">` +
  1118. this.shop_GetAllProductImages(wrap, data.A_id) +
  1119. `</div>` +
  1120. `<div id="img-upload-block" class="list-button position-relative">` +
  1121. `<div id="upload-msg">Uploading...</div>` +
  1122. `<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 />` +
  1123. `</div>` +
  1124. `</div>` +
  1125. `</div>` +
  1126. `</div>` +
  1127. `</div>` +
  1128. `<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+1});});$('#list-images').addClass('loading');fave.ShopProductsImageReorder('shop-images-reorder',{Items:orderData});},});});</script>`
  1129. },
  1130. },
  1131. {
  1132. Kind: builder.DFKCheckBox,
  1133. Caption: "Active",
  1134. Name: "active",
  1135. Value: utils.IntToStr(data.A_active),
  1136. },
  1137. {
  1138. Kind: builder.DFKSubmit,
  1139. Value: btn_caption,
  1140. Target: "add-edit-button",
  1141. },
  1142. })
  1143. if wrap.CurrSubModule == "add" {
  1144. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1145. } else {
  1146. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1147. }
  1148. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1149. if wrap.CurrSubModule == "categories-add" {
  1150. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1151. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1152. {Name: "Add new category"},
  1153. })
  1154. } else {
  1155. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1156. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1157. {Name: "Modify category"},
  1158. })
  1159. }
  1160. data := utils.MySql_shop_category{
  1161. A_id: 0,
  1162. A_user: 0,
  1163. A_name: "",
  1164. A_alias: "",
  1165. A_lft: 0,
  1166. A_rgt: 0,
  1167. }
  1168. if wrap.CurrSubModule == "categories-modify" {
  1169. if len(wrap.UrlArgs) != 3 {
  1170. return "", "", ""
  1171. }
  1172. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1173. return "", "", ""
  1174. }
  1175. err := wrap.DB.QueryRow(`
  1176. SELECT
  1177. id,
  1178. user,
  1179. name,
  1180. alias,
  1181. lft,
  1182. rgt
  1183. FROM
  1184. shop_cats
  1185. WHERE
  1186. id = ?
  1187. LIMIT 1;`,
  1188. utils.StrToInt(wrap.UrlArgs[2]),
  1189. ).Scan(
  1190. &data.A_id,
  1191. &data.A_user,
  1192. &data.A_name,
  1193. &data.A_alias,
  1194. &data.A_lft,
  1195. &data.A_rgt,
  1196. )
  1197. if *wrap.LogCpError(&err) != nil {
  1198. return "", "", ""
  1199. }
  1200. }
  1201. btn_caption := "Add"
  1202. if wrap.CurrSubModule == "categories-modify" {
  1203. btn_caption = "Save"
  1204. }
  1205. parentId := 0
  1206. if wrap.CurrSubModule == "categories-modify" {
  1207. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1208. }
  1209. content += builder.DataForm(wrap, []builder.DataFormField{
  1210. {
  1211. Kind: builder.DFKHidden,
  1212. Name: "action",
  1213. Value: "shop-categories-modify",
  1214. },
  1215. {
  1216. Kind: builder.DFKHidden,
  1217. Name: "id",
  1218. Value: utils.IntToStr(data.A_id),
  1219. },
  1220. {
  1221. Kind: builder.DFKText,
  1222. Caption: "Parent",
  1223. Name: "parent",
  1224. Value: "0",
  1225. CallBack: func(field *builder.DataFormField) string {
  1226. return `<div class="form-group n2">` +
  1227. `<div class="row">` +
  1228. `<div class="col-md-3">` +
  1229. `<label for="lbl_parent">Parent</label>` +
  1230. `</div>` +
  1231. `<div class="col-md-9">` +
  1232. `<div>` +
  1233. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1234. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1235. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1236. `</select>` +
  1237. `</div>` +
  1238. `</div>` +
  1239. `</div>` +
  1240. `</div>`
  1241. },
  1242. },
  1243. {
  1244. Kind: builder.DFKText,
  1245. Caption: "Name",
  1246. Name: "name",
  1247. Value: data.A_name,
  1248. Required: true,
  1249. Min: "1",
  1250. Max: "255",
  1251. },
  1252. {
  1253. Kind: builder.DFKText,
  1254. Caption: "Alias",
  1255. Name: "alias",
  1256. Value: data.A_alias,
  1257. Hint: "Example: popular-products",
  1258. Max: "255",
  1259. },
  1260. {
  1261. Kind: builder.DFKSubmit,
  1262. Value: btn_caption,
  1263. Target: "add-edit-button",
  1264. },
  1265. })
  1266. if wrap.CurrSubModule == "categories-add" {
  1267. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1268. } else {
  1269. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1270. }
  1271. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1272. if wrap.CurrSubModule == "attributes-add" {
  1273. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1274. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1275. {Name: "Add new attribute"},
  1276. })
  1277. } else {
  1278. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1279. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1280. {Name: "Modify attribute"},
  1281. })
  1282. }
  1283. data := utils.MySql_shop_filter{
  1284. A_id: 0,
  1285. A_name: "",
  1286. A_filter: "",
  1287. }
  1288. if wrap.CurrSubModule == "attributes-modify" {
  1289. if len(wrap.UrlArgs) != 3 {
  1290. return "", "", ""
  1291. }
  1292. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1293. return "", "", ""
  1294. }
  1295. err := wrap.DB.QueryRow(`
  1296. SELECT
  1297. id,
  1298. name,
  1299. filter
  1300. FROM
  1301. shop_filters
  1302. WHERE
  1303. id = ?
  1304. LIMIT 1;`,
  1305. utils.StrToInt(wrap.UrlArgs[2]),
  1306. ).Scan(
  1307. &data.A_id,
  1308. &data.A_name,
  1309. &data.A_filter,
  1310. )
  1311. if *wrap.LogCpError(&err) != nil {
  1312. return "", "", ""
  1313. }
  1314. }
  1315. btn_caption := "Add"
  1316. if wrap.CurrSubModule == "attributes-modify" {
  1317. btn_caption = "Save"
  1318. }
  1319. content += builder.DataForm(wrap, []builder.DataFormField{
  1320. {
  1321. Kind: builder.DFKHidden,
  1322. Name: "action",
  1323. Value: "shop-attributes-modify",
  1324. },
  1325. {
  1326. Kind: builder.DFKHidden,
  1327. Name: "id",
  1328. Value: utils.IntToStr(data.A_id),
  1329. },
  1330. {
  1331. Kind: builder.DFKText,
  1332. Caption: "Attribute name",
  1333. Name: "name",
  1334. Value: data.A_name,
  1335. Required: true,
  1336. Min: "1",
  1337. Max: "255",
  1338. },
  1339. {
  1340. Kind: builder.DFKText,
  1341. Caption: "Attribute in filter",
  1342. Name: "filter",
  1343. Value: data.A_filter,
  1344. Required: true,
  1345. Min: "1",
  1346. Max: "255",
  1347. },
  1348. {
  1349. Kind: builder.DFKText,
  1350. Caption: "Attribute values",
  1351. Name: "",
  1352. Value: "",
  1353. CallBack: func(field *builder.DataFormField) string {
  1354. return `<div class="form-group n4">` +
  1355. `<div class="row">` +
  1356. `<div class="col-md-3">` +
  1357. `<label>Attribute values</label>` +
  1358. `</div>` +
  1359. `<div class="col-md-9">` +
  1360. `<div class="list-wrapper">` +
  1361. `<div id="list">` +
  1362. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1363. `</div>` +
  1364. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1365. `</div>` +
  1366. `</div>` +
  1367. `</div>` +
  1368. `</div>`
  1369. },
  1370. },
  1371. {
  1372. Kind: builder.DFKSubmit,
  1373. Value: btn_caption,
  1374. Target: "add-edit-button",
  1375. },
  1376. })
  1377. if wrap.CurrSubModule == "attributes-add" {
  1378. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1379. } else {
  1380. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1381. }
  1382. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1383. if wrap.CurrSubModule == "currencies-add" {
  1384. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1385. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1386. {Name: "Add new currency"},
  1387. })
  1388. } else {
  1389. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1390. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1391. {Name: "Modify currency"},
  1392. })
  1393. }
  1394. data := utils.MySql_shop_currency{
  1395. A_id: 0,
  1396. A_name: "",
  1397. A_coefficient: 0,
  1398. A_code: "",
  1399. A_symbol: "",
  1400. }
  1401. if wrap.CurrSubModule == "currencies-modify" {
  1402. if len(wrap.UrlArgs) != 3 {
  1403. return "", "", ""
  1404. }
  1405. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1406. return "", "", ""
  1407. }
  1408. err := wrap.DB.QueryRow(`
  1409. SELECT
  1410. id,
  1411. name,
  1412. coefficient,
  1413. code,
  1414. symbol
  1415. FROM
  1416. shop_currencies
  1417. WHERE
  1418. id = ?
  1419. LIMIT 1;`,
  1420. utils.StrToInt(wrap.UrlArgs[2]),
  1421. ).Scan(
  1422. &data.A_id,
  1423. &data.A_name,
  1424. &data.A_coefficient,
  1425. &data.A_code,
  1426. &data.A_symbol,
  1427. )
  1428. if *wrap.LogCpError(&err) != nil {
  1429. return "", "", ""
  1430. }
  1431. }
  1432. btn_caption := "Add"
  1433. if wrap.CurrSubModule == "currencies-modify" {
  1434. btn_caption = "Save"
  1435. }
  1436. content += builder.DataForm(wrap, []builder.DataFormField{
  1437. {
  1438. Kind: builder.DFKHidden,
  1439. Name: "action",
  1440. Value: "shop-currencies-modify",
  1441. },
  1442. {
  1443. Kind: builder.DFKHidden,
  1444. Name: "id",
  1445. Value: utils.IntToStr(data.A_id),
  1446. },
  1447. {
  1448. Kind: builder.DFKText,
  1449. Caption: "Currency name",
  1450. Name: "name",
  1451. Value: data.A_name,
  1452. Required: true,
  1453. Min: "1",
  1454. Max: "255",
  1455. },
  1456. {
  1457. Kind: builder.DFKText,
  1458. Caption: "Currency coefficient",
  1459. Name: "coefficient",
  1460. Value: "0",
  1461. CallBack: func(field *builder.DataFormField) string {
  1462. return `<div class="form-group n3">` +
  1463. `<div class="row">` +
  1464. `<div class="col-md-3">` +
  1465. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1466. `</div>` +
  1467. `<div class="col-md-9">` +
  1468. `<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>` +
  1469. `</div>` +
  1470. `</div>` +
  1471. `</div>`
  1472. },
  1473. },
  1474. {
  1475. Kind: builder.DFKText,
  1476. Caption: "Currency code",
  1477. Name: "code",
  1478. Value: data.A_code,
  1479. Required: true,
  1480. Min: "1",
  1481. Max: "10",
  1482. },
  1483. {
  1484. Kind: builder.DFKText,
  1485. Caption: "Currency symbol",
  1486. Name: "symbol",
  1487. Value: data.A_symbol,
  1488. Required: true,
  1489. Min: "1",
  1490. Max: "5",
  1491. },
  1492. {
  1493. Kind: builder.DFKSubmit,
  1494. Value: btn_caption,
  1495. Target: "add-edit-button",
  1496. },
  1497. })
  1498. if wrap.CurrSubModule == "currencies-add" {
  1499. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1500. } else {
  1501. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1502. }
  1503. }
  1504. return this.getSidebarModules(wrap), content, sidebar
  1505. })
  1506. }