module_shop.go 66 KB

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