module_shop.go 67 KB

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