module_shop.go 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. package modules
  2. import (
  3. "html"
  4. "net/http"
  5. "strings"
  6. "time"
  7. "golang-fave/engine/assets"
  8. "golang-fave/engine/basket"
  9. "golang-fave/engine/builder"
  10. "golang-fave/engine/consts"
  11. "golang-fave/engine/fetdata"
  12. "golang-fave/engine/sqlw"
  13. "golang-fave/engine/utils"
  14. "golang-fave/engine/wrapper"
  15. )
  16. func (this *Modules) shop_GetCurrencySelectOptions(wrap *wrapper.Wrapper, id int) string {
  17. result := ``
  18. rows, err := wrap.DB.Query(
  19. wrap.R.Context(),
  20. `SELECT
  21. id,
  22. code
  23. FROM
  24. fave_shop_currencies
  25. ORDER BY
  26. id ASC
  27. ;`,
  28. )
  29. if err == nil {
  30. defer rows.Close()
  31. values := make([]string, 2)
  32. scan := make([]interface{}, len(values))
  33. for i := range values {
  34. scan[i] = &values[i]
  35. }
  36. idStr := utils.IntToStr(id)
  37. for rows.Next() {
  38. err = rows.Scan(scan...)
  39. if *wrap.LogCpError(&err) == nil {
  40. selected := ""
  41. if string(values[0]) == idStr {
  42. selected = " selected"
  43. }
  44. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `"` + selected + `>` + html.EscapeString(string(values[1])) + `</option>`
  45. }
  46. }
  47. }
  48. return result
  49. }
  50. func (this *Modules) shop_GetProductValuesInputs(wrap *wrapper.Wrapper, product_id int) string {
  51. result := ``
  52. rows, err := wrap.DB.Query(
  53. wrap.R.Context(),
  54. `SELECT
  55. fave_shop_filters.id,
  56. fave_shop_filters.name,
  57. fave_shop_filters_values.id,
  58. fave_shop_filters_values.name,
  59. IF(fave_shop_filter_product_values.filter_value_id > 0, 1, 0) as selected
  60. FROM
  61. fave_shop_filters_values
  62. LEFT JOIN fave_shop_filters ON fave_shop_filters.id = fave_shop_filters_values.filter_id
  63. LEFT JOIN fave_shop_filter_product_values ON
  64. fave_shop_filter_product_values.filter_value_id = fave_shop_filters_values.id AND
  65. fave_shop_filter_product_values.product_id = `+utils.IntToStr(product_id)+`
  66. LEFT JOIN (
  67. SELECT
  68. fave_shop_filters_values.filter_id,
  69. fave_shop_filter_product_values.product_id
  70. FROM
  71. fave_shop_filter_product_values
  72. LEFT JOIN fave_shop_filters_values ON fave_shop_filters_values.id = fave_shop_filter_product_values.filter_value_id
  73. WHERE
  74. fave_shop_filter_product_values.product_id = `+utils.IntToStr(product_id)+`
  75. GROUP BY
  76. fave_shop_filters_values.filter_id
  77. ) as filter_used ON filter_used.filter_id = fave_shop_filters.id
  78. WHERE
  79. filter_used.filter_id IS NOT NULL
  80. ORDER BY
  81. fave_shop_filters.name ASC,
  82. fave_shop_filters_values.name ASC
  83. ;`,
  84. )
  85. filter_ids := []int{}
  86. filter_names := map[int]string{}
  87. filter_values := map[int][]string{}
  88. if err == nil {
  89. defer rows.Close()
  90. values := make([]string, 5)
  91. scan := make([]interface{}, len(values))
  92. for i := range values {
  93. scan[i] = &values[i]
  94. }
  95. for rows.Next() {
  96. err = rows.Scan(scan...)
  97. if *wrap.LogCpError(&err) == nil {
  98. filter_id := utils.StrToInt(string(values[0]))
  99. if !utils.InArrayInt(filter_ids, filter_id) {
  100. filter_ids = append(filter_ids, filter_id)
  101. }
  102. filter_names[filter_id] = html.EscapeString(string(values[1]))
  103. selected := ``
  104. if utils.StrToInt(string(values[4])) == 1 {
  105. selected = ` selected`
  106. }
  107. filter_values[filter_id] = append(filter_values[filter_id], `<option value="`+html.EscapeString(string(values[2]))+`"`+selected+`>`+html.EscapeString(string(values[3]))+`</option>`)
  108. }
  109. }
  110. }
  111. for _, filter_id := range filter_ids {
  112. result += `<div class="form-group" id="prod_attr_` + utils.IntToStr(filter_id) + `">` +
  113. `<div><b>` + filter_names[filter_id] + `</b></div>` +
  114. `<div class="position-relative">` +
  115. `<select class="selectpicker form-control" name="value.` + utils.IntToStr(filter_id) + `" autocomplete="off" required multiple>` +
  116. strings.Join(filter_values[filter_id], "") +
  117. `</select>` +
  118. `<button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopProductsRemove(this);">&times;</button>` +
  119. `</div>` +
  120. `</div>`
  121. }
  122. return result
  123. }
  124. func (this *Modules) shop_GetFilterValuesInputs(wrap *wrapper.Wrapper, filter_id int) string {
  125. result := ``
  126. rows, err := wrap.DB.Query(
  127. wrap.R.Context(),
  128. `SELECT
  129. id,
  130. name
  131. FROM
  132. fave_shop_filters_values
  133. WHERE
  134. filter_id = ?
  135. ORDER BY
  136. name ASC
  137. ;`,
  138. filter_id,
  139. )
  140. if err == nil {
  141. defer rows.Close()
  142. values := make([]string, 2)
  143. scan := make([]interface{}, len(values))
  144. for i := range values {
  145. scan[i] = &values[i]
  146. }
  147. for rows.Next() {
  148. err = rows.Scan(scan...)
  149. if *wrap.LogCpError(&err) == nil {
  150. 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>`
  151. }
  152. }
  153. }
  154. return result
  155. }
  156. func (this *Modules) shop_GetAllAttributesSelectOptions(wrap *wrapper.Wrapper) string {
  157. result := ``
  158. rows, err := wrap.DB.Query(
  159. wrap.R.Context(),
  160. `SELECT
  161. id,
  162. name,
  163. filter
  164. FROM
  165. fave_shop_filters
  166. ORDER BY
  167. name ASC
  168. ;`,
  169. )
  170. result += `<option title="&mdash;" value="0">&mdash;</option>`
  171. if err == nil {
  172. defer rows.Close()
  173. values := make([]string, 3)
  174. scan := make([]interface{}, len(values))
  175. for i := range values {
  176. scan[i] = &values[i]
  177. }
  178. for rows.Next() {
  179. err = rows.Scan(scan...)
  180. if *wrap.LogCpError(&err) == nil {
  181. result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `">` + html.EscapeString(string(values[1])) + `</option>`
  182. }
  183. }
  184. }
  185. return result
  186. }
  187. func (this *Modules) shop_GetAllCurrencies(wrap *wrapper.Wrapper) map[int]string {
  188. result := map[int]string{}
  189. rows, err := wrap.DB.Query(
  190. wrap.R.Context(),
  191. `SELECT
  192. id,
  193. code
  194. FROM
  195. fave_shop_currencies
  196. ORDER BY
  197. id ASC
  198. ;`,
  199. )
  200. if err == nil {
  201. defer rows.Close()
  202. values := make([]string, 2)
  203. scan := make([]interface{}, len(values))
  204. for i := range values {
  205. scan[i] = &values[i]
  206. }
  207. for rows.Next() {
  208. err = rows.Scan(scan...)
  209. if *wrap.LogCpError(&err) == nil {
  210. result[utils.StrToInt(string(values[0]))] = html.EscapeString(string(values[1]))
  211. }
  212. }
  213. }
  214. return result
  215. }
  216. func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id int) string {
  217. result := ``
  218. rows, err := wrap.DB.Query(
  219. wrap.R.Context(),
  220. `SELECT
  221. id,
  222. product_id,
  223. filename
  224. FROM
  225. fave_shop_product_images
  226. WHERE
  227. product_id = ?
  228. ORDER BY
  229. ord ASC
  230. ;`,
  231. product_id,
  232. )
  233. if err == nil {
  234. defer rows.Close()
  235. values := make([]string, 3)
  236. scan := make([]interface{}, len(values))
  237. for i := range values {
  238. scan[i] = &values[i]
  239. }
  240. for rows.Next() {
  241. err = rows.Scan(scan...)
  242. if *wrap.LogCpError(&err) == nil {
  243. 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>`
  244. }
  245. }
  246. }
  247. return result
  248. }
  249. func (this *Modules) shop_GetSubProducts(wrap *wrapper.Wrapper, id int) string {
  250. result := ``
  251. rows, err := wrap.DB.Query(
  252. wrap.R.Context(),
  253. `SELECT
  254. id,
  255. name
  256. FROM
  257. fave_shop_products
  258. WHERE
  259. parent_id = ?
  260. ORDER BY
  261. id DESC
  262. ;`,
  263. id,
  264. )
  265. if err == nil {
  266. defer rows.Close()
  267. values := make([]string, 2)
  268. scan := make([]interface{}, len(values))
  269. for i := range values {
  270. scan[i] = &values[i]
  271. }
  272. for rows.Next() {
  273. err = rows.Scan(scan...)
  274. if *wrap.LogCpError(&err) == nil {
  275. result += `<div><a href="/cp/` + wrap.CurrModule + `/modify/` + html.EscapeString(string(values[0])) + `/">` + html.EscapeString(string(values[1])) + ` ` + html.EscapeString(string(values[0])) + `</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>`
  276. }
  277. }
  278. }
  279. return result
  280. }
  281. func (this *Modules) shop_GetParentProduct(wrap *wrapper.Wrapper, id int) string {
  282. result := ``
  283. rows, err := wrap.DB.Query(
  284. wrap.R.Context(),
  285. `SELECT
  286. id,
  287. name
  288. FROM
  289. fave_shop_products
  290. WHERE
  291. id = ?
  292. ;`,
  293. id,
  294. )
  295. if err == nil {
  296. defer rows.Close()
  297. values := make([]string, 2)
  298. scan := make([]interface{}, len(values))
  299. for i := range values {
  300. scan[i] = &values[i]
  301. }
  302. for rows.Next() {
  303. err = rows.Scan(scan...)
  304. if *wrap.LogCpError(&err) == nil {
  305. result += `<div><a href="/cp/` + wrap.CurrModule + `/modify/` + html.EscapeString(string(values[0])) + `/">` + html.EscapeString(string(values[1])) + ` ` + html.EscapeString(string(values[0])) + `</a></div>`
  306. }
  307. }
  308. }
  309. return result
  310. }
  311. func (this *Modules) shop_GetOrderStatus(status int) string {
  312. if status == 0 {
  313. return `<span style="color:#f0ad4e;">New</span>`
  314. } else if status == 1 {
  315. return `<span style="color:#28a745;">Confirmed</span>`
  316. } else if status == 2 {
  317. return `<span style="color:#f0ad4e;">In progress</span>`
  318. } else if status == 3 {
  319. return `<span style="color:#d9534f;">Canceled</span>`
  320. } else if status == 4 {
  321. return `<span style="color:#6c757d;">Completed</span>`
  322. }
  323. return "Unknown"
  324. }
  325. func (this *Modules) RegisterModule_Shop() *Module {
  326. return this.newModule(MInfo{
  327. Mount: "shop",
  328. Name: "Shop",
  329. Order: 2,
  330. System: false,
  331. Icon: assets.SysSvgIconShop,
  332. Sub: &[]MISub{
  333. {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
  334. {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
  335. {Mount: "modify", Name: "Modify product", Show: false},
  336. {Sep: true, Show: true},
  337. {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
  338. {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
  339. {Mount: "categories-modify", Name: "Modify category", Show: false},
  340. {Sep: true, Show: true},
  341. {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
  342. {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
  343. {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
  344. {Sep: true, Show: true},
  345. {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
  346. {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
  347. {Mount: "currencies-modify", Name: "Modify currency", Show: false},
  348. {Sep: true, Show: true},
  349. {Mount: "orders", Name: "List of orders", Show: true, Icon: assets.SysSvgIconList},
  350. {Mount: "orders-modify", Name: "Viewing order", Show: false},
  351. },
  352. }, func(wrap *wrapper.Wrapper) {
  353. if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
  354. // Shop category
  355. row := &utils.MySql_shop_category{}
  356. rou := &utils.MySql_user{}
  357. err := wrap.DB.QueryRow(
  358. wrap.R.Context(),
  359. `SELECT
  360. main.id,
  361. main.user,
  362. main.name,
  363. main.alias,
  364. main.lft,
  365. main.rgt,
  366. main.depth,
  367. parent.id AS parent_id,
  368. fave_users.id,
  369. fave_users.first_name,
  370. fave_users.last_name,
  371. fave_users.email,
  372. fave_users.admin,
  373. fave_users.active
  374. FROM
  375. (
  376. SELECT
  377. node.id,
  378. node.user,
  379. node.name,
  380. node.alias,
  381. node.lft,
  382. node.rgt,
  383. (COUNT(parent.id) - 1) AS depth
  384. FROM
  385. fave_shop_cats AS node,
  386. fave_shop_cats AS parent
  387. WHERE
  388. node.lft BETWEEN parent.lft AND parent.rgt
  389. GROUP BY
  390. node.id
  391. ORDER BY
  392. node.lft ASC
  393. ) AS main
  394. LEFT JOIN (
  395. SELECT
  396. node.id,
  397. node.user,
  398. node.name,
  399. node.alias,
  400. node.lft,
  401. node.rgt,
  402. (COUNT(parent.id) - 0) AS depth
  403. FROM
  404. fave_shop_cats AS node,
  405. fave_shop_cats AS parent
  406. WHERE
  407. node.lft BETWEEN parent.lft AND parent.rgt
  408. GROUP BY
  409. node.id
  410. ORDER BY
  411. node.lft ASC
  412. ) AS parent ON
  413. parent.depth = main.depth AND
  414. main.lft > parent.lft AND
  415. main.rgt < parent.rgt
  416. LEFT JOIN fave_users ON fave_users.id = main.user
  417. WHERE
  418. main.id > 1 AND
  419. main.alias = ?
  420. ORDER BY
  421. main.lft ASC
  422. ;`,
  423. wrap.UrlArgs[2],
  424. ).Scan(
  425. &row.A_id,
  426. &row.A_user,
  427. &row.A_name,
  428. &row.A_alias,
  429. &row.A_lft,
  430. &row.A_rgt,
  431. &row.A_depth,
  432. &row.A_parent,
  433. &rou.A_id,
  434. &rou.A_first_name,
  435. &rou.A_last_name,
  436. &rou.A_email,
  437. &rou.A_admin,
  438. &rou.A_active,
  439. )
  440. if err != nil && err != wrapper.ErrNoRows {
  441. // System error 500
  442. wrap.LogCpError(&err)
  443. utils.SystemErrorPageEngine(wrap.W, err)
  444. return
  445. } else if err == wrapper.ErrNoRows {
  446. // User error 404 page
  447. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  448. return
  449. }
  450. // Fix url
  451. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  452. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  453. return
  454. }
  455. // Render template
  456. wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
  457. return
  458. } else if len(wrap.UrlArgs) >= 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "basket" && (wrap.UrlArgs[2] == "info" || wrap.UrlArgs[2] == "plus" || wrap.UrlArgs[2] == "minus" || wrap.UrlArgs[2] == "remove" || wrap.UrlArgs[2] == "currency") {
  459. SBParam := basket.SBParam{
  460. R: wrap.R,
  461. DB: wrap.DB,
  462. Host: wrap.CurrHost,
  463. Config: wrap.Config,
  464. SessionId: wrap.GetSessionId(),
  465. }
  466. if wrap.UrlArgs[2] == "info" {
  467. wrap.W.WriteHeader(http.StatusOK)
  468. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  469. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  470. wrap.W.Write([]byte(wrap.ShopBasket.Info(&SBParam)))
  471. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  472. return
  473. } else if wrap.UrlArgs[2] == "plus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  474. wrap.W.WriteHeader(http.StatusOK)
  475. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  476. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  477. wrap.W.Write([]byte(wrap.ShopBasket.Plus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  478. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  479. return
  480. } else if wrap.UrlArgs[2] == "minus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  481. wrap.W.WriteHeader(http.StatusOK)
  482. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  483. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  484. wrap.W.Write([]byte(wrap.ShopBasket.Minus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  485. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  486. return
  487. } else if wrap.UrlArgs[2] == "remove" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  488. wrap.W.WriteHeader(http.StatusOK)
  489. wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  490. wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
  491. wrap.W.Write([]byte(wrap.ShopBasket.Remove(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
  492. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  493. return
  494. } else if wrap.UrlArgs[2] == "currency" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
  495. http.SetCookie(wrap.W, &http.Cookie{
  496. Name: "currency",
  497. Value: wrap.UrlArgs[3],
  498. Path: "/",
  499. Expires: time.Now().Add(7 * 24 * time.Hour),
  500. HttpOnly: true,
  501. })
  502. redirectUrl := wrap.R.Referer()
  503. if redirectUrl == "" {
  504. redirectUrl = "/"
  505. }
  506. http.Redirect(wrap.W, wrap.R, redirectUrl, 302)
  507. wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
  508. return
  509. }
  510. } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
  511. // Shop product
  512. row := &utils.MySql_shop_product{}
  513. rou := &utils.MySql_user{}
  514. err := wrap.DB.QueryRow(
  515. wrap.R.Context(),
  516. `SELECT
  517. fave_shop_products.id,
  518. fave_shop_products.parent_id,
  519. fave_shop_products.user,
  520. fave_shop_products.currency,
  521. fave_shop_products.price,
  522. fave_shop_products.price_old,
  523. fave_shop_products.name,
  524. fave_shop_products.alias,
  525. fave_shop_products.vendor,
  526. fave_shop_products.quantity,
  527. fave_shop_products.category,
  528. fave_shop_products.briefly,
  529. fave_shop_products.content,
  530. UNIX_TIMESTAMP(fave_shop_products.datetime) as datetime,
  531. fave_shop_products.active,
  532. fave_users.id,
  533. fave_users.first_name,
  534. fave_users.last_name,
  535. fave_users.email,
  536. fave_users.admin,
  537. fave_users.active
  538. FROM
  539. fave_shop_products
  540. LEFT JOIN fave_users ON fave_users.id = fave_shop_products.user
  541. WHERE
  542. fave_shop_products.active = 1 and
  543. fave_shop_products.alias = ?
  544. LIMIT 1;`,
  545. wrap.UrlArgs[1],
  546. ).Scan(
  547. &row.A_id,
  548. &row.A_parent,
  549. &row.A_user,
  550. &row.A_currency,
  551. &row.A_price,
  552. &row.A_price_old,
  553. &row.A_name,
  554. &row.A_alias,
  555. &row.A_vendor,
  556. &row.A_quantity,
  557. &row.A_category,
  558. &row.A_briefly,
  559. &row.A_content,
  560. &row.A_datetime,
  561. &row.A_active,
  562. &rou.A_id,
  563. &rou.A_first_name,
  564. &rou.A_last_name,
  565. &rou.A_email,
  566. &rou.A_admin,
  567. &rou.A_active,
  568. )
  569. if err != nil && err != wrapper.ErrNoRows {
  570. // System error 500
  571. wrap.LogCpError(&err)
  572. utils.SystemErrorPageEngine(wrap.W, err)
  573. return
  574. } else if err == wrapper.ErrNoRows {
  575. // User error 404 page
  576. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  577. return
  578. }
  579. // Fix url
  580. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  581. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  582. return
  583. }
  584. // Render template
  585. wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
  586. return
  587. } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
  588. // Shop
  589. // Fix url
  590. if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
  591. http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
  592. return
  593. }
  594. // Render template
  595. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  596. return
  597. } else if (*wrap.Config).Engine.MainModule == 2 {
  598. // Render template
  599. wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
  600. return
  601. }
  602. // User error 404 page
  603. wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
  604. }, func(wrap *wrapper.Wrapper) (string, string, string) {
  605. content := ""
  606. sidebar := ""
  607. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  608. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  609. {Name: "List of products"},
  610. })
  611. // Load currencies
  612. currencies := this.shop_GetAllCurrencies(wrap)
  613. content += builder.DataTable(
  614. wrap,
  615. "fave_shop_products",
  616. "id",
  617. "DESC",
  618. &[]builder.DataTableRow{
  619. {
  620. DBField: "id",
  621. },
  622. {
  623. DBField: "name",
  624. NameInTable: "Product / URL",
  625. CallBack: func(values *[]string) string {
  626. name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` ` + html.EscapeString((*values)[0]) + `</a>`
  627. alias := html.EscapeString((*values)[2])
  628. parent := ``
  629. outofstock := ``
  630. if (*values)[7] != "" {
  631. parent = `<div class="parent">&uarr;<small><a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[7] + `/">` + html.EscapeString((*values)[8]) + ` ` + (*values)[7] + `</a></small></div>`
  632. }
  633. if utils.StrToInt((*values)[10]) <= 0 {
  634. outofstock = `<div><span class="badge badge-primary">Out of stock</span></div>`
  635. }
  636. return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>` + parent + outofstock
  637. },
  638. },
  639. {
  640. DBField: "alias",
  641. },
  642. {
  643. DBField: "currency",
  644. },
  645. {
  646. DBField: "price",
  647. NameInTable: "Price",
  648. Classes: "d-none d-md-table-cell",
  649. CallBack: func(values *[]string) string {
  650. price_old := ""
  651. price_promo := ""
  652. price_styles := ""
  653. if utils.StrToFloat64((*values)[9]) > 0 {
  654. price_old = `<div title="Old price"><strike>` + utils.Float64ToStr(utils.StrToFloat64((*values)[9])) + `</strike></div>`
  655. price_styles = ` style="color:#fb3f4c;"`
  656. }
  657. if utils.StrToFloat64((*values)[11]) > 0 {
  658. price_promo = `<div style="color:#ffc107;" title="Promo price">` + utils.Float64ToStr(utils.StrToFloat64((*values)[11])) + `</div>`
  659. }
  660. return price_promo + price_old + `<div` + price_styles + `title="Current price">` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
  661. `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
  662. },
  663. },
  664. {
  665. DBField: "datetime",
  666. DBExp: "UNIX_TIMESTAMP(`datetime`)",
  667. NameInTable: "Date / Time",
  668. Classes: "d-none d-lg-table-cell",
  669. CallBack: func(values *[]string) string {
  670. t := int64(utils.StrToInt((*values)[5]))
  671. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  672. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  673. },
  674. },
  675. {
  676. DBField: "active",
  677. NameInTable: "Active",
  678. Classes: "d-none d-sm-table-cell",
  679. CallBack: func(values *[]string) string {
  680. return builder.CheckBox(utils.StrToInt((*values)[6]))
  681. },
  682. },
  683. {
  684. DBField: "parent_id",
  685. },
  686. {
  687. DBField: "pname",
  688. DBExp: "spp.name",
  689. },
  690. {
  691. DBField: "price_old",
  692. },
  693. {
  694. DBField: "quantity",
  695. },
  696. {
  697. DBField: "price_promo",
  698. },
  699. },
  700. func(values *[]string) string {
  701. return builder.DataTableAction(&[]builder.DataTableActionRow{
  702. {
  703. Icon: assets.SysSvgIconView,
  704. Href: `/shop/` + (*values)[2] + `/`,
  705. Hint: "View",
  706. Target: "_blank",
  707. },
  708. {
  709. Icon: assets.SysSvgIconEdit,
  710. Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
  711. Hint: "Edit",
  712. },
  713. {
  714. Icon: assets.SysSvgIconRemove,
  715. Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
  716. (*values)[0] + "','Are you sure want to delete product?');",
  717. Hint: "Delete",
  718. Classes: "delete",
  719. },
  720. })
  721. },
  722. "/cp/"+wrap.CurrModule+"/",
  723. func() (int, error) {
  724. var count int
  725. return count, wrap.DB.QueryRow(
  726. wrap.R.Context(),
  727. "SELECT COUNT(*) FROM `fave_shop_products`;",
  728. ).Scan(&count)
  729. },
  730. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  731. return wrap.DB.Query(
  732. wrap.R.Context(),
  733. `SELECT
  734. fave_shop_products.id,
  735. fave_shop_products.name,
  736. fave_shop_products.alias,
  737. fave_shop_products.currency,
  738. fave_shop_products.price,
  739. UNIX_TIMESTAMP(`+"`fave_shop_products`.`datetime`"+`) AS datetime,
  740. fave_shop_products.active,
  741. fave_shop_products.parent_id,
  742. spp.name AS pname,
  743. fave_shop_products.price_old,
  744. fave_shop_products.quantity,
  745. fave_shop_products.price_promo
  746. FROM
  747. fave_shop_products
  748. LEFT JOIN fave_shop_products AS spp ON spp.id = fave_shop_products.parent_id
  749. ORDER BY
  750. fave_shop_products.id DESC
  751. LIMIT ?, ?;`,
  752. limit_offset,
  753. pear_page,
  754. )
  755. },
  756. true,
  757. )
  758. } else if wrap.CurrSubModule == "categories" {
  759. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  760. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  761. {Name: "List of categories"},
  762. })
  763. content += builder.DataTable(
  764. wrap,
  765. "fave_shop_cats",
  766. "id",
  767. "ASC",
  768. &[]builder.DataTableRow{
  769. {
  770. DBField: "id",
  771. },
  772. {
  773. DBField: "user",
  774. },
  775. {
  776. DBField: "name",
  777. NameInTable: "Category",
  778. CallBack: func(values *[]string) string {
  779. depth := utils.StrToInt((*values)[4]) - 1
  780. if depth < 0 {
  781. depth = 0
  782. }
  783. sub := strings.Repeat("&mdash; ", depth)
  784. name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
  785. return `<div>` + name + `</div>`
  786. },
  787. },
  788. {
  789. DBField: "alias",
  790. },
  791. {
  792. DBField: "depth",
  793. },
  794. },
  795. func(values *[]string) string {
  796. return builder.DataTableAction(&[]builder.DataTableActionRow{
  797. {
  798. Icon: assets.SysSvgIconView,
  799. Href: `/shop/category/` + (*values)[3] + `/`,
  800. Hint: "View",
  801. Target: "_blank",
  802. },
  803. {
  804. Icon: assets.SysSvgIconEdit,
  805. Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
  806. Hint: "Edit",
  807. },
  808. {
  809. Icon: assets.SysSvgIconRemove,
  810. Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
  811. (*values)[0] + "','Are you sure want to delete category?');",
  812. Hint: "Delete",
  813. Classes: "delete",
  814. },
  815. })
  816. },
  817. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  818. nil,
  819. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  820. return wrap.DB.Query(
  821. wrap.R.Context(),
  822. `SELECT
  823. node.id,
  824. node.user,
  825. node.name,
  826. node.alias,
  827. (COUNT(parent.id) - 1) AS depth
  828. FROM
  829. fave_shop_cats AS node,
  830. fave_shop_cats AS parent
  831. WHERE
  832. node.lft BETWEEN parent.lft AND parent.rgt AND
  833. node.id > 1
  834. GROUP BY
  835. node.id
  836. ORDER BY
  837. node.lft ASC
  838. ;`,
  839. )
  840. },
  841. false,
  842. )
  843. } else if wrap.CurrSubModule == "attributes" {
  844. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  845. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  846. {Name: "List of attributes"},
  847. })
  848. content += builder.DataTable(
  849. wrap,
  850. "fave_shop_filters",
  851. "id",
  852. "DESC",
  853. &[]builder.DataTableRow{
  854. {
  855. DBField: "id",
  856. },
  857. {
  858. DBField: "name",
  859. NameInTable: "Name",
  860. CallBack: func(values *[]string) string {
  861. name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
  862. return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
  863. },
  864. },
  865. {
  866. DBField: "filter",
  867. },
  868. },
  869. func(values *[]string) string {
  870. return builder.DataTableAction(&[]builder.DataTableActionRow{
  871. {
  872. Icon: assets.SysSvgIconEdit,
  873. Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
  874. Hint: "Edit",
  875. },
  876. {
  877. Icon: assets.SysSvgIconRemove,
  878. Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
  879. (*values)[0] + "','Are you sure want to delete attribute?');",
  880. Hint: "Delete",
  881. Classes: "delete",
  882. },
  883. })
  884. },
  885. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  886. nil,
  887. nil,
  888. true,
  889. )
  890. } else if wrap.CurrSubModule == "currencies" {
  891. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  892. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  893. {Name: "List of currencies"},
  894. })
  895. content += builder.DataTable(
  896. wrap,
  897. "fave_shop_currencies",
  898. "id",
  899. "DESC",
  900. &[]builder.DataTableRow{
  901. {
  902. DBField: "id",
  903. },
  904. {
  905. DBField: "name",
  906. NameInTable: "Name",
  907. CallBack: func(values *[]string) string {
  908. name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
  909. return `<div>` + name + `</div>`
  910. },
  911. },
  912. {
  913. DBField: "coefficient",
  914. NameInTable: "Coefficient",
  915. Classes: "d-none d-md-table-cell",
  916. CallBack: func(values *[]string) string {
  917. return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
  918. },
  919. },
  920. {
  921. DBField: "code",
  922. },
  923. {
  924. DBField: "symbol",
  925. },
  926. },
  927. func(values *[]string) string {
  928. return builder.DataTableAction(&[]builder.DataTableActionRow{
  929. {
  930. Icon: assets.SysSvgIconEdit,
  931. Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
  932. Hint: "Edit",
  933. },
  934. {
  935. Icon: assets.SysSvgIconRemove,
  936. Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
  937. (*values)[0] + "','Are you sure want to delete currency?');",
  938. Hint: "Delete",
  939. Classes: "delete",
  940. },
  941. })
  942. },
  943. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  944. nil,
  945. nil,
  946. true,
  947. )
  948. } else if wrap.CurrSubModule == "orders" {
  949. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  950. {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
  951. {Name: "List of orders"},
  952. })
  953. content += builder.DataTable(
  954. wrap,
  955. "fave_shop_orders",
  956. "id",
  957. "DESC",
  958. &[]builder.DataTableRow{
  959. {
  960. DBField: "id",
  961. NameInTable: "Order #",
  962. Classes: "d-none d-lg-table-cell",
  963. },
  964. {
  965. DBField: "client_phone",
  966. },
  967. {
  968. DBField: "update_datetime",
  969. },
  970. {
  971. DBField: "currency_id",
  972. },
  973. {
  974. DBField: "currency_name",
  975. },
  976. {
  977. DBField: "currency_coefficient",
  978. },
  979. {
  980. DBField: "currency_code",
  981. },
  982. {
  983. DBField: "currency_symbol",
  984. },
  985. {
  986. DBField: "client_last_name",
  987. NameInTable: "Client / Contact",
  988. CallBack: func(values *[]string) string {
  989. link := "/cp/" + wrap.CurrModule + "/orders-modify/" + (*values)[0] + "/"
  990. last_name := html.EscapeString((*values)[8])
  991. first_name := html.EscapeString((*values)[9])
  992. middle_name := html.EscapeString((*values)[10])
  993. phone := html.EscapeString((*values)[1])
  994. email := html.EscapeString((*values)[12])
  995. order_id := `<span class="d-inline d-sm-none">#` + (*values)[0] + `. </span>`
  996. name := ""
  997. if last_name != "" {
  998. name += " " + last_name
  999. }
  1000. if first_name != "" {
  1001. name += " " + first_name
  1002. }
  1003. if middle_name != "" {
  1004. name += " " + middle_name
  1005. }
  1006. name = `<a href="` + link + `">` + order_id + utils.Trim(name) + `</a>`
  1007. contact := ""
  1008. if email != "" {
  1009. contact += " " + email
  1010. }
  1011. if phone != "" {
  1012. contact += " (" + phone + ")"
  1013. }
  1014. contact = `<a href="` + link + `">` + utils.Trim(contact) + `</a>`
  1015. return `<div>` + name + `</div><div><small>` + contact + `</small></div>`
  1016. },
  1017. },
  1018. {
  1019. DBField: "client_first_name",
  1020. },
  1021. {
  1022. DBField: "client_middle_name",
  1023. },
  1024. {
  1025. DBField: "create_datetime",
  1026. DBExp: "UNIX_TIMESTAMP(`create_datetime`)",
  1027. NameInTable: "Date / Time",
  1028. Classes: "d-none d-lg-table-cell",
  1029. CallBack: func(values *[]string) string {
  1030. t := int64(utils.StrToInt((*values)[11]))
  1031. return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
  1032. `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
  1033. },
  1034. },
  1035. {
  1036. DBField: "client_email",
  1037. NameInTable: "Status / Total",
  1038. CallBack: func(values *[]string) string {
  1039. status := this.shop_GetOrderStatus(utils.StrToInt((*values)[15]))
  1040. total := utils.Float64ToStr(utils.StrToFloat64((*values)[16])) + " " + html.EscapeString((*values)[6])
  1041. return `<div>` + status + `</div><div><small>` + total + `</small></div>`
  1042. },
  1043. },
  1044. {
  1045. DBField: "client_delivery_comment",
  1046. },
  1047. {
  1048. DBField: "client_order_comment",
  1049. },
  1050. {
  1051. DBField: "status",
  1052. },
  1053. {
  1054. DBField: "total",
  1055. },
  1056. },
  1057. nil,
  1058. "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
  1059. nil,
  1060. func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
  1061. return wrap.DB.Query(
  1062. wrap.R.Context(),
  1063. `SELECT
  1064. fave_shop_orders.id,
  1065. fave_shop_orders.client_phone,
  1066. fave_shop_orders.update_datetime,
  1067. fave_shop_orders.currency_id,
  1068. fave_shop_orders.currency_name,
  1069. fave_shop_orders.currency_coefficient,
  1070. fave_shop_orders.currency_code,
  1071. fave_shop_orders.currency_symbol,
  1072. fave_shop_orders.client_last_name,
  1073. fave_shop_orders.client_first_name,
  1074. fave_shop_orders.client_middle_name,
  1075. UNIX_TIMESTAMP(fave_shop_orders.create_datetime) as create_datetime,
  1076. fave_shop_orders.client_email,
  1077. fave_shop_orders.client_delivery_comment,
  1078. fave_shop_orders.client_order_comment,
  1079. fave_shop_orders.status,
  1080. shop_order_total.total
  1081. FROM
  1082. fave_shop_orders
  1083. LEFT JOIN (
  1084. SELECT
  1085. order_id,
  1086. SUM(price * quantity) as total
  1087. FROM
  1088. fave_shop_order_products
  1089. GROUP BY
  1090. order_id
  1091. ) as shop_order_total ON shop_order_total.order_id = fave_shop_orders.id
  1092. ORDER BY
  1093. fave_shop_orders.status ASC,
  1094. fave_shop_orders.id DESC
  1095. LIMIT ?, ?;`,
  1096. limit_offset,
  1097. pear_page,
  1098. )
  1099. },
  1100. true,
  1101. )
  1102. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  1103. if wrap.CurrSubModule == "add" {
  1104. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1105. {Name: "Add new product"},
  1106. })
  1107. } else {
  1108. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  1109. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  1110. content += `<div class="product-another"><a title="Duplicate product and attach" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
  1111. }
  1112. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1113. {Name: "Modify product"},
  1114. })
  1115. }
  1116. data := utils.MySql_shop_product{
  1117. A_id: 0,
  1118. A_user: 0,
  1119. A_currency: 0,
  1120. A_price: 0,
  1121. A_price_old: 0,
  1122. A_gname: "",
  1123. A_name: "",
  1124. A_alias: "",
  1125. A_vendor: "",
  1126. A_quantity: 0,
  1127. A_category: 0,
  1128. A_briefly: "",
  1129. A_content: "",
  1130. A_datetime: 0,
  1131. A_active: 0,
  1132. A_custom1: "",
  1133. A_custom2: "",
  1134. }
  1135. if wrap.CurrSubModule == "modify" {
  1136. if len(wrap.UrlArgs) != 3 {
  1137. return "", "", ""
  1138. }
  1139. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1140. return "", "", ""
  1141. }
  1142. err := wrap.DB.QueryRow(
  1143. wrap.R.Context(),
  1144. `SELECT
  1145. id,
  1146. parent_id,
  1147. user,
  1148. currency,
  1149. price,
  1150. price_old,
  1151. price_promo,
  1152. gname,
  1153. name,
  1154. alias,
  1155. vendor,
  1156. quantity,
  1157. category,
  1158. briefly,
  1159. content,
  1160. active,
  1161. custom1,
  1162. custom2
  1163. FROM
  1164. fave_shop_products
  1165. WHERE
  1166. id = ?
  1167. LIMIT 1;`,
  1168. utils.StrToInt(wrap.UrlArgs[2]),
  1169. ).Scan(
  1170. &data.A_id,
  1171. &data.A_parent,
  1172. &data.A_user,
  1173. &data.A_currency,
  1174. &data.A_price,
  1175. &data.A_price_old,
  1176. &data.A_price_promo,
  1177. &data.A_gname,
  1178. &data.A_name,
  1179. &data.A_alias,
  1180. &data.A_vendor,
  1181. &data.A_quantity,
  1182. &data.A_category,
  1183. &data.A_briefly,
  1184. &data.A_content,
  1185. &data.A_active,
  1186. &data.A_custom1,
  1187. &data.A_custom2,
  1188. )
  1189. if *wrap.LogCpError(&err) != nil {
  1190. return "", "", ""
  1191. }
  1192. }
  1193. if data.A_parent_id() > 0 {
  1194. content += `<style>.product-another{display:none}</style>`
  1195. }
  1196. // All product current categories
  1197. var selids []int
  1198. if data.A_id > 0 {
  1199. rows, err := wrap.DB.Query(wrap.R.Context(), "SELECT category_id FROM fave_shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  1200. if err == nil {
  1201. defer rows.Close()
  1202. values := make([]int, 1)
  1203. scan := make([]interface{}, len(values))
  1204. for i := range values {
  1205. scan[i] = &values[i]
  1206. }
  1207. for rows.Next() {
  1208. err = rows.Scan(scan...)
  1209. if *wrap.LogCpError(&err) == nil {
  1210. selids = append(selids, int(values[0]))
  1211. }
  1212. }
  1213. }
  1214. }
  1215. // Sub products
  1216. sub_products := ``
  1217. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1218. sub_products = this.shop_GetSubProducts(wrap, data.A_id)
  1219. }
  1220. btn_caption := "Add"
  1221. if wrap.CurrSubModule == "modify" {
  1222. btn_caption = "Save"
  1223. }
  1224. content += builder.DataForm(wrap, []builder.DataFormField{
  1225. {
  1226. Kind: builder.DFKHidden,
  1227. Name: "action",
  1228. Value: "shop-modify",
  1229. },
  1230. {
  1231. Kind: builder.DFKHidden,
  1232. Name: "id",
  1233. Value: utils.IntToStr(data.A_id),
  1234. },
  1235. {
  1236. Kind: builder.DFKText,
  1237. CallBack: func(field *builder.DataFormField) string {
  1238. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1239. return `<div class="form-group nf">` +
  1240. `<div class="row">` +
  1241. `<div class="col-md-3">` +
  1242. `<label>Sub products</label>` +
  1243. `</div>` +
  1244. `<div class="col-md-9">` +
  1245. `<div class="list-wrapper">` +
  1246. sub_products +
  1247. `<div><a href="javascript:fave.ShopAttachProduct(` + utils.IntToStr(data.A_id) + `);"><b>Attach product</b></a></div>` +
  1248. `</div>` +
  1249. `</div>` +
  1250. `</div>` +
  1251. `</div>`
  1252. }
  1253. return ""
  1254. },
  1255. },
  1256. {
  1257. Kind: builder.DFKText,
  1258. CallBack: func(field *builder.DataFormField) string {
  1259. if data.A_id >= 1 && data.A_parent_id() != 0 {
  1260. return `<div class="form-group nf">` +
  1261. `<div class="row">` +
  1262. `<div class="col-md-3">` +
  1263. `<label>Parent</label>` +
  1264. `</div>` +
  1265. `<div class="col-md-9">` +
  1266. `<div class="list-wrapper">` +
  1267. this.shop_GetParentProduct(wrap, data.A_parent_id()) +
  1268. `</div>` +
  1269. `</div>` +
  1270. `</div>` +
  1271. `</div>`
  1272. }
  1273. return ""
  1274. },
  1275. },
  1276. {
  1277. Kind: builder.DFKText,
  1278. CallBack: func(field *builder.DataFormField) string {
  1279. if data.A_id >= 1 && data.A_parent_id() <= 0 && sub_products != "" {
  1280. return `<div class="form-group nf">` +
  1281. `<div class="row">` +
  1282. `<div class="col-md-3">` +
  1283. `<label for="lbl_gname">Group name</label>` +
  1284. `</div>` +
  1285. `<div class="col-md-9">` +
  1286. `<div><input class="form-control" type="text" id="lbl_gname" name="gname" value="` + html.EscapeString(data.A_gname) + `" maxlength="255" autocomplete="off"></div>` +
  1287. `</div>` +
  1288. `</div>` +
  1289. `</div>`
  1290. }
  1291. return ""
  1292. },
  1293. },
  1294. {
  1295. Kind: builder.DFKText,
  1296. Caption: "Product name",
  1297. Name: "name",
  1298. Value: data.A_name,
  1299. Required: true,
  1300. Min: "1",
  1301. Max: "255",
  1302. },
  1303. {
  1304. Kind: builder.DFKText,
  1305. Caption: "Product price",
  1306. Name: "price",
  1307. Value: "0",
  1308. CallBack: func(field *builder.DataFormField) string {
  1309. return `<div class="form-group n6">` +
  1310. `<div class="row">` +
  1311. `<div class="col-md-3">` +
  1312. `<label for="lbl_price">Product price</label>` +
  1313. `</div>` +
  1314. `<div class="col-md-9">` +
  1315. `<div>` +
  1316. `<div class="row">` +
  1317. `<div class="col-md-8">` +
  1318. `<div class="row">` +
  1319. `<div class="col-md-12">` +
  1320. `<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>` +
  1321. `</div>` +
  1322. `</div>` +
  1323. `<div class="d-md-none mb-3"></div>` +
  1324. `</div>` +
  1325. `<div class="col-md-4">` +
  1326. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  1327. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  1328. `</select>` +
  1329. `</div>` +
  1330. `</div>` +
  1331. `</div>` +
  1332. `</div>` +
  1333. `</div>` +
  1334. `</div>`
  1335. },
  1336. },
  1337. {
  1338. Kind: builder.DFKText,
  1339. Caption: "Old/Promo price",
  1340. Name: "price_old",
  1341. Value: "0",
  1342. CallBack: func(field *builder.DataFormField) string {
  1343. return `<div class="form-group n6">` +
  1344. `<div class="row">` +
  1345. `<div class="col-md-3">` +
  1346. `<label for="lbl_price_old">Old/Promo price</label>` +
  1347. `</div>` +
  1348. `<div class="col-md-9">` +
  1349. `<div>` +
  1350. `<div class="row">` +
  1351. `<div class="col-md-12">` +
  1352. `<div class="row">` +
  1353. `<div class="col-md-6">` +
  1354. `<div><input class="form-control" type="number" id="lbl_price_old" name="price_old" value="` + utils.Float64ToStr(data.A_price_old) + `" placeholder="" autocomplete="off"></div>` +
  1355. `<div class="d-md-none mb-3"></div>` +
  1356. `</div>` +
  1357. `<div class="col-md-6">` +
  1358. `<div><input class="form-control" type="number" id="lbl_price_promo" name="price_promo" value="` + utils.Float64ToStr(data.A_price_promo) + `" placeholder="" autocomplete="off"></div>` +
  1359. `</div>` +
  1360. `</div>` +
  1361. `</div>` +
  1362. `</div>` +
  1363. `</div>` +
  1364. `</div>` +
  1365. `</div>` +
  1366. `</div>`
  1367. },
  1368. },
  1369. {
  1370. Kind: builder.DFKText,
  1371. Caption: "Product alias",
  1372. Name: "alias",
  1373. Value: data.A_alias,
  1374. Hint: "Example: mobile-phone",
  1375. Max: "255",
  1376. },
  1377. {
  1378. Kind: builder.DFKText,
  1379. Caption: "Vendor/Count",
  1380. Name: "vendor",
  1381. Value: "0",
  1382. CallBack: func(field *builder.DataFormField) string {
  1383. return `<div class="form-group n8">` +
  1384. `<div class="row">` +
  1385. `<div class="col-md-3">` +
  1386. `<label for="lbl_vendor">Vendor/Count</label>` +
  1387. `</div>` +
  1388. `<div class="col-md-9">` +
  1389. `<div>` +
  1390. `<div class="row">` +
  1391. `<div class="col-md-8">` +
  1392. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  1393. `<div class="d-md-none mb-3"></div>` +
  1394. `</div>` +
  1395. `<div class="col-md-4">` +
  1396. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  1397. `</div>` +
  1398. `</div>` +
  1399. `</div>` +
  1400. `</div>` +
  1401. `</div>` +
  1402. `</div>`
  1403. },
  1404. },
  1405. {
  1406. Kind: builder.DFKText,
  1407. Caption: "Category",
  1408. Name: "category",
  1409. Value: "0",
  1410. CallBack: func(field *builder.DataFormField) string {
  1411. return `<div class="form-group n9">` +
  1412. `<div class="row">` +
  1413. `<div class="col-md-3">` +
  1414. `<label for="lbl_category">Category</label>` +
  1415. `</div>` +
  1416. `<div class="col-md-9">` +
  1417. `<div>` +
  1418. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  1419. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1420. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  1421. `</select>` +
  1422. `</div>` +
  1423. `</div>` +
  1424. `</div>` +
  1425. `</div>`
  1426. },
  1427. },
  1428. {
  1429. Kind: builder.DFKText,
  1430. Caption: "Categories",
  1431. Name: "cats",
  1432. Value: "0",
  1433. CallBack: func(field *builder.DataFormField) string {
  1434. return `<div class="form-group n10">` +
  1435. `<div class="row">` +
  1436. `<div class="col-md-3">` +
  1437. `<label for="lbl_cats">Categories</label>` +
  1438. `</div>` +
  1439. `<div class="col-md-9">` +
  1440. `<div>` +
  1441. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  1442. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  1443. `</select>` +
  1444. `</div>` +
  1445. `</div>` +
  1446. `</div>` +
  1447. `</div>`
  1448. },
  1449. },
  1450. {
  1451. Kind: builder.DFKText,
  1452. Caption: "Attributes",
  1453. Name: "",
  1454. Value: "",
  1455. CallBack: func(field *builder.DataFormField) string {
  1456. return `<div class="form-group n11">` +
  1457. `<div class="row">` +
  1458. `<div class="col-md-3">` +
  1459. `<label>Attributes</label>` +
  1460. `</div>` +
  1461. `<div class="col-md-9">` +
  1462. `<div class="list-wrapper">` +
  1463. `<div id="list">` +
  1464. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  1465. `</div>` +
  1466. `<div class="list-button position-relative">` +
  1467. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  1468. this.shop_GetAllAttributesSelectOptions(wrap) +
  1469. `</select>` +
  1470. `</div>` +
  1471. `</div>` +
  1472. `</div>` +
  1473. `</div>` +
  1474. `</div>`
  1475. },
  1476. },
  1477. {
  1478. Kind: builder.DFKTextArea,
  1479. Caption: "Briefly",
  1480. Name: "briefly",
  1481. Value: data.A_briefly,
  1482. Classes: "briefly wysiwyg",
  1483. },
  1484. {
  1485. Kind: builder.DFKTextArea,
  1486. Caption: "Product content",
  1487. Name: "content",
  1488. Value: data.A_content,
  1489. Classes: "wysiwyg",
  1490. },
  1491. {
  1492. Kind: builder.DFKText,
  1493. Caption: "Product images",
  1494. Name: "",
  1495. Value: "",
  1496. CallBack: func(field *builder.DataFormField) string {
  1497. if data.A_id == 0 {
  1498. return ``
  1499. }
  1500. return `<div class="form-group n14">` +
  1501. `<div class="row">` +
  1502. `<div class="col-md-3">` +
  1503. `<label>Product images</label>` +
  1504. `</div>` +
  1505. `<div class="col-md-9">` +
  1506. `<div class="list-wrapper">` +
  1507. `<div id="list-images">` +
  1508. this.shop_GetAllProductImages(wrap, data.A_id) +
  1509. `</div>` +
  1510. `<div id="img-upload-block" class="list-button position-relative">` +
  1511. `<div id="upload-msg">Uploading...</div>` +
  1512. `<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:12px;" multiple />` +
  1513. `</div>` +
  1514. `</div>` +
  1515. `</div>` +
  1516. `</div>` +
  1517. `</div>` +
  1518. `<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>`
  1519. },
  1520. },
  1521. {
  1522. Kind: builder.DFKText,
  1523. Caption: "Custom field 1",
  1524. Name: "",
  1525. Value: "",
  1526. CallBack: func(field *builder.DataFormField) string {
  1527. if (*wrap.Config).Shop.CustomFields.Field1.Enabled <= 0 {
  1528. return ``
  1529. }
  1530. return `<div class="form-group nf">
  1531. <div class="row">
  1532. <div class="col-md-3">
  1533. <label for="lbl_custom1">` + (*wrap.Config).Shop.CustomFields.Field1.Caption + `</label>
  1534. </div>
  1535. <div class="col-md-9">
  1536. <div><input class="form-control" type="text" id="lbl_custom1" name="custom1" value="` + html.EscapeString(data.A_custom1) + `" maxlength="2048" autocomplete="off"></div>
  1537. </div>
  1538. </div>
  1539. </div>`
  1540. },
  1541. },
  1542. {
  1543. Kind: builder.DFKText,
  1544. Caption: "Custom field 2",
  1545. Name: "",
  1546. Value: "",
  1547. CallBack: func(field *builder.DataFormField) string {
  1548. if (*wrap.Config).Shop.CustomFields.Field2.Enabled <= 0 {
  1549. return ``
  1550. }
  1551. return `<div class="form-group nf">
  1552. <div class="row">
  1553. <div class="col-md-3">
  1554. <label for="lbl_custom2">` + (*wrap.Config).Shop.CustomFields.Field2.Caption + `</label>
  1555. </div>
  1556. <div class="col-md-9">
  1557. <div><input class="form-control" type="text" id="lbl_custom2" name="custom2" value="` + html.EscapeString(data.A_custom2) + `" maxlength="2048" autocomplete="off"></div>
  1558. </div>
  1559. </div>
  1560. </div>`
  1561. },
  1562. },
  1563. {
  1564. Kind: builder.DFKCheckBox,
  1565. Caption: "Active",
  1566. Name: "active",
  1567. Value: utils.IntToStr(data.A_active),
  1568. },
  1569. {
  1570. Kind: builder.DFKSubmit,
  1571. Value: btn_caption,
  1572. Target: "add-edit-button",
  1573. },
  1574. })
  1575. if wrap.CurrSubModule == "add" {
  1576. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1577. } else {
  1578. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1579. }
  1580. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1581. if wrap.CurrSubModule == "categories-add" {
  1582. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1583. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1584. {Name: "Add new category"},
  1585. })
  1586. } else {
  1587. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1588. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1589. {Name: "Modify category"},
  1590. })
  1591. }
  1592. data := utils.MySql_shop_category{
  1593. A_id: 0,
  1594. A_user: 0,
  1595. A_name: "",
  1596. A_alias: "",
  1597. A_lft: 0,
  1598. A_rgt: 0,
  1599. }
  1600. if wrap.CurrSubModule == "categories-modify" {
  1601. if len(wrap.UrlArgs) != 3 {
  1602. return "", "", ""
  1603. }
  1604. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1605. return "", "", ""
  1606. }
  1607. err := wrap.DB.QueryRow(
  1608. wrap.R.Context(),
  1609. `SELECT
  1610. id,
  1611. user,
  1612. name,
  1613. alias,
  1614. lft,
  1615. rgt
  1616. FROM
  1617. fave_shop_cats
  1618. WHERE
  1619. id = ?
  1620. LIMIT 1;`,
  1621. utils.StrToInt(wrap.UrlArgs[2]),
  1622. ).Scan(
  1623. &data.A_id,
  1624. &data.A_user,
  1625. &data.A_name,
  1626. &data.A_alias,
  1627. &data.A_lft,
  1628. &data.A_rgt,
  1629. )
  1630. if *wrap.LogCpError(&err) != nil {
  1631. return "", "", ""
  1632. }
  1633. }
  1634. btn_caption := "Add"
  1635. if wrap.CurrSubModule == "categories-modify" {
  1636. btn_caption = "Save"
  1637. }
  1638. parentId := 0
  1639. if wrap.CurrSubModule == "categories-modify" {
  1640. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1641. }
  1642. content += builder.DataForm(wrap, []builder.DataFormField{
  1643. {
  1644. Kind: builder.DFKHidden,
  1645. Name: "action",
  1646. Value: "shop-categories-modify",
  1647. },
  1648. {
  1649. Kind: builder.DFKHidden,
  1650. Name: "id",
  1651. Value: utils.IntToStr(data.A_id),
  1652. },
  1653. {
  1654. Kind: builder.DFKText,
  1655. Caption: "Parent",
  1656. Name: "parent",
  1657. Value: "0",
  1658. CallBack: func(field *builder.DataFormField) string {
  1659. return `<div class="form-group n2">` +
  1660. `<div class="row">` +
  1661. `<div class="col-md-3">` +
  1662. `<label for="lbl_parent">Parent</label>` +
  1663. `</div>` +
  1664. `<div class="col-md-9">` +
  1665. `<div>` +
  1666. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1667. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1668. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1669. `</select>` +
  1670. `</div>` +
  1671. `</div>` +
  1672. `</div>` +
  1673. `</div>`
  1674. },
  1675. },
  1676. {
  1677. Kind: builder.DFKText,
  1678. Caption: "Name",
  1679. Name: "name",
  1680. Value: data.A_name,
  1681. Required: true,
  1682. Min: "1",
  1683. Max: "255",
  1684. },
  1685. {
  1686. Kind: builder.DFKText,
  1687. Caption: "Alias",
  1688. Name: "alias",
  1689. Value: data.A_alias,
  1690. Hint: "Example: popular-products",
  1691. Max: "255",
  1692. },
  1693. {
  1694. Kind: builder.DFKSubmit,
  1695. Value: btn_caption,
  1696. Target: "add-edit-button",
  1697. },
  1698. })
  1699. if wrap.CurrSubModule == "categories-add" {
  1700. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1701. } else {
  1702. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1703. }
  1704. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1705. if wrap.CurrSubModule == "attributes-add" {
  1706. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1707. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1708. {Name: "Add new attribute"},
  1709. })
  1710. } else {
  1711. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1712. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1713. {Name: "Modify attribute"},
  1714. })
  1715. }
  1716. data := utils.MySql_shop_filter{
  1717. A_id: 0,
  1718. A_name: "",
  1719. A_filter: "",
  1720. }
  1721. if wrap.CurrSubModule == "attributes-modify" {
  1722. if len(wrap.UrlArgs) != 3 {
  1723. return "", "", ""
  1724. }
  1725. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1726. return "", "", ""
  1727. }
  1728. err := wrap.DB.QueryRow(
  1729. wrap.R.Context(),
  1730. `SELECT
  1731. id,
  1732. name,
  1733. filter
  1734. FROM
  1735. fave_shop_filters
  1736. WHERE
  1737. id = ?
  1738. LIMIT 1;`,
  1739. utils.StrToInt(wrap.UrlArgs[2]),
  1740. ).Scan(
  1741. &data.A_id,
  1742. &data.A_name,
  1743. &data.A_filter,
  1744. )
  1745. if *wrap.LogCpError(&err) != nil {
  1746. return "", "", ""
  1747. }
  1748. }
  1749. btn_caption := "Add"
  1750. if wrap.CurrSubModule == "attributes-modify" {
  1751. btn_caption = "Save"
  1752. }
  1753. content += builder.DataForm(wrap, []builder.DataFormField{
  1754. {
  1755. Kind: builder.DFKHidden,
  1756. Name: "action",
  1757. Value: "shop-attributes-modify",
  1758. },
  1759. {
  1760. Kind: builder.DFKHidden,
  1761. Name: "id",
  1762. Value: utils.IntToStr(data.A_id),
  1763. },
  1764. {
  1765. Kind: builder.DFKText,
  1766. Caption: "Attribute name",
  1767. Name: "name",
  1768. Value: data.A_name,
  1769. Required: true,
  1770. Min: "1",
  1771. Max: "255",
  1772. },
  1773. {
  1774. Kind: builder.DFKText,
  1775. Caption: "Attribute in filter",
  1776. Name: "filter",
  1777. Value: data.A_filter,
  1778. Required: true,
  1779. Min: "1",
  1780. Max: "255",
  1781. },
  1782. {
  1783. Kind: builder.DFKText,
  1784. Caption: "Attribute values",
  1785. Name: "",
  1786. Value: "",
  1787. CallBack: func(field *builder.DataFormField) string {
  1788. return `<div class="form-group n4">` +
  1789. `<div class="row">` +
  1790. `<div class="col-md-3">` +
  1791. `<label>Attribute values</label>` +
  1792. `</div>` +
  1793. `<div class="col-md-9">` +
  1794. `<div class="list-wrapper">` +
  1795. `<div id="list">` +
  1796. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1797. `</div>` +
  1798. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1799. `</div>` +
  1800. `</div>` +
  1801. `</div>` +
  1802. `</div>`
  1803. },
  1804. },
  1805. {
  1806. Kind: builder.DFKSubmit,
  1807. Value: btn_caption,
  1808. Target: "add-edit-button",
  1809. },
  1810. })
  1811. if wrap.CurrSubModule == "attributes-add" {
  1812. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1813. } else {
  1814. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1815. }
  1816. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1817. if wrap.CurrSubModule == "currencies-add" {
  1818. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1819. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1820. {Name: "Add new currency"},
  1821. })
  1822. } else {
  1823. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1824. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1825. {Name: "Modify currency"},
  1826. })
  1827. }
  1828. data := utils.MySql_shop_currency{
  1829. A_id: 0,
  1830. A_name: "",
  1831. A_coefficient: 0,
  1832. A_code: "",
  1833. A_symbol: "",
  1834. }
  1835. if wrap.CurrSubModule == "currencies-modify" {
  1836. if len(wrap.UrlArgs) != 3 {
  1837. return "", "", ""
  1838. }
  1839. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1840. return "", "", ""
  1841. }
  1842. err := wrap.DB.QueryRow(
  1843. wrap.R.Context(),
  1844. `SELECT
  1845. id,
  1846. name,
  1847. coefficient,
  1848. code,
  1849. symbol
  1850. FROM
  1851. fave_shop_currencies
  1852. WHERE
  1853. id = ?
  1854. LIMIT 1;`,
  1855. utils.StrToInt(wrap.UrlArgs[2]),
  1856. ).Scan(
  1857. &data.A_id,
  1858. &data.A_name,
  1859. &data.A_coefficient,
  1860. &data.A_code,
  1861. &data.A_symbol,
  1862. )
  1863. if *wrap.LogCpError(&err) != nil {
  1864. return "", "", ""
  1865. }
  1866. }
  1867. btn_caption := "Add"
  1868. if wrap.CurrSubModule == "currencies-modify" {
  1869. btn_caption = "Save"
  1870. }
  1871. content += builder.DataForm(wrap, []builder.DataFormField{
  1872. {
  1873. Kind: builder.DFKHidden,
  1874. Name: "action",
  1875. Value: "shop-currencies-modify",
  1876. },
  1877. {
  1878. Kind: builder.DFKHidden,
  1879. Name: "id",
  1880. Value: utils.IntToStr(data.A_id),
  1881. },
  1882. {
  1883. Kind: builder.DFKText,
  1884. Caption: "Currency name",
  1885. Name: "name",
  1886. Value: data.A_name,
  1887. Required: true,
  1888. Min: "1",
  1889. Max: "255",
  1890. },
  1891. {
  1892. Kind: builder.DFKText,
  1893. Caption: "Currency coefficient",
  1894. Name: "coefficient",
  1895. Value: "0",
  1896. CallBack: func(field *builder.DataFormField) string {
  1897. return `<div class="form-group n3">` +
  1898. `<div class="row">` +
  1899. `<div class="col-md-3">` +
  1900. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1901. `</div>` +
  1902. `<div class="col-md-9">` +
  1903. `<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>` +
  1904. `</div>` +
  1905. `</div>` +
  1906. `</div>`
  1907. },
  1908. },
  1909. {
  1910. Kind: builder.DFKText,
  1911. Caption: "Currency code",
  1912. Name: "code",
  1913. Value: data.A_code,
  1914. Required: true,
  1915. Min: "1",
  1916. Max: "10",
  1917. },
  1918. {
  1919. Kind: builder.DFKText,
  1920. Caption: "Currency symbol",
  1921. Name: "symbol",
  1922. Value: data.A_symbol,
  1923. Required: true,
  1924. Min: "1",
  1925. Max: "5",
  1926. },
  1927. {
  1928. Kind: builder.DFKSubmit,
  1929. Value: btn_caption,
  1930. Target: "add-edit-button",
  1931. },
  1932. })
  1933. if wrap.CurrSubModule == "currencies-add" {
  1934. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1935. } else {
  1936. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1937. }
  1938. } else if wrap.CurrSubModule == "orders-modify" {
  1939. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1940. {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/orders/"},
  1941. {Name: "Modify order"},
  1942. })
  1943. if len(wrap.UrlArgs) != 3 {
  1944. return "", "", ""
  1945. }
  1946. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1947. return "", "", ""
  1948. }
  1949. var curr_order_id int
  1950. var curr_order_client_phone string
  1951. var curr_order_update_datetime string
  1952. var curr_order_currency_id int
  1953. var curr_order_currency_name string
  1954. var curr_order_currency_coefficient float64
  1955. var curr_order_currency_code string
  1956. var curr_order_currency_symbol string
  1957. var curr_order_client_last_name string
  1958. var curr_order_client_first_name string
  1959. var curr_order_client_middle_name string
  1960. var curr_order_create_datetime int
  1961. var curr_order_client_email string
  1962. var curr_order_client_delivery_comment string
  1963. var curr_order_client_order_comment string
  1964. var curr_order_status int
  1965. var curr_order_total float64
  1966. err := wrap.DB.QueryRow(
  1967. wrap.R.Context(),
  1968. `SELECT
  1969. fave_shop_orders.id,
  1970. fave_shop_orders.client_phone,
  1971. fave_shop_orders.update_datetime,
  1972. fave_shop_orders.currency_id,
  1973. fave_shop_orders.currency_name,
  1974. fave_shop_orders.currency_coefficient,
  1975. fave_shop_orders.currency_code,
  1976. fave_shop_orders.currency_symbol,
  1977. fave_shop_orders.client_last_name,
  1978. fave_shop_orders.client_first_name,
  1979. fave_shop_orders.client_middle_name,
  1980. UNIX_TIMESTAMP(fave_shop_orders.create_datetime) as create_datetime,
  1981. fave_shop_orders.client_email,
  1982. fave_shop_orders.client_delivery_comment,
  1983. fave_shop_orders.client_order_comment,
  1984. fave_shop_orders.status,
  1985. shop_order_total.total
  1986. FROM
  1987. fave_shop_orders
  1988. LEFT JOIN (
  1989. SELECT
  1990. order_id,
  1991. SUM(price * quantity) as total
  1992. FROM
  1993. fave_shop_order_products
  1994. GROUP BY
  1995. order_id
  1996. ) as shop_order_total ON shop_order_total.order_id = fave_shop_orders.id
  1997. WHERE
  1998. fave_shop_orders.id = ?
  1999. LIMIT 1;`,
  2000. utils.StrToInt(wrap.UrlArgs[2]),
  2001. ).Scan(
  2002. &curr_order_id,
  2003. &curr_order_client_phone,
  2004. &curr_order_update_datetime,
  2005. &curr_order_currency_id,
  2006. &curr_order_currency_name,
  2007. &curr_order_currency_coefficient,
  2008. &curr_order_currency_code,
  2009. &curr_order_currency_symbol,
  2010. &curr_order_client_last_name,
  2011. &curr_order_client_first_name,
  2012. &curr_order_client_middle_name,
  2013. &curr_order_create_datetime,
  2014. &curr_order_client_email,
  2015. &curr_order_client_delivery_comment,
  2016. &curr_order_client_order_comment,
  2017. &curr_order_status,
  2018. &curr_order_total,
  2019. )
  2020. if *wrap.LogCpError(&err) != nil {
  2021. return "", "", ""
  2022. }
  2023. last_name := html.EscapeString(curr_order_client_last_name)
  2024. first_name := html.EscapeString(curr_order_client_first_name)
  2025. middle_name := html.EscapeString(curr_order_client_middle_name)
  2026. phone := html.EscapeString(curr_order_client_phone)
  2027. email := html.EscapeString(curr_order_client_email)
  2028. order_id := `<span class="d-inline d-sm-none">#` + utils.IntToStr(curr_order_id) + `. </span>`
  2029. name := ""
  2030. if last_name != "" {
  2031. name += " " + last_name
  2032. }
  2033. if first_name != "" {
  2034. name += " " + first_name
  2035. }
  2036. if middle_name != "" {
  2037. name += " " + middle_name
  2038. }
  2039. name = order_id + utils.Trim(name)
  2040. contact := ""
  2041. if email != "" {
  2042. contact += " " + email
  2043. }
  2044. if phone != "" {
  2045. contact += " (" + phone + ")"
  2046. }
  2047. contact = utils.Trim(contact)
  2048. content += `<table id="cp-table-shop_orders" class="table data-table table-striped table-bordered table-hover table_shop_orders">
  2049. <thead>
  2050. <tr>
  2051. <th scope="col" class="col_id d-none d-lg-table-cell">Order #</th>
  2052. <th scope="col" class="col_client_last_name">Client / Contact</th>
  2053. <th scope="col" class="col_create_datetime d-none d-lg-table-cell">Date / Time</th>
  2054. <th scope="col" class="col_client_email">Status / Total</th>
  2055. </tr>
  2056. </thead>
  2057. <tbody>
  2058. <tr>
  2059. <td class="col_id d-none d-lg-table-cell">` + utils.IntToStr(curr_order_id) + `</td>
  2060. <td class="col_client_last_name">
  2061. <div>` + name + `</div>
  2062. <div><small>` + contact + `</small></div>
  2063. <div>
  2064. <small>
  2065. <a href="javascript:fave.ShopSetOrderStatus(this,'` + utils.IntToStr(curr_order_id) + `','0','Are you sure want to change order status?');">` + this.shop_GetOrderStatus(0) + `</a> | <a href="javascript:fave.ShopSetOrderStatus(this,'` + utils.IntToStr(curr_order_id) + `','1','Are you sure want to change order status?');">` + this.shop_GetOrderStatus(1) + `</a> | <a href="javascript:fave.ShopSetOrderStatus(this,'` + utils.IntToStr(curr_order_id) + `','2','Are you sure want to change order status?');">` + this.shop_GetOrderStatus(2) + `</a> | <a href="javascript:fave.ShopSetOrderStatus(this,'` + utils.IntToStr(curr_order_id) + `','3','Are you sure want to change order status?');">` + this.shop_GetOrderStatus(3) + `</a> | <a href="javascript:fave.ShopSetOrderStatus(this,'` + utils.IntToStr(curr_order_id) + `','4','Are you sure want to change order status?');">` + this.shop_GetOrderStatus(4) + `</a>
  2066. </small>
  2067. </div>
  2068. </td>
  2069. <td class="col_create_datetime d-none d-lg-table-cell">
  2070. <div>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "02.01.2006") + `</div>
  2071. <div><small>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "15:04:05") + `</small></div>
  2072. </td>
  2073. <td class="col_client_email">
  2074. <div>` + this.shop_GetOrderStatus(curr_order_status) + `</div>
  2075. <div><small>` + utils.Float64ToStr(curr_order_total) + " " + html.EscapeString(curr_order_currency_code) + `</small></div>
  2076. </td>
  2077. </tr>
  2078. </tbody>
  2079. </table>`
  2080. content += `<table id="cp-table-shop_products" class="table data-table table-striped table-bordered table-hover mt-3 table_shop_products">
  2081. <thead>
  2082. <tr>
  2083. <th scope="col" class="col_name">Product</th>
  2084. <th scope="col" class="col_price d-none d-md-table-cell">Price</th>
  2085. <th scope="col" class="col_quantity">Quantity</th>
  2086. <th scope="col" class="col_total d-none d-md-table-cell">Total</th>
  2087. </tr>
  2088. </thead>
  2089. <tbody>
  2090. `
  2091. rows, err := wrap.DB.Query(
  2092. wrap.R.Context(),
  2093. `SELECT
  2094. fave_shop_order_products.product_id,
  2095. fave_shop_products.name,
  2096. fave_shop_products.alias,
  2097. fave_shop_order_products.price,
  2098. fave_shop_order_products.quantity,
  2099. (fave_shop_order_products.price * fave_shop_order_products.quantity) as total
  2100. FROM
  2101. fave_shop_order_products
  2102. LEFT JOIN fave_shop_products ON fave_shop_products.id = fave_shop_order_products.product_id
  2103. WHERE
  2104. fave_shop_order_products.order_id = ?
  2105. ;`,
  2106. curr_order_id,
  2107. )
  2108. if err == nil {
  2109. defer rows.Close()
  2110. var curr_product_id int
  2111. var curr_product_name string
  2112. var curr_product_alias string
  2113. var curr_product_price float64
  2114. var curr_product_quantity int
  2115. var curr_product_total float64
  2116. for rows.Next() {
  2117. err = rows.Scan(
  2118. &curr_product_id,
  2119. &curr_product_name,
  2120. &curr_product_alias,
  2121. &curr_product_price,
  2122. &curr_product_quantity,
  2123. &curr_product_total,
  2124. )
  2125. if *wrap.LogCpError(&err) == nil {
  2126. content += `<tr>
  2127. <td class="col_name">
  2128. <div><a href="/cp/shop/modify/` + utils.IntToStr(curr_product_id) + `/">` + html.EscapeString(curr_product_name) + ` ` + utils.IntToStr(curr_product_id) + `</a></div>
  2129. <div><small><a href="/shop/` + html.EscapeString(curr_product_alias) + `/" target="_blank">/shop/` + html.EscapeString(curr_product_alias) + `/</a></small></div>
  2130. </td>
  2131. <td class="col_price d-none d-md-table-cell">
  2132. <div>` + utils.Float64ToStr(curr_product_price) + `</div>
  2133. <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
  2134. </td>
  2135. <td class="col_quantity">
  2136. ` + utils.IntToStr(curr_product_quantity) + `
  2137. </td>
  2138. <td class="col_total d-none d-md-table-cell">
  2139. <div>` + utils.Float64ToStr(curr_product_total) + `</div>
  2140. <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
  2141. </td>
  2142. </tr>`
  2143. }
  2144. }
  2145. }
  2146. content += `</tbody>
  2147. </table>`
  2148. // Delivery
  2149. content += `<div class="card mt-3">
  2150. <div class="card-header"><b>Delivery</b></div>
  2151. <ul class="list-group list-group-flush">
  2152. <li class="list-group-item">`
  2153. if utils.Trim(curr_order_client_delivery_comment) != "" {
  2154. content += html.EscapeString(curr_order_client_delivery_comment)
  2155. } else {
  2156. content += `NO SET`
  2157. }
  2158. content += `</li>
  2159. </ul>
  2160. </div>`
  2161. // Comment
  2162. content += `<div class="card mt-3">
  2163. <div class="card-header"><b>Comment</b></div>
  2164. <ul class="list-group list-group-flush">
  2165. <li class="list-group-item">`
  2166. if utils.Trim(curr_order_client_order_comment) != "" {
  2167. content += html.EscapeString(curr_order_client_order_comment)
  2168. } else {
  2169. content += `NO SET`
  2170. }
  2171. content += `</li>
  2172. </ul>
  2173. </div>`
  2174. }
  2175. return this.getSidebarModules(wrap), content, sidebar
  2176. })
  2177. }