module_shop.go 62 KB

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