module_shop.go 66 KB

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