module_shop.go 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  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.status ASC,
  1053. shop_orders.id DESC
  1054. LIMIT ?, ?;`,
  1055. limit_offset,
  1056. pear_page,
  1057. )
  1058. },
  1059. true,
  1060. )
  1061. } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
  1062. if wrap.CurrSubModule == "add" {
  1063. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1064. {Name: "Add new product"},
  1065. })
  1066. } else {
  1067. if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
  1068. content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
  1069. content += `<div class="product-another"><a title="Duplicate product and attach" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
  1070. }
  1071. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1072. {Name: "Modify product"},
  1073. })
  1074. }
  1075. data := utils.MySql_shop_product{
  1076. A_id: 0,
  1077. A_user: 0,
  1078. A_currency: 0,
  1079. A_price: 0,
  1080. A_gname: "",
  1081. A_name: "",
  1082. A_alias: "",
  1083. A_vendor: "",
  1084. A_quantity: 0,
  1085. A_category: 0,
  1086. A_briefly: "",
  1087. A_content: "",
  1088. A_datetime: 0,
  1089. A_active: 0,
  1090. }
  1091. if wrap.CurrSubModule == "modify" {
  1092. if len(wrap.UrlArgs) != 3 {
  1093. return "", "", ""
  1094. }
  1095. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1096. return "", "", ""
  1097. }
  1098. err := wrap.DB.QueryRow(`
  1099. SELECT
  1100. id,
  1101. parent_id,
  1102. user,
  1103. currency,
  1104. price,
  1105. gname,
  1106. name,
  1107. alias,
  1108. vendor,
  1109. quantity,
  1110. category,
  1111. briefly,
  1112. content,
  1113. active
  1114. FROM
  1115. shop_products
  1116. WHERE
  1117. id = ?
  1118. LIMIT 1;`,
  1119. utils.StrToInt(wrap.UrlArgs[2]),
  1120. ).Scan(
  1121. &data.A_id,
  1122. &data.A_parent,
  1123. &data.A_user,
  1124. &data.A_currency,
  1125. &data.A_price,
  1126. &data.A_gname,
  1127. &data.A_name,
  1128. &data.A_alias,
  1129. &data.A_vendor,
  1130. &data.A_quantity,
  1131. &data.A_category,
  1132. &data.A_briefly,
  1133. &data.A_content,
  1134. &data.A_active,
  1135. )
  1136. if *wrap.LogCpError(&err) != nil {
  1137. return "", "", ""
  1138. }
  1139. }
  1140. if data.A_parent_id() > 0 {
  1141. content += `<style>.product-another{display:none}</style>`
  1142. }
  1143. // All product current categories
  1144. var selids []int
  1145. if data.A_id > 0 {
  1146. rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
  1147. if err == nil {
  1148. defer rows.Close()
  1149. values := make([]int, 1)
  1150. scan := make([]interface{}, len(values))
  1151. for i := range values {
  1152. scan[i] = &values[i]
  1153. }
  1154. for rows.Next() {
  1155. err = rows.Scan(scan...)
  1156. if *wrap.LogCpError(&err) == nil {
  1157. selids = append(selids, int(values[0]))
  1158. }
  1159. }
  1160. }
  1161. }
  1162. // Sub products
  1163. sub_products := ``
  1164. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1165. sub_products = this.shop_GetSubProducts(wrap, data.A_id)
  1166. }
  1167. btn_caption := "Add"
  1168. if wrap.CurrSubModule == "modify" {
  1169. btn_caption = "Save"
  1170. }
  1171. content += builder.DataForm(wrap, []builder.DataFormField{
  1172. {
  1173. Kind: builder.DFKHidden,
  1174. Name: "action",
  1175. Value: "shop-modify",
  1176. },
  1177. {
  1178. Kind: builder.DFKHidden,
  1179. Name: "id",
  1180. Value: utils.IntToStr(data.A_id),
  1181. },
  1182. {
  1183. Kind: builder.DFKText,
  1184. CallBack: func(field *builder.DataFormField) string {
  1185. if data.A_id >= 1 && data.A_parent_id() <= 0 {
  1186. return `<div class="form-group nf">` +
  1187. `<div class="row">` +
  1188. `<div class="col-md-3">` +
  1189. `<label>Sub products</label>` +
  1190. `</div>` +
  1191. `<div class="col-md-9">` +
  1192. `<div class="list-wrapper">` +
  1193. sub_products +
  1194. `<div><a href="javascript:fave.ShopAttachProduct(` + utils.IntToStr(data.A_id) + `);"><b>Attach product</b></a></div>` +
  1195. `</div>` +
  1196. `</div>` +
  1197. `</div>` +
  1198. `</div>`
  1199. }
  1200. return ""
  1201. },
  1202. },
  1203. {
  1204. Kind: builder.DFKText,
  1205. CallBack: func(field *builder.DataFormField) string {
  1206. if data.A_id >= 1 && data.A_parent_id() != 0 {
  1207. return `<div class="form-group nf">` +
  1208. `<div class="row">` +
  1209. `<div class="col-md-3">` +
  1210. `<label>Parent</label>` +
  1211. `</div>` +
  1212. `<div class="col-md-9">` +
  1213. `<div class="list-wrapper">` +
  1214. this.shop_GetParentProduct(wrap, data.A_parent_id()) +
  1215. `</div>` +
  1216. `</div>` +
  1217. `</div>` +
  1218. `</div>`
  1219. }
  1220. return ""
  1221. },
  1222. },
  1223. {
  1224. Kind: builder.DFKText,
  1225. CallBack: func(field *builder.DataFormField) string {
  1226. if data.A_id >= 1 && data.A_parent_id() <= 0 && sub_products != "" {
  1227. return `<div class="form-group nf">` +
  1228. `<div class="row">` +
  1229. `<div class="col-md-3">` +
  1230. `<label for="lbl_gname">Group name</label>` +
  1231. `</div>` +
  1232. `<div class="col-md-9">` +
  1233. `<div><input class="form-control" type="text" id="lbl_gname" name="gname" value="` + html.EscapeString(data.A_gname) + `" maxlength="255" autocomplete="off"></div>` +
  1234. `</div>` +
  1235. `</div>` +
  1236. `</div>`
  1237. }
  1238. return ""
  1239. },
  1240. },
  1241. {
  1242. Kind: builder.DFKText,
  1243. Caption: "Product name",
  1244. Name: "name",
  1245. Value: data.A_name,
  1246. Required: true,
  1247. Min: "1",
  1248. Max: "255",
  1249. },
  1250. {
  1251. Kind: builder.DFKText,
  1252. Caption: "Product price",
  1253. Name: "price",
  1254. Value: "0",
  1255. CallBack: func(field *builder.DataFormField) string {
  1256. return `<div class="form-group n6">` +
  1257. `<div class="row">` +
  1258. `<div class="col-md-3">` +
  1259. `<label for="lbl_price">Product price</label>` +
  1260. `</div>` +
  1261. `<div class="col-md-9">` +
  1262. `<div>` +
  1263. `<div class="row">` +
  1264. `<div class="col-md-8">` +
  1265. `<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>` +
  1266. `<div class="d-md-none mb-3"></div>` +
  1267. `</div>` +
  1268. `<div class="col-md-4">` +
  1269. `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
  1270. this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
  1271. `</select>` +
  1272. `</div>` +
  1273. `</div>` +
  1274. `</div>` +
  1275. `</div>` +
  1276. `</div>` +
  1277. `</div>`
  1278. },
  1279. },
  1280. {
  1281. Kind: builder.DFKText,
  1282. Caption: "Product alias",
  1283. Name: "alias",
  1284. Value: data.A_alias,
  1285. Hint: "Example: mobile-phone",
  1286. Max: "255",
  1287. },
  1288. {
  1289. Kind: builder.DFKText,
  1290. Caption: "Vendor/Count",
  1291. Name: "vendor",
  1292. Value: "0",
  1293. CallBack: func(field *builder.DataFormField) string {
  1294. return `<div class="form-group n8">` +
  1295. `<div class="row">` +
  1296. `<div class="col-md-3">` +
  1297. `<label for="lbl_vendor">Vendor/Count</label>` +
  1298. `</div>` +
  1299. `<div class="col-md-9">` +
  1300. `<div>` +
  1301. `<div class="row">` +
  1302. `<div class="col-md-8">` +
  1303. `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
  1304. `<div class="d-md-none mb-3"></div>` +
  1305. `</div>` +
  1306. `<div class="col-md-4">` +
  1307. `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
  1308. `</div>` +
  1309. `</div>` +
  1310. `</div>` +
  1311. `</div>` +
  1312. `</div>` +
  1313. `</div>`
  1314. },
  1315. },
  1316. {
  1317. Kind: builder.DFKText,
  1318. Caption: "Category",
  1319. Name: "category",
  1320. Value: "0",
  1321. CallBack: func(field *builder.DataFormField) string {
  1322. return `<div class="form-group n9">` +
  1323. `<div class="row">` +
  1324. `<div class="col-md-3">` +
  1325. `<label for="lbl_category">Category</label>` +
  1326. `</div>` +
  1327. `<div class="col-md-9">` +
  1328. `<div>` +
  1329. `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
  1330. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1331. this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
  1332. `</select>` +
  1333. `</div>` +
  1334. `</div>` +
  1335. `</div>` +
  1336. `</div>`
  1337. },
  1338. },
  1339. {
  1340. Kind: builder.DFKText,
  1341. Caption: "Categories",
  1342. Name: "cats",
  1343. Value: "0",
  1344. CallBack: func(field *builder.DataFormField) string {
  1345. return `<div class="form-group n10">` +
  1346. `<div class="row">` +
  1347. `<div class="col-md-3">` +
  1348. `<label for="lbl_cats">Categories</label>` +
  1349. `</div>` +
  1350. `<div class="col-md-9">` +
  1351. `<div>` +
  1352. `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
  1353. this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
  1354. `</select>` +
  1355. `</div>` +
  1356. `</div>` +
  1357. `</div>` +
  1358. `</div>`
  1359. },
  1360. },
  1361. {
  1362. Kind: builder.DFKText,
  1363. Caption: "Attributes",
  1364. Name: "",
  1365. Value: "",
  1366. CallBack: func(field *builder.DataFormField) string {
  1367. return `<div class="form-group n11">` +
  1368. `<div class="row">` +
  1369. `<div class="col-md-3">` +
  1370. `<label>Attributes</label>` +
  1371. `</div>` +
  1372. `<div class="col-md-9">` +
  1373. `<div class="list-wrapper">` +
  1374. `<div id="list">` +
  1375. this.shop_GetProductValuesInputs(wrap, data.A_id) +
  1376. `</div>` +
  1377. `<div class="list-button position-relative">` +
  1378. `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
  1379. this.shop_GetAllAttributesSelectOptions(wrap) +
  1380. `</select>` +
  1381. `</div>` +
  1382. `</div>` +
  1383. `</div>` +
  1384. `</div>` +
  1385. `</div>`
  1386. },
  1387. },
  1388. {
  1389. Kind: builder.DFKTextArea,
  1390. Caption: "Briefly",
  1391. Name: "briefly",
  1392. Value: data.A_briefly,
  1393. Classes: "briefly wysiwyg",
  1394. },
  1395. {
  1396. Kind: builder.DFKTextArea,
  1397. Caption: "Product content",
  1398. Name: "content",
  1399. Value: data.A_content,
  1400. Classes: "wysiwyg",
  1401. },
  1402. {
  1403. Kind: builder.DFKText,
  1404. Caption: "Product images",
  1405. Name: "",
  1406. Value: "",
  1407. CallBack: func(field *builder.DataFormField) string {
  1408. if data.A_id == 0 {
  1409. return ``
  1410. }
  1411. return `<div class="form-group n14">` +
  1412. `<div class="row">` +
  1413. `<div class="col-md-3">` +
  1414. `<label>Product images</label>` +
  1415. `</div>` +
  1416. `<div class="col-md-9">` +
  1417. `<div class="list-wrapper">` +
  1418. `<div id="list-images">` +
  1419. this.shop_GetAllProductImages(wrap, data.A_id) +
  1420. `</div>` +
  1421. `<div id="img-upload-block" class="list-button position-relative">` +
  1422. `<div id="upload-msg">Uploading...</div>` +
  1423. `<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 />` +
  1424. `</div>` +
  1425. `</div>` +
  1426. `</div>` +
  1427. `</div>` +
  1428. `</div>` +
  1429. `<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>`
  1430. },
  1431. },
  1432. {
  1433. Kind: builder.DFKCheckBox,
  1434. Caption: "Active",
  1435. Name: "active",
  1436. Value: utils.IntToStr(data.A_active),
  1437. },
  1438. {
  1439. Kind: builder.DFKSubmit,
  1440. Value: btn_caption,
  1441. Target: "add-edit-button",
  1442. },
  1443. })
  1444. if wrap.CurrSubModule == "add" {
  1445. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1446. } else {
  1447. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1448. }
  1449. } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
  1450. if wrap.CurrSubModule == "categories-add" {
  1451. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1452. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1453. {Name: "Add new category"},
  1454. })
  1455. } else {
  1456. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1457. {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
  1458. {Name: "Modify category"},
  1459. })
  1460. }
  1461. data := utils.MySql_shop_category{
  1462. A_id: 0,
  1463. A_user: 0,
  1464. A_name: "",
  1465. A_alias: "",
  1466. A_lft: 0,
  1467. A_rgt: 0,
  1468. }
  1469. if wrap.CurrSubModule == "categories-modify" {
  1470. if len(wrap.UrlArgs) != 3 {
  1471. return "", "", ""
  1472. }
  1473. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1474. return "", "", ""
  1475. }
  1476. err := wrap.DB.QueryRow(`
  1477. SELECT
  1478. id,
  1479. user,
  1480. name,
  1481. alias,
  1482. lft,
  1483. rgt
  1484. FROM
  1485. shop_cats
  1486. WHERE
  1487. id = ?
  1488. LIMIT 1;`,
  1489. utils.StrToInt(wrap.UrlArgs[2]),
  1490. ).Scan(
  1491. &data.A_id,
  1492. &data.A_user,
  1493. &data.A_name,
  1494. &data.A_alias,
  1495. &data.A_lft,
  1496. &data.A_rgt,
  1497. )
  1498. if *wrap.LogCpError(&err) != nil {
  1499. return "", "", ""
  1500. }
  1501. }
  1502. btn_caption := "Add"
  1503. if wrap.CurrSubModule == "categories-modify" {
  1504. btn_caption = "Save"
  1505. }
  1506. parentId := 0
  1507. if wrap.CurrSubModule == "categories-modify" {
  1508. parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
  1509. }
  1510. content += builder.DataForm(wrap, []builder.DataFormField{
  1511. {
  1512. Kind: builder.DFKHidden,
  1513. Name: "action",
  1514. Value: "shop-categories-modify",
  1515. },
  1516. {
  1517. Kind: builder.DFKHidden,
  1518. Name: "id",
  1519. Value: utils.IntToStr(data.A_id),
  1520. },
  1521. {
  1522. Kind: builder.DFKText,
  1523. Caption: "Parent",
  1524. Name: "parent",
  1525. Value: "0",
  1526. CallBack: func(field *builder.DataFormField) string {
  1527. return `<div class="form-group n2">` +
  1528. `<div class="row">` +
  1529. `<div class="col-md-3">` +
  1530. `<label for="lbl_parent">Parent</label>` +
  1531. `</div>` +
  1532. `<div class="col-md-9">` +
  1533. `<div>` +
  1534. `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
  1535. `<option title="Nothing selected" value="0">&mdash;</option>` +
  1536. this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
  1537. `</select>` +
  1538. `</div>` +
  1539. `</div>` +
  1540. `</div>` +
  1541. `</div>`
  1542. },
  1543. },
  1544. {
  1545. Kind: builder.DFKText,
  1546. Caption: "Name",
  1547. Name: "name",
  1548. Value: data.A_name,
  1549. Required: true,
  1550. Min: "1",
  1551. Max: "255",
  1552. },
  1553. {
  1554. Kind: builder.DFKText,
  1555. Caption: "Alias",
  1556. Name: "alias",
  1557. Value: data.A_alias,
  1558. Hint: "Example: popular-products",
  1559. Max: "255",
  1560. },
  1561. {
  1562. Kind: builder.DFKSubmit,
  1563. Value: btn_caption,
  1564. Target: "add-edit-button",
  1565. },
  1566. })
  1567. if wrap.CurrSubModule == "categories-add" {
  1568. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1569. } else {
  1570. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1571. }
  1572. } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
  1573. if wrap.CurrSubModule == "attributes-add" {
  1574. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1575. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1576. {Name: "Add new attribute"},
  1577. })
  1578. } else {
  1579. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1580. {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
  1581. {Name: "Modify attribute"},
  1582. })
  1583. }
  1584. data := utils.MySql_shop_filter{
  1585. A_id: 0,
  1586. A_name: "",
  1587. A_filter: "",
  1588. }
  1589. if wrap.CurrSubModule == "attributes-modify" {
  1590. if len(wrap.UrlArgs) != 3 {
  1591. return "", "", ""
  1592. }
  1593. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1594. return "", "", ""
  1595. }
  1596. err := wrap.DB.QueryRow(`
  1597. SELECT
  1598. id,
  1599. name,
  1600. filter
  1601. FROM
  1602. shop_filters
  1603. WHERE
  1604. id = ?
  1605. LIMIT 1;`,
  1606. utils.StrToInt(wrap.UrlArgs[2]),
  1607. ).Scan(
  1608. &data.A_id,
  1609. &data.A_name,
  1610. &data.A_filter,
  1611. )
  1612. if *wrap.LogCpError(&err) != nil {
  1613. return "", "", ""
  1614. }
  1615. }
  1616. btn_caption := "Add"
  1617. if wrap.CurrSubModule == "attributes-modify" {
  1618. btn_caption = "Save"
  1619. }
  1620. content += builder.DataForm(wrap, []builder.DataFormField{
  1621. {
  1622. Kind: builder.DFKHidden,
  1623. Name: "action",
  1624. Value: "shop-attributes-modify",
  1625. },
  1626. {
  1627. Kind: builder.DFKHidden,
  1628. Name: "id",
  1629. Value: utils.IntToStr(data.A_id),
  1630. },
  1631. {
  1632. Kind: builder.DFKText,
  1633. Caption: "Attribute name",
  1634. Name: "name",
  1635. Value: data.A_name,
  1636. Required: true,
  1637. Min: "1",
  1638. Max: "255",
  1639. },
  1640. {
  1641. Kind: builder.DFKText,
  1642. Caption: "Attribute in filter",
  1643. Name: "filter",
  1644. Value: data.A_filter,
  1645. Required: true,
  1646. Min: "1",
  1647. Max: "255",
  1648. },
  1649. {
  1650. Kind: builder.DFKText,
  1651. Caption: "Attribute values",
  1652. Name: "",
  1653. Value: "",
  1654. CallBack: func(field *builder.DataFormField) string {
  1655. return `<div class="form-group n4">` +
  1656. `<div class="row">` +
  1657. `<div class="col-md-3">` +
  1658. `<label>Attribute values</label>` +
  1659. `</div>` +
  1660. `<div class="col-md-9">` +
  1661. `<div class="list-wrapper">` +
  1662. `<div id="list">` +
  1663. this.shop_GetFilterValuesInputs(wrap, data.A_id) +
  1664. `</div>` +
  1665. `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
  1666. `</div>` +
  1667. `</div>` +
  1668. `</div>` +
  1669. `</div>`
  1670. },
  1671. },
  1672. {
  1673. Kind: builder.DFKSubmit,
  1674. Value: btn_caption,
  1675. Target: "add-edit-button",
  1676. },
  1677. })
  1678. if wrap.CurrSubModule == "attributes-add" {
  1679. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1680. } else {
  1681. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1682. }
  1683. } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
  1684. if wrap.CurrSubModule == "currencies-add" {
  1685. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1686. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1687. {Name: "Add new currency"},
  1688. })
  1689. } else {
  1690. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1691. {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
  1692. {Name: "Modify currency"},
  1693. })
  1694. }
  1695. data := utils.MySql_shop_currency{
  1696. A_id: 0,
  1697. A_name: "",
  1698. A_coefficient: 0,
  1699. A_code: "",
  1700. A_symbol: "",
  1701. }
  1702. if wrap.CurrSubModule == "currencies-modify" {
  1703. if len(wrap.UrlArgs) != 3 {
  1704. return "", "", ""
  1705. }
  1706. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1707. return "", "", ""
  1708. }
  1709. err := wrap.DB.QueryRow(`
  1710. SELECT
  1711. id,
  1712. name,
  1713. coefficient,
  1714. code,
  1715. symbol
  1716. FROM
  1717. shop_currencies
  1718. WHERE
  1719. id = ?
  1720. LIMIT 1;`,
  1721. utils.StrToInt(wrap.UrlArgs[2]),
  1722. ).Scan(
  1723. &data.A_id,
  1724. &data.A_name,
  1725. &data.A_coefficient,
  1726. &data.A_code,
  1727. &data.A_symbol,
  1728. )
  1729. if *wrap.LogCpError(&err) != nil {
  1730. return "", "", ""
  1731. }
  1732. }
  1733. btn_caption := "Add"
  1734. if wrap.CurrSubModule == "currencies-modify" {
  1735. btn_caption = "Save"
  1736. }
  1737. content += builder.DataForm(wrap, []builder.DataFormField{
  1738. {
  1739. Kind: builder.DFKHidden,
  1740. Name: "action",
  1741. Value: "shop-currencies-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: "Currency 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: "Currency coefficient",
  1760. Name: "coefficient",
  1761. Value: "0",
  1762. CallBack: func(field *builder.DataFormField) string {
  1763. return `<div class="form-group n3">` +
  1764. `<div class="row">` +
  1765. `<div class="col-md-3">` +
  1766. `<label for="lbl_coefficient">Currency coefficient</label>` +
  1767. `</div>` +
  1768. `<div class="col-md-9">` +
  1769. `<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>` +
  1770. `</div>` +
  1771. `</div>` +
  1772. `</div>`
  1773. },
  1774. },
  1775. {
  1776. Kind: builder.DFKText,
  1777. Caption: "Currency code",
  1778. Name: "code",
  1779. Value: data.A_code,
  1780. Required: true,
  1781. Min: "1",
  1782. Max: "10",
  1783. },
  1784. {
  1785. Kind: builder.DFKText,
  1786. Caption: "Currency symbol",
  1787. Name: "symbol",
  1788. Value: data.A_symbol,
  1789. Required: true,
  1790. Min: "1",
  1791. Max: "5",
  1792. },
  1793. {
  1794. Kind: builder.DFKSubmit,
  1795. Value: btn_caption,
  1796. Target: "add-edit-button",
  1797. },
  1798. })
  1799. if wrap.CurrSubModule == "currencies-add" {
  1800. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
  1801. } else {
  1802. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  1803. }
  1804. } else if wrap.CurrSubModule == "orders-modify" {
  1805. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  1806. {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/orders/"},
  1807. {Name: "Modify order"},
  1808. })
  1809. if len(wrap.UrlArgs) != 3 {
  1810. return "", "", ""
  1811. }
  1812. if !utils.IsNumeric(wrap.UrlArgs[2]) {
  1813. return "", "", ""
  1814. }
  1815. var curr_order_id int
  1816. var curr_order_client_phone string
  1817. var curr_order_update_datetime string
  1818. var curr_order_currency_id int
  1819. var curr_order_currency_name string
  1820. var curr_order_currency_coefficient float64
  1821. var curr_order_currency_code string
  1822. var curr_order_currency_symbol string
  1823. var curr_order_client_last_name string
  1824. var curr_order_client_first_name string
  1825. var curr_order_client_middle_name string
  1826. var curr_order_create_datetime int
  1827. var curr_order_client_email string
  1828. var curr_order_client_delivery_comment string
  1829. var curr_order_client_order_comment string
  1830. var curr_order_status int
  1831. var curr_order_total float64
  1832. err := wrap.DB.QueryRow(`
  1833. SELECT
  1834. shop_orders.id,
  1835. shop_orders.client_phone,
  1836. shop_orders.update_datetime,
  1837. shop_orders.currency_id,
  1838. shop_orders.currency_name,
  1839. shop_orders.currency_coefficient,
  1840. shop_orders.currency_code,
  1841. shop_orders.currency_symbol,
  1842. shop_orders.client_last_name,
  1843. shop_orders.client_first_name,
  1844. shop_orders.client_middle_name,
  1845. UNIX_TIMESTAMP(shop_orders.create_datetime) as create_datetime,
  1846. shop_orders.client_email,
  1847. shop_orders.client_delivery_comment,
  1848. shop_orders.client_order_comment,
  1849. shop_orders.status,
  1850. shop_order_total.total
  1851. FROM
  1852. shop_orders
  1853. LEFT JOIN (
  1854. SELECT
  1855. order_id,
  1856. SUM(price * quantity) as total
  1857. FROM
  1858. shop_order_products
  1859. GROUP BY
  1860. order_id
  1861. ) as shop_order_total ON shop_order_total.order_id = shop_orders.id
  1862. WHERE
  1863. shop_orders.id = ?
  1864. LIMIT 1;`,
  1865. utils.StrToInt(wrap.UrlArgs[2]),
  1866. ).Scan(
  1867. &curr_order_id,
  1868. &curr_order_client_phone,
  1869. &curr_order_update_datetime,
  1870. &curr_order_currency_id,
  1871. &curr_order_currency_name,
  1872. &curr_order_currency_coefficient,
  1873. &curr_order_currency_code,
  1874. &curr_order_currency_symbol,
  1875. &curr_order_client_last_name,
  1876. &curr_order_client_first_name,
  1877. &curr_order_client_middle_name,
  1878. &curr_order_create_datetime,
  1879. &curr_order_client_email,
  1880. &curr_order_client_delivery_comment,
  1881. &curr_order_client_order_comment,
  1882. &curr_order_status,
  1883. &curr_order_total,
  1884. )
  1885. if *wrap.LogCpError(&err) != nil {
  1886. return "", "", ""
  1887. }
  1888. last_name := html.EscapeString(curr_order_client_last_name)
  1889. first_name := html.EscapeString(curr_order_client_first_name)
  1890. middle_name := html.EscapeString(curr_order_client_middle_name)
  1891. phone := html.EscapeString(curr_order_client_phone)
  1892. email := html.EscapeString(curr_order_client_email)
  1893. order_id := `<span class="d-inline d-sm-none">#` + utils.IntToStr(curr_order_id) + `. </span>`
  1894. name := ""
  1895. if last_name != "" {
  1896. name += " " + last_name
  1897. }
  1898. if first_name != "" {
  1899. name += " " + first_name
  1900. }
  1901. if middle_name != "" {
  1902. name += " " + middle_name
  1903. }
  1904. name = order_id + strings.TrimSpace(name)
  1905. contact := ""
  1906. if email != "" {
  1907. contact += " " + email
  1908. }
  1909. if phone != "" {
  1910. contact += " (" + phone + ")"
  1911. }
  1912. contact = strings.TrimSpace(contact)
  1913. content += `<table id="cp-table-shop_orders" class="table data-table table-striped table-bordered table-hover table_shop_orders">
  1914. <thead>
  1915. <tr>
  1916. <th scope="col" class="col_id d-none d-lg-table-cell">Order #</th>
  1917. <th scope="col" class="col_client_last_name">Client / Contact</th>
  1918. <th scope="col" class="col_create_datetime d-none d-lg-table-cell">Date / Time</th>
  1919. <th scope="col" class="col_client_email">Status / Total</th>
  1920. </tr>
  1921. </thead>
  1922. <tbody>
  1923. <tr>
  1924. <td class="col_id d-none d-lg-table-cell">` + utils.IntToStr(curr_order_id) + `</td>
  1925. <td class="col_client_last_name">
  1926. <div>` + name + `</div>
  1927. <div><small>` + contact + `</small></div>
  1928. <div>
  1929. <small>
  1930. <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>
  1931. </small>
  1932. </div>
  1933. </td>
  1934. <td class="col_create_datetime d-none d-lg-table-cell">
  1935. <div>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "02.01.2006") + `</div>
  1936. <div><small>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "15:04:05") + `</small></div>
  1937. </td>
  1938. <td class="col_client_email">
  1939. <div>` + this.shop_GetOrderStatus(curr_order_status) + `</div>
  1940. <div><small>` + utils.Float64ToStr(curr_order_total) + " " + html.EscapeString(curr_order_currency_code) + `</small></div>
  1941. </td>
  1942. </tr>
  1943. </tbody>
  1944. </table>`
  1945. content += `<table id="cp-table-shop_products" class="table data-table table-striped table-bordered table-hover mt-3 table_shop_products">
  1946. <thead>
  1947. <tr>
  1948. <th scope="col" class="col_name">Product</th>
  1949. <th scope="col" class="col_price d-none d-md-table-cell">Price</th>
  1950. <th scope="col" class="col_quantity">Quantity</th>
  1951. <th scope="col" class="col_total d-none d-md-table-cell">Total</th>
  1952. </tr>
  1953. </thead>
  1954. <tbody>
  1955. `
  1956. rows, err := wrap.DB.Query(
  1957. `SELECT
  1958. shop_order_products.product_id,
  1959. shop_products.name,
  1960. shop_products.alias,
  1961. shop_order_products.price,
  1962. shop_order_products.quantity,
  1963. (shop_order_products.price * shop_order_products.quantity) as total
  1964. FROM
  1965. shop_order_products
  1966. LEFT JOIN shop_products ON shop_products.id = shop_order_products.product_id
  1967. WHERE
  1968. shop_order_products.order_id = ?
  1969. ;`,
  1970. curr_order_id,
  1971. )
  1972. if err == nil {
  1973. defer rows.Close()
  1974. var curr_product_id int
  1975. var curr_product_name string
  1976. var curr_product_alias string
  1977. var curr_product_price float64
  1978. var curr_product_quantity int
  1979. var curr_product_total float64
  1980. for rows.Next() {
  1981. err = rows.Scan(
  1982. &curr_product_id,
  1983. &curr_product_name,
  1984. &curr_product_alias,
  1985. &curr_product_price,
  1986. &curr_product_quantity,
  1987. &curr_product_total,
  1988. )
  1989. if *wrap.LogCpError(&err) == nil {
  1990. content += `<tr>
  1991. <td class="col_name">
  1992. <div><a href="/cp/shop/modify/` + utils.IntToStr(curr_product_id) + `/">` + html.EscapeString(curr_product_name) + ` ` + utils.IntToStr(curr_product_id) + `</a></div>
  1993. <div><small><a href="/shop/` + html.EscapeString(curr_product_alias) + `/" target="_blank">/shop/` + html.EscapeString(curr_product_alias) + `/</a></small></div>
  1994. </td>
  1995. <td class="col_price d-none d-md-table-cell">
  1996. <div>` + utils.Float64ToStr(curr_product_price) + `</div>
  1997. <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
  1998. </td>
  1999. <td class="col_quantity">
  2000. ` + utils.IntToStr(curr_product_quantity) + `
  2001. </td>
  2002. <td class="col_total d-none d-md-table-cell">
  2003. <div>` + utils.Float64ToStr(curr_product_total) + `</div>
  2004. <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
  2005. </td>
  2006. </tr>`
  2007. }
  2008. }
  2009. }
  2010. content += `</tbody>
  2011. </table>`
  2012. // Delivery
  2013. content += `<div class="card mt-3">
  2014. <div class="card-header"><b>Delivery</b></div>
  2015. <ul class="list-group list-group-flush">
  2016. <li class="list-group-item">`
  2017. if strings.TrimSpace(curr_order_client_delivery_comment) != "" {
  2018. content += html.EscapeString(curr_order_client_delivery_comment)
  2019. } else {
  2020. content += `NO SET`
  2021. }
  2022. content += `</li>
  2023. </ul>
  2024. </div>`
  2025. // Comment
  2026. content += `<div class="card mt-3">
  2027. <div class="card-header"><b>Comment</b></div>
  2028. <ul class="list-group list-group-flush">
  2029. <li class="list-group-item">`
  2030. if strings.TrimSpace(curr_order_client_order_comment) != "" {
  2031. content += html.EscapeString(curr_order_client_order_comment)
  2032. } else {
  2033. content += `NO SET`
  2034. }
  2035. content += `</li>
  2036. </ul>
  2037. </div>`
  2038. }
  2039. return this.getSidebarModules(wrap), content, sidebar
  2040. })
  2041. }