module_shop.go 63 KB

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