module_shop.go 65 KB

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