module_shop.go 66 KB

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