123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187 |
- package modules
- import (
- "html"
- "net/http"
- "strings"
- "time"
- "golang-fave/assets"
- "golang-fave/consts"
- "golang-fave/engine/basket"
- "golang-fave/engine/builder"
- "golang-fave/engine/fetdata"
- "golang-fave/engine/sqlw"
- "golang-fave/engine/wrapper"
- "golang-fave/utils"
- )
- func (this *Modules) shop_GetCurrencySelectOptions(wrap *wrapper.Wrapper, id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- code
- FROM
- shop_currencies
- ORDER BY
- id ASC
- ;`,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 2)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- idStr := utils.IntToStr(id)
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- selected := ""
- if string(values[0]) == idStr {
- selected = " selected"
- }
- result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `"` + selected + `>` + html.EscapeString(string(values[1])) + `</option>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetProductValuesInputs(wrap *wrapper.Wrapper, product_id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- shop_filters.id,
- shop_filters.name,
- shop_filters_values.id,
- shop_filters_values.name,
- IF(shop_filter_product_values.filter_value_id > 0, 1, 0) as selected
- FROM
- shop_filters_values
- LEFT JOIN shop_filters ON shop_filters.id = shop_filters_values.filter_id
- LEFT JOIN shop_filter_product_values ON
- shop_filter_product_values.filter_value_id = shop_filters_values.id AND
- shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
- LEFT JOIN (
- SELECT
- shop_filters_values.filter_id,
- shop_filter_product_values.product_id
- FROM
- shop_filter_product_values
- LEFT JOIN shop_filters_values ON shop_filters_values.id = shop_filter_product_values.filter_value_id
- WHERE
- shop_filter_product_values.product_id = ` + utils.IntToStr(product_id) + `
- GROUP BY
- shop_filters_values.filter_id
- ) as filter_used ON filter_used.filter_id = shop_filters.id
- WHERE
- filter_used.filter_id IS NOT NULL
- ORDER BY
- shop_filters.name ASC,
- shop_filters_values.name ASC
- ;`,
- )
- filter_ids := []int{}
- filter_names := map[int]string{}
- filter_values := map[int][]string{}
- if err == nil {
- defer rows.Close()
- values := make([]string, 5)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- filter_id := utils.StrToInt(string(values[0]))
- if !utils.InArrayInt(filter_ids, filter_id) {
- filter_ids = append(filter_ids, filter_id)
- }
- filter_names[filter_id] = html.EscapeString(string(values[1]))
- selected := ``
- if utils.StrToInt(string(values[4])) == 1 {
- selected = ` selected`
- }
- filter_values[filter_id] = append(filter_values[filter_id], `<option value="`+html.EscapeString(string(values[2]))+`"`+selected+`>`+html.EscapeString(string(values[3]))+`</option>`)
- }
- }
- }
- for _, filter_id := range filter_ids {
- result += `<div class="form-group" id="prod_attr_` + utils.IntToStr(filter_id) + `">` +
- `<div><b>` + filter_names[filter_id] + `</b></div>` +
- `<div class="position-relative">` +
- `<select class="selectpicker form-control" name="value.` + utils.IntToStr(filter_id) + `" autocomplete="off" required multiple>` +
- strings.Join(filter_values[filter_id], "") +
- `</select>` +
- `<button type="button" class="btn btn-danger btn-dynamic-remove" onclick="fave.ShopProductsRemove(this);">×</button>` +
- `</div>` +
- `</div>`
- }
- return result
- }
- func (this *Modules) shop_GetFilterValuesInputs(wrap *wrapper.Wrapper, filter_id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- name
- FROM
- shop_filters_values
- WHERE
- filter_id = ?
- ORDER BY
- name ASC
- ;`,
- filter_id,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 2)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- 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);">×</button></div>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetAllAttributesSelectOptions(wrap *wrapper.Wrapper) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- name,
- filter
- FROM
- shop_filters
- ORDER BY
- name ASC
- ;`,
- )
- result += `<option title="—" value="0">—</option>`
- if err == nil {
- defer rows.Close()
- values := make([]string, 3)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- result += `<option title="` + html.EscapeString(string(values[1])) + `" value="` + html.EscapeString(string(values[0])) + `">` + html.EscapeString(string(values[1])) + `</option>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetAllCurrencies(wrap *wrapper.Wrapper) map[int]string {
- result := map[int]string{}
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- code
- FROM
- shop_currencies
- ORDER BY
- id ASC
- ;`,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 2)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- result[utils.StrToInt(string(values[0]))] = html.EscapeString(string(values[1]))
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- product_id,
- filename
- FROM
- shop_product_images
- WHERE
- product_id = ?
- ORDER BY
- ord ASC
- ;`,
- product_id,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 3)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- 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>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetSubProducts(wrap *wrapper.Wrapper, id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- name
- FROM
- shop_products
- WHERE
- parent_id = ?
- ORDER BY
- id DESC
- ;`,
- id,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 2)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- 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>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetParentProduct(wrap *wrapper.Wrapper, id int) string {
- result := ``
- rows, err := wrap.DB.Query(
- `SELECT
- id,
- name
- FROM
- shop_products
- WHERE
- id = ?
- ;`,
- id,
- )
- if err == nil {
- defer rows.Close()
- values := make([]string, 2)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- 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>`
- }
- }
- }
- return result
- }
- func (this *Modules) shop_GetOrderStatus(status int) string {
- if status == 0 {
- return `<span style="color:#f0ad4e;">New</span>`
- } else if status == 1 {
- return `<span style="color:#28a745;">Confirmed</span>`
- } else if status == 2 {
- return `<span style="color:#f0ad4e;">In progress</span>`
- } else if status == 3 {
- return `<span style="color:#d9534f;">Canceled</span>`
- } else if status == 4 {
- return `<span style="color:#6c757d;">Completed</span>`
- }
- return "Unknown"
- }
- func (this *Modules) RegisterModule_Shop() *Module {
- return this.newModule(MInfo{
- WantDB: true,
- Mount: "shop",
- Name: "Shop",
- Order: 2,
- System: false,
- Icon: assets.SysSvgIconShop,
- Sub: &[]MISub{
- {Mount: "default", Name: "List of products", Show: true, Icon: assets.SysSvgIconList},
- {Mount: "add", Name: "Add new product", Show: true, Icon: assets.SysSvgIconPlus},
- {Mount: "modify", Name: "Modify product", Show: false},
- {Sep: true, Show: true},
- {Mount: "categories", Name: "List of categories", Show: true, Icon: assets.SysSvgIconList},
- {Mount: "categories-add", Name: "Add new category", Show: true, Icon: assets.SysSvgIconPlus},
- {Mount: "categories-modify", Name: "Modify category", Show: false},
- {Sep: true, Show: true},
- {Mount: "attributes", Name: "List of attributes", Show: true, Icon: assets.SysSvgIconList},
- {Mount: "attributes-add", Name: "Add new attribute", Show: true, Icon: assets.SysSvgIconPlus},
- {Mount: "attributes-modify", Name: "Modify attribute", Show: false},
- {Sep: true, Show: true},
- {Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
- {Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
- {Mount: "currencies-modify", Name: "Modify currency", Show: false},
- {Sep: true, Show: true},
- {Mount: "orders", Name: "List of orders", Show: true, Icon: assets.SysSvgIconList},
- {Mount: "orders-modify", Name: "Viewing order", Show: false},
- },
- }, func(wrap *wrapper.Wrapper) {
- if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
- // Shop category
- row := &utils.MySql_shop_category{}
- rou := &utils.MySql_user{}
- err := wrap.DB.QueryRow(`
- SELECT
- main.id,
- main.user,
- main.name,
- main.alias,
- main.lft,
- main.rgt,
- main.depth,
- parent.id AS parent_id,
- users.id,
- users.first_name,
- users.last_name,
- users.email,
- users.admin,
- users.active
- FROM
- (
- SELECT
- node.id,
- node.user,
- node.name,
- node.alias,
- node.lft,
- node.rgt,
- (COUNT(parent.id) - 1) AS depth
- FROM
- shop_cats AS node,
- shop_cats AS parent
- WHERE
- node.lft BETWEEN parent.lft AND parent.rgt
- GROUP BY
- node.id
- ORDER BY
- node.lft ASC
- ) AS main
- LEFT JOIN (
- SELECT
- node.id,
- node.user,
- node.name,
- node.alias,
- node.lft,
- node.rgt,
- (COUNT(parent.id) - 0) AS depth
- FROM
- shop_cats AS node,
- shop_cats AS parent
- WHERE
- node.lft BETWEEN parent.lft AND parent.rgt
- GROUP BY
- node.id
- ORDER BY
- node.lft ASC
- ) AS parent ON
- parent.depth = main.depth AND
- main.lft > parent.lft AND
- main.rgt < parent.rgt
- LEFT JOIN users ON users.id = main.user
- WHERE
- main.id > 1 AND
- main.alias = ?
- ORDER BY
- main.lft ASC
- ;`,
- wrap.UrlArgs[2],
- ).Scan(
- &row.A_id,
- &row.A_user,
- &row.A_name,
- &row.A_alias,
- &row.A_lft,
- &row.A_rgt,
- &row.A_depth,
- &row.A_parent,
- &rou.A_id,
- &rou.A_first_name,
- &rou.A_last_name,
- &rou.A_email,
- &rou.A_admin,
- &rou.A_active,
- )
- if err != nil && err != wrapper.ErrNoRows {
- // System error 500
- wrap.LogCpError(&err)
- utils.SystemErrorPageEngine(wrap.W, err)
- return
- } else if err == wrapper.ErrNoRows {
- // User error 404 page
- wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
- return
- }
- // Fix url
- if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
- http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
- return
- }
- // Render template
- wrap.RenderFrontEnd("shop-category", fetdata.New(wrap, false, row, rou), http.StatusOK)
- return
- } 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") {
- SBParam := basket.SBParam{
- R: wrap.R,
- DB: wrap.DB,
- Host: wrap.CurrHost,
- Config: wrap.Config,
- SessionId: wrap.GetSessionId(),
- }
- if wrap.UrlArgs[2] == "info" {
- wrap.W.WriteHeader(http.StatusOK)
- wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
- wrap.W.Write([]byte(wrap.ShopBasket.Info(&SBParam)))
- wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
- return
- } else if wrap.UrlArgs[2] == "plus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
- wrap.W.WriteHeader(http.StatusOK)
- wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
- wrap.W.Write([]byte(wrap.ShopBasket.Plus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
- wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
- return
- } else if wrap.UrlArgs[2] == "minus" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
- wrap.W.WriteHeader(http.StatusOK)
- wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
- wrap.W.Write([]byte(wrap.ShopBasket.Minus(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
- wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
- return
- } else if wrap.UrlArgs[2] == "remove" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
- wrap.W.WriteHeader(http.StatusOK)
- wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- wrap.W.Header().Set("Content-Type", "application/json; charset=utf-8")
- wrap.W.Write([]byte(wrap.ShopBasket.Remove(&SBParam, utils.StrToInt(wrap.UrlArgs[3]))))
- wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
- return
- } else if wrap.UrlArgs[2] == "currency" && len(wrap.UrlArgs) == 4 && utils.IsNumeric(wrap.UrlArgs[3]) {
- http.SetCookie(wrap.W, &http.Cookie{
- Name: "currency",
- Value: wrap.UrlArgs[3],
- Path: "/",
- Expires: time.Now().Add(7 * 24 * time.Hour),
- HttpOnly: true,
- })
- redirectUrl := wrap.R.Referer()
- if redirectUrl == "" {
- redirectUrl = "/"
- }
- http.Redirect(wrap.W, wrap.R, redirectUrl, 302)
- wrap.S.SetString("LastBasketAction", wrap.UrlArgs[2])
- return
- }
- } else if len(wrap.UrlArgs) == 2 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] != "" {
- // Shop product
- row := &utils.MySql_shop_product{}
- rou := &utils.MySql_user{}
- err := wrap.DB.QueryRow(`
- SELECT
- shop_products.id,
- shop_products.parent_id,
- shop_products.user,
- shop_products.currency,
- shop_products.price,
- shop_products.price_old,
- shop_products.name,
- shop_products.alias,
- shop_products.vendor,
- shop_products.quantity,
- shop_products.category,
- shop_products.briefly,
- shop_products.content,
- UNIX_TIMESTAMP(shop_products.datetime) as datetime,
- shop_products.active,
- users.id,
- users.first_name,
- users.last_name,
- users.email,
- users.admin,
- users.active
- FROM
- shop_products
- LEFT JOIN users ON users.id = shop_products.user
- WHERE
- shop_products.active = 1 and
- shop_products.alias = ?
- LIMIT 1;`,
- wrap.UrlArgs[1],
- ).Scan(
- &row.A_id,
- &row.A_parent,
- &row.A_user,
- &row.A_currency,
- &row.A_price,
- &row.A_price_old,
- &row.A_name,
- &row.A_alias,
- &row.A_vendor,
- &row.A_quantity,
- &row.A_category,
- &row.A_briefly,
- &row.A_content,
- &row.A_datetime,
- &row.A_active,
- &rou.A_id,
- &rou.A_first_name,
- &rou.A_last_name,
- &rou.A_email,
- &rou.A_admin,
- &rou.A_active,
- )
- if err != nil && err != wrapper.ErrNoRows {
- // System error 500
- wrap.LogCpError(&err)
- utils.SystemErrorPageEngine(wrap.W, err)
- return
- } else if err == wrapper.ErrNoRows {
- // User error 404 page
- wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
- return
- }
- // Fix url
- if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
- http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
- return
- }
- // Render template
- wrap.RenderFrontEnd("shop-product", fetdata.New(wrap, false, row, rou), http.StatusOK)
- return
- } else if len(wrap.UrlArgs) == 1 && wrap.UrlArgs[0] == "shop" {
- // Shop
- // Fix url
- if wrap.R.URL.Path[len(wrap.R.URL.Path)-1] != '/' {
- http.Redirect(wrap.W, wrap.R, wrap.R.URL.Path+"/"+utils.ExtractGetParams(wrap.R.RequestURI), 301)
- return
- }
- // Render template
- wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
- return
- } else if (*wrap.Config).Engine.MainModule == 2 {
- // Render template
- wrap.RenderFrontEnd("shop", fetdata.New(wrap, false, nil, nil), http.StatusOK)
- return
- }
- // User error 404 page
- wrap.RenderFrontEnd("404", fetdata.New(wrap, true, nil, nil), http.StatusNotFound)
- }, func(wrap *wrapper.Wrapper) (string, string, string) {
- content := ""
- sidebar := ""
- if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "List of products"},
- })
- // Load currencies
- currencies := this.shop_GetAllCurrencies(wrap)
- content += builder.DataTable(
- wrap,
- "shop_products",
- "id",
- "DESC",
- &[]builder.DataTableRow{
- {
- DBField: "id",
- },
- {
- DBField: "name",
- NameInTable: "Product / URL",
- CallBack: func(values *[]string) string {
- name := `<a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` ` + html.EscapeString((*values)[0]) + `</a>`
- alias := html.EscapeString((*values)[2])
- parent := ``
- outofstock := ``
- if (*values)[7] != "" {
- parent = `<div class="parent">↑<small><a href="/cp/` + wrap.CurrModule + `/modify/` + (*values)[7] + `/">` + html.EscapeString((*values)[8]) + ` ` + (*values)[7] + `</a></small></div>`
- }
- if utils.StrToInt((*values)[10]) <= 0 {
- outofstock = `<div><span class="badge badge-primary">Out of stock</span></div>`
- }
- return `<div>` + name + `</div><div><small>/shop/` + alias + `/</small></div>` + parent + outofstock
- },
- },
- {
- DBField: "alias",
- },
- {
- DBField: "currency",
- },
- {
- DBField: "price",
- NameInTable: "Price",
- Classes: "d-none d-md-table-cell",
- CallBack: func(values *[]string) string {
- price_old := ""
- peice_styles := ""
- if utils.StrToFloat64((*values)[9]) > 0 {
- price_old = `<div><strike>` + utils.Float64ToStr(utils.StrToFloat64((*values)[9])) + `</strike></div>`
- peice_styles = ` style="color:#fb3f4c;"`
- }
- return price_old + `<div` + peice_styles + `>` + utils.Float64ToStr(utils.StrToFloat64((*values)[4])) + `</div>` +
- `<div><small>` + currencies[utils.StrToInt((*values)[3])] + `</small></div>`
- },
- },
- {
- DBField: "datetime",
- DBExp: "UNIX_TIMESTAMP(`datetime`)",
- NameInTable: "Date / Time",
- Classes: "d-none d-lg-table-cell",
- CallBack: func(values *[]string) string {
- t := int64(utils.StrToInt((*values)[5]))
- return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
- `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
- },
- },
- {
- DBField: "active",
- NameInTable: "Active",
- Classes: "d-none d-sm-table-cell",
- CallBack: func(values *[]string) string {
- return builder.CheckBox(utils.StrToInt((*values)[6]))
- },
- },
- {
- DBField: "parent_id",
- },
- {
- DBField: "pname",
- DBExp: "spp.name",
- },
- {
- DBField: "price_old",
- },
- {
- DBField: "quantity",
- },
- },
- func(values *[]string) string {
- return builder.DataTableAction(&[]builder.DataTableActionRow{
- {
- Icon: assets.SysSvgIconView,
- Href: `/shop/` + (*values)[2] + `/`,
- Hint: "View",
- Target: "_blank",
- },
- {
- Icon: assets.SysSvgIconEdit,
- Href: "/cp/" + wrap.CurrModule + "/modify/" + (*values)[0] + "/",
- Hint: "Edit",
- },
- {
- Icon: assets.SysSvgIconRemove,
- Href: "javascript:fave.ActionDataTableDelete(this,'shop-delete','" +
- (*values)[0] + "','Are you sure want to delete product?');",
- Hint: "Delete",
- Classes: "delete",
- },
- })
- },
- "/cp/"+wrap.CurrModule+"/",
- func() (int, error) {
- var count int
- return count, wrap.DB.QueryRow(
- "SELECT COUNT(*) FROM `shop_products`;",
- ).Scan(&count)
- },
- func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
- return wrap.DB.Query(
- `SELECT
- shop_products.id,
- shop_products.name,
- shop_products.alias,
- shop_products.currency,
- shop_products.price,
- UNIX_TIMESTAMP(`+"`shop_products`.`datetime`"+`) AS datetime,
- shop_products.active,
- shop_products.parent_id,
- spp.name AS pname,
- shop_products.price_old,
- shop_products.quantity
- FROM
- shop_products
- LEFT JOIN shop_products AS spp ON spp.id = shop_products.parent_id
- ORDER BY
- shop_products.id DESC
- LIMIT ?, ?;`,
- limit_offset,
- pear_page,
- )
- },
- true,
- )
- } else if wrap.CurrSubModule == "categories" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
- {Name: "List of categories"},
- })
- content += builder.DataTable(
- wrap,
- "shop_cats",
- "id",
- "ASC",
- &[]builder.DataTableRow{
- {
- DBField: "id",
- },
- {
- DBField: "user",
- },
- {
- DBField: "name",
- NameInTable: "Category",
- CallBack: func(values *[]string) string {
- depth := utils.StrToInt((*values)[4]) - 1
- if depth < 0 {
- depth = 0
- }
- sub := strings.Repeat("— ", depth)
- name := `<a href="/cp/` + wrap.CurrModule + `/categories-modify/` + (*values)[0] + `/">` + sub + html.EscapeString((*values)[2]) + `</a>`
- return `<div>` + name + `</div>`
- },
- },
- {
- DBField: "alias",
- },
- {
- DBField: "depth",
- },
- },
- func(values *[]string) string {
- return builder.DataTableAction(&[]builder.DataTableActionRow{
- {
- Icon: assets.SysSvgIconView,
- Href: `/shop/category/` + (*values)[3] + `/`,
- Hint: "View",
- Target: "_blank",
- },
- {
- Icon: assets.SysSvgIconEdit,
- Href: "/cp/" + wrap.CurrModule + "/categories-modify/" + (*values)[0] + "/",
- Hint: "Edit",
- },
- {
- Icon: assets.SysSvgIconRemove,
- Href: "javascript:fave.ActionDataTableDelete(this,'shop-categories-delete','" +
- (*values)[0] + "','Are you sure want to delete category?');",
- Hint: "Delete",
- Classes: "delete",
- },
- })
- },
- "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
- nil,
- func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
- return wrap.DB.Query(
- `SELECT
- node.id,
- node.user,
- node.name,
- node.alias,
- (COUNT(parent.id) - 1) AS depth
- FROM
- shop_cats AS node,
- shop_cats AS parent
- WHERE
- node.lft BETWEEN parent.lft AND parent.rgt AND
- node.id > 1
- GROUP BY
- node.id
- ORDER BY
- node.lft ASC
- ;`,
- )
- },
- false,
- )
- } else if wrap.CurrSubModule == "attributes" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
- {Name: "List of attributes"},
- })
- content += builder.DataTable(
- wrap,
- "shop_filters",
- "id",
- "DESC",
- &[]builder.DataTableRow{
- {
- DBField: "id",
- },
- {
- DBField: "name",
- NameInTable: "Name",
- CallBack: func(values *[]string) string {
- name := `<a href="/cp/` + wrap.CurrModule + `/attributes-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + `</a>`
- return `<div>` + name + `</div><div><small>` + html.EscapeString((*values)[2]) + `</small></div>`
- },
- },
- {
- DBField: "filter",
- },
- },
- func(values *[]string) string {
- return builder.DataTableAction(&[]builder.DataTableActionRow{
- {
- Icon: assets.SysSvgIconEdit,
- Href: "/cp/" + wrap.CurrModule + "/attributes-modify/" + (*values)[0] + "/",
- Hint: "Edit",
- },
- {
- Icon: assets.SysSvgIconRemove,
- Href: "javascript:fave.ActionDataTableDelete(this,'shop-attributes-delete','" +
- (*values)[0] + "','Are you sure want to delete attribute?');",
- Hint: "Delete",
- Classes: "delete",
- },
- })
- },
- "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
- nil,
- nil,
- true,
- )
- } else if wrap.CurrSubModule == "currencies" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
- {Name: "List of currencies"},
- })
- content += builder.DataTable(
- wrap,
- "shop_currencies",
- "id",
- "DESC",
- &[]builder.DataTableRow{
- {
- DBField: "id",
- },
- {
- DBField: "name",
- NameInTable: "Name",
- CallBack: func(values *[]string) string {
- name := `<a href="/cp/` + wrap.CurrModule + `/currencies-modify/` + (*values)[0] + `/">` + html.EscapeString((*values)[1]) + ` (` + (*values)[3] + `, ` + (*values)[4] + `)</a>`
- return `<div>` + name + `</div>`
- },
- },
- {
- DBField: "coefficient",
- NameInTable: "Coefficient",
- Classes: "d-none d-md-table-cell",
- CallBack: func(values *[]string) string {
- return utils.Float64ToStrF(utils.StrToFloat64((*values)[2]), "%.4f")
- },
- },
- {
- DBField: "code",
- },
- {
- DBField: "symbol",
- },
- },
- func(values *[]string) string {
- return builder.DataTableAction(&[]builder.DataTableActionRow{
- {
- Icon: assets.SysSvgIconEdit,
- Href: "/cp/" + wrap.CurrModule + "/currencies-modify/" + (*values)[0] + "/",
- Hint: "Edit",
- },
- {
- Icon: assets.SysSvgIconRemove,
- Href: "javascript:fave.ActionDataTableDelete(this,'shop-currencies-delete','" +
- (*values)[0] + "','Are you sure want to delete currency?');",
- Hint: "Delete",
- Classes: "delete",
- },
- })
- },
- "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
- nil,
- nil,
- true,
- )
- } else if wrap.CurrSubModule == "orders" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
- {Name: "List of orders"},
- })
- content += builder.DataTable(
- wrap,
- "shop_orders",
- "id",
- "DESC",
- &[]builder.DataTableRow{
- {
- DBField: "id",
- NameInTable: "Order #",
- Classes: "d-none d-lg-table-cell",
- },
- {
- DBField: "client_phone",
- },
- {
- DBField: "update_datetime",
- },
- {
- DBField: "currency_id",
- },
- {
- DBField: "currency_name",
- },
- {
- DBField: "currency_coefficient",
- },
- {
- DBField: "currency_code",
- },
- {
- DBField: "currency_symbol",
- },
- {
- DBField: "client_last_name",
- NameInTable: "Client / Contact",
- CallBack: func(values *[]string) string {
- link := "/cp/" + wrap.CurrModule + "/orders-modify/" + (*values)[0] + "/"
- last_name := html.EscapeString((*values)[8])
- first_name := html.EscapeString((*values)[9])
- middle_name := html.EscapeString((*values)[10])
- phone := html.EscapeString((*values)[1])
- email := html.EscapeString((*values)[12])
- order_id := `<span class="d-inline d-sm-none">#` + (*values)[0] + `. </span>`
- name := ""
- if last_name != "" {
- name += " " + last_name
- }
- if first_name != "" {
- name += " " + first_name
- }
- if middle_name != "" {
- name += " " + middle_name
- }
- name = `<a href="` + link + `">` + order_id + utils.Trim(name) + `</a>`
- contact := ""
- if email != "" {
- contact += " " + email
- }
- if phone != "" {
- contact += " (" + phone + ")"
- }
- contact = `<a href="` + link + `">` + utils.Trim(contact) + `</a>`
- return `<div>` + name + `</div><div><small>` + contact + `</small></div>`
- },
- },
- {
- DBField: "client_first_name",
- },
- {
- DBField: "client_middle_name",
- },
- {
- DBField: "create_datetime",
- DBExp: "UNIX_TIMESTAMP(`create_datetime`)",
- NameInTable: "Date / Time",
- Classes: "d-none d-lg-table-cell",
- CallBack: func(values *[]string) string {
- t := int64(utils.StrToInt((*values)[11]))
- return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
- `<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
- },
- },
- {
- DBField: "client_email",
- NameInTable: "Status / Total",
- CallBack: func(values *[]string) string {
- status := this.shop_GetOrderStatus(utils.StrToInt((*values)[15]))
- total := utils.Float64ToStr(utils.StrToFloat64((*values)[16])) + " " + html.EscapeString((*values)[6])
- return `<div>` + status + `</div><div><small>` + total + `</small></div>`
- },
- },
- {
- DBField: "client_delivery_comment",
- },
- {
- DBField: "client_order_comment",
- },
- {
- DBField: "status",
- },
- {
- DBField: "total",
- },
- },
- nil,
- "/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
- nil,
- func(limit_offset int, pear_page int) (*sqlw.Rows, error) {
- return wrap.DB.Query(
- `SELECT
- shop_orders.id,
- shop_orders.client_phone,
- shop_orders.update_datetime,
- shop_orders.currency_id,
- shop_orders.currency_name,
- shop_orders.currency_coefficient,
- shop_orders.currency_code,
- shop_orders.currency_symbol,
- shop_orders.client_last_name,
- shop_orders.client_first_name,
- shop_orders.client_middle_name,
- UNIX_TIMESTAMP(shop_orders.create_datetime) as create_datetime,
- shop_orders.client_email,
- shop_orders.client_delivery_comment,
- shop_orders.client_order_comment,
- shop_orders.status,
- shop_order_total.total
- FROM
- shop_orders
- LEFT JOIN (
- SELECT
- order_id,
- SUM(price * quantity) as total
- FROM
- shop_order_products
- GROUP BY
- order_id
- ) as shop_order_total ON shop_order_total.order_id = shop_orders.id
- ORDER BY
- shop_orders.status ASC,
- shop_orders.id DESC
- LIMIT ?, ?;`,
- limit_offset,
- pear_page,
- )
- },
- true,
- )
- } else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
- if wrap.CurrSubModule == "add" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Add new product"},
- })
- } else {
- if len(wrap.UrlArgs) >= 3 && utils.IsNumeric(wrap.UrlArgs[2]) {
- content += `<div class="product-copy"><a title="Duplicate product" href="javascript:fave.ShopProductsDuplicate(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconCopy + `</a></div>`
- content += `<div class="product-another"><a title="Duplicate product and attach" href="javascript:fave.ShopProductsDuplicateWithAttach(this, ` + wrap.UrlArgs[2] + `);">` + assets.SysSvgIconPlus + `</a></div>`
- }
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Modify product"},
- })
- }
- data := utils.MySql_shop_product{
- A_id: 0,
- A_user: 0,
- A_currency: 0,
- A_price: 0,
- A_price_old: 0,
- A_gname: "",
- A_name: "",
- A_alias: "",
- A_vendor: "",
- A_quantity: 0,
- A_category: 0,
- A_briefly: "",
- A_content: "",
- A_datetime: 0,
- A_active: 0,
- A_custom1: "",
- A_custom2: "",
- }
- if wrap.CurrSubModule == "modify" {
- if len(wrap.UrlArgs) != 3 {
- return "", "", ""
- }
- if !utils.IsNumeric(wrap.UrlArgs[2]) {
- return "", "", ""
- }
- err := wrap.DB.QueryRow(`
- SELECT
- id,
- parent_id,
- user,
- currency,
- price,
- price_old,
- gname,
- name,
- alias,
- vendor,
- quantity,
- category,
- briefly,
- content,
- active,
- custom1,
- custom2
- FROM
- shop_products
- WHERE
- id = ?
- LIMIT 1;`,
- utils.StrToInt(wrap.UrlArgs[2]),
- ).Scan(
- &data.A_id,
- &data.A_parent,
- &data.A_user,
- &data.A_currency,
- &data.A_price,
- &data.A_price_old,
- &data.A_gname,
- &data.A_name,
- &data.A_alias,
- &data.A_vendor,
- &data.A_quantity,
- &data.A_category,
- &data.A_briefly,
- &data.A_content,
- &data.A_active,
- &data.A_custom1,
- &data.A_custom2,
- )
- if *wrap.LogCpError(&err) != nil {
- return "", "", ""
- }
- }
- if data.A_parent_id() > 0 {
- content += `<style>.product-another{display:none}</style>`
- }
- // All product current categories
- var selids []int
- if data.A_id > 0 {
- rows, err := wrap.DB.Query("SELECT category_id FROM shop_cat_product_rel WHERE product_id = ?;", data.A_id)
- if err == nil {
- defer rows.Close()
- values := make([]int, 1)
- scan := make([]interface{}, len(values))
- for i := range values {
- scan[i] = &values[i]
- }
- for rows.Next() {
- err = rows.Scan(scan...)
- if *wrap.LogCpError(&err) == nil {
- selids = append(selids, int(values[0]))
- }
- }
- }
- }
- // Sub products
- sub_products := ``
- if data.A_id >= 1 && data.A_parent_id() <= 0 {
- sub_products = this.shop_GetSubProducts(wrap, data.A_id)
- }
- btn_caption := "Add"
- if wrap.CurrSubModule == "modify" {
- btn_caption = "Save"
- }
- content += builder.DataForm(wrap, []builder.DataFormField{
- {
- Kind: builder.DFKHidden,
- Name: "action",
- Value: "shop-modify",
- },
- {
- Kind: builder.DFKHidden,
- Name: "id",
- Value: utils.IntToStr(data.A_id),
- },
- {
- Kind: builder.DFKText,
- CallBack: func(field *builder.DataFormField) string {
- if data.A_id >= 1 && data.A_parent_id() <= 0 {
- return `<div class="form-group nf">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label>Sub products</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div class="list-wrapper">` +
- sub_products +
- `<div><a href="javascript:fave.ShopAttachProduct(` + utils.IntToStr(data.A_id) + `);"><b>Attach product</b></a></div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- }
- return ""
- },
- },
- {
- Kind: builder.DFKText,
- CallBack: func(field *builder.DataFormField) string {
- if data.A_id >= 1 && data.A_parent_id() != 0 {
- return `<div class="form-group nf">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label>Parent</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div class="list-wrapper">` +
- this.shop_GetParentProduct(wrap, data.A_parent_id()) +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- }
- return ""
- },
- },
- {
- Kind: builder.DFKText,
- CallBack: func(field *builder.DataFormField) string {
- if data.A_id >= 1 && data.A_parent_id() <= 0 && sub_products != "" {
- return `<div class="form-group nf">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_gname">Group name</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div><input class="form-control" type="text" id="lbl_gname" name="gname" value="` + html.EscapeString(data.A_gname) + `" maxlength="255" autocomplete="off"></div>` +
- `</div>` +
- `</div>` +
- `</div>`
- }
- return ""
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Product name",
- Name: "name",
- Value: data.A_name,
- Required: true,
- Min: "1",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Product price",
- Name: "price",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n6">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_price">Product price</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div>` +
- `<div class="row">` +
- `<div class="col-md-8">` +
- `<div class="row">` +
- `<div class="col-md-6">` +
- `<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>` +
- `</div>` +
- `<div class="col-md-6">` +
- `<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>` +
- `</div>` +
- `</div>` +
- `<div class="d-md-none mb-3"></div>` +
- `</div>` +
- `<div class="col-md-4">` +
- `<select class="selectpicker form-control" id="lbl_currency" name="currency" data-live-search="true">` +
- this.shop_GetCurrencySelectOptions(wrap, data.A_currency) +
- `</select>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Product alias",
- Name: "alias",
- Value: data.A_alias,
- Hint: "Example: mobile-phone",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Vendor/Count",
- Name: "vendor",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n8">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_vendor">Vendor/Count</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div>` +
- `<div class="row">` +
- `<div class="col-md-8">` +
- `<div><input class="form-control" type="text" id="lbl_vendor" name="vendor" value="` + html.EscapeString(data.A_vendor) + `" placeholder="" autocomplete="off"></div>` +
- `<div class="d-md-none mb-3"></div>` +
- `</div>` +
- `<div class="col-md-4">` +
- `<input class="form-control" type="number" step="1" id="lbl_quantity" name="quantity" value="` + utils.IntToStr(data.A_quantity) + `" placeholder="" autocomplete="off">` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Category",
- Name: "category",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n9">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_category">Category</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div>` +
- `<select class="selectpicker form-control" id="lbl_category" name="category" data-live-search="true">` +
- `<option title="Nothing selected" value="0">—</option>` +
- this.shop_GetCategorySelectOptions(wrap, 0, data.A_category, []int{}) +
- `</select>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Categories",
- Name: "cats",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n10">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_cats">Categories</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div>` +
- `<select class="selectpicker form-control" id="lbl_cats" name="cats[]" data-live-search="true" multiple>` +
- this.shop_GetCategorySelectOptions(wrap, 0, 0, selids) +
- `</select>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Attributes",
- Name: "",
- Value: "",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n11">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label>Attributes</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div class="list-wrapper">` +
- `<div id="list">` +
- this.shop_GetProductValuesInputs(wrap, data.A_id) +
- `</div>` +
- `<div class="list-button position-relative">` +
- `<select class="selectpicker form-control" id="lbl_attributes" data-live-search="true" onchange="fave.ShopProductsAdd();">` +
- this.shop_GetAllAttributesSelectOptions(wrap) +
- `</select>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKTextArea,
- Caption: "Briefly",
- Name: "briefly",
- Value: data.A_briefly,
- Classes: "briefly wysiwyg",
- },
- {
- Kind: builder.DFKTextArea,
- Caption: "Product content",
- Name: "content",
- Value: data.A_content,
- Classes: "wysiwyg",
- },
- {
- Kind: builder.DFKText,
- Caption: "Product images",
- Name: "",
- Value: "",
- CallBack: func(field *builder.DataFormField) string {
- if data.A_id == 0 {
- return ``
- }
- return `<div class="form-group n14">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label>Product images</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div class="list-wrapper">` +
- `<div id="list-images">` +
- this.shop_GetAllProductImages(wrap, data.A_id) +
- `</div>` +
- `<div id="img-upload-block" class="list-button position-relative">` +
- `<div id="upload-msg">Uploading...</div>` +
- `<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 />` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `<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>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Custom field 1",
- Name: "",
- Value: "",
- CallBack: func(field *builder.DataFormField) string {
- if (*wrap.Config).Shop.CustomFields.Field1.Enabled <= 0 {
- return ``
- }
- return `<div class="form-group nf">
- <div class="row">
- <div class="col-md-3">
- <label for="lbl_custom1">` + (*wrap.Config).Shop.CustomFields.Field1.Caption + `</label>
- </div>
- <div class="col-md-9">
- <div><input class="form-control" type="text" id="lbl_custom1" name="custom1" value="` + html.EscapeString(data.A_custom1) + `" maxlength="2048" autocomplete="off"></div>
- </div>
- </div>
- </div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Custom field 2",
- Name: "",
- Value: "",
- CallBack: func(field *builder.DataFormField) string {
- if (*wrap.Config).Shop.CustomFields.Field2.Enabled <= 0 {
- return ``
- }
- return `<div class="form-group nf">
- <div class="row">
- <div class="col-md-3">
- <label for="lbl_custom2">` + (*wrap.Config).Shop.CustomFields.Field2.Caption + `</label>
- </div>
- <div class="col-md-9">
- <div><input class="form-control" type="text" id="lbl_custom2" name="custom2" value="` + html.EscapeString(data.A_custom2) + `" maxlength="2048" autocomplete="off"></div>
- </div>
- </div>
- </div>`
- },
- },
- {
- Kind: builder.DFKCheckBox,
- Caption: "Active",
- Name: "active",
- Value: utils.IntToStr(data.A_active),
- },
- {
- Kind: builder.DFKSubmit,
- Value: btn_caption,
- Target: "add-edit-button",
- },
- })
- if wrap.CurrSubModule == "add" {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
- } else {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
- }
- } else if wrap.CurrSubModule == "categories-add" || wrap.CurrSubModule == "categories-modify" {
- if wrap.CurrSubModule == "categories-add" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
- {Name: "Add new category"},
- })
- } else {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Categories", Link: "/cp/" + wrap.CurrModule + "/categories/"},
- {Name: "Modify category"},
- })
- }
- data := utils.MySql_shop_category{
- A_id: 0,
- A_user: 0,
- A_name: "",
- A_alias: "",
- A_lft: 0,
- A_rgt: 0,
- }
- if wrap.CurrSubModule == "categories-modify" {
- if len(wrap.UrlArgs) != 3 {
- return "", "", ""
- }
- if !utils.IsNumeric(wrap.UrlArgs[2]) {
- return "", "", ""
- }
- err := wrap.DB.QueryRow(`
- SELECT
- id,
- user,
- name,
- alias,
- lft,
- rgt
- FROM
- shop_cats
- WHERE
- id = ?
- LIMIT 1;`,
- utils.StrToInt(wrap.UrlArgs[2]),
- ).Scan(
- &data.A_id,
- &data.A_user,
- &data.A_name,
- &data.A_alias,
- &data.A_lft,
- &data.A_rgt,
- )
- if *wrap.LogCpError(&err) != nil {
- return "", "", ""
- }
- }
- btn_caption := "Add"
- if wrap.CurrSubModule == "categories-modify" {
- btn_caption = "Save"
- }
- parentId := 0
- if wrap.CurrSubModule == "categories-modify" {
- parentId = this.shop_GetCategoryParentId(wrap, data.A_id)
- }
- content += builder.DataForm(wrap, []builder.DataFormField{
- {
- Kind: builder.DFKHidden,
- Name: "action",
- Value: "shop-categories-modify",
- },
- {
- Kind: builder.DFKHidden,
- Name: "id",
- Value: utils.IntToStr(data.A_id),
- },
- {
- Kind: builder.DFKText,
- Caption: "Parent",
- Name: "parent",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n2">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_parent">Parent</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div>` +
- `<select class="selectpicker form-control" id="lbl_parent" name="parent" data-live-search="true">` +
- `<option title="Nothing selected" value="0">—</option>` +
- this.shop_GetCategorySelectOptions(wrap, data.A_id, parentId, []int{}) +
- `</select>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Name",
- Name: "name",
- Value: data.A_name,
- Required: true,
- Min: "1",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Alias",
- Name: "alias",
- Value: data.A_alias,
- Hint: "Example: popular-products",
- Max: "255",
- },
- {
- Kind: builder.DFKSubmit,
- Value: btn_caption,
- Target: "add-edit-button",
- },
- })
- if wrap.CurrSubModule == "categories-add" {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
- } else {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
- }
- } else if wrap.CurrSubModule == "attributes-add" || wrap.CurrSubModule == "attributes-modify" {
- if wrap.CurrSubModule == "attributes-add" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
- {Name: "Add new attribute"},
- })
- } else {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Attributes", Link: "/cp/" + wrap.CurrModule + "/attributes/"},
- {Name: "Modify attribute"},
- })
- }
- data := utils.MySql_shop_filter{
- A_id: 0,
- A_name: "",
- A_filter: "",
- }
- if wrap.CurrSubModule == "attributes-modify" {
- if len(wrap.UrlArgs) != 3 {
- return "", "", ""
- }
- if !utils.IsNumeric(wrap.UrlArgs[2]) {
- return "", "", ""
- }
- err := wrap.DB.QueryRow(`
- SELECT
- id,
- name,
- filter
- FROM
- shop_filters
- WHERE
- id = ?
- LIMIT 1;`,
- utils.StrToInt(wrap.UrlArgs[2]),
- ).Scan(
- &data.A_id,
- &data.A_name,
- &data.A_filter,
- )
- if *wrap.LogCpError(&err) != nil {
- return "", "", ""
- }
- }
- btn_caption := "Add"
- if wrap.CurrSubModule == "attributes-modify" {
- btn_caption = "Save"
- }
- content += builder.DataForm(wrap, []builder.DataFormField{
- {
- Kind: builder.DFKHidden,
- Name: "action",
- Value: "shop-attributes-modify",
- },
- {
- Kind: builder.DFKHidden,
- Name: "id",
- Value: utils.IntToStr(data.A_id),
- },
- {
- Kind: builder.DFKText,
- Caption: "Attribute name",
- Name: "name",
- Value: data.A_name,
- Required: true,
- Min: "1",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Attribute in filter",
- Name: "filter",
- Value: data.A_filter,
- Required: true,
- Min: "1",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Attribute values",
- Name: "",
- Value: "",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n4">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label>Attribute values</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<div class="list-wrapper">` +
- `<div id="list">` +
- this.shop_GetFilterValuesInputs(wrap, data.A_id) +
- `</div>` +
- `<div class="list-button"><button type="button" class="btn btn-success" onclick="fave.ShopAttributesAdd();">Add attribute value</button></div>` +
- `</div>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKSubmit,
- Value: btn_caption,
- Target: "add-edit-button",
- },
- })
- if wrap.CurrSubModule == "attributes-add" {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
- } else {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
- }
- } else if wrap.CurrSubModule == "currencies-add" || wrap.CurrSubModule == "currencies-modify" {
- if wrap.CurrSubModule == "currencies-add" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
- {Name: "Add new currency"},
- })
- } else {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Currencies", Link: "/cp/" + wrap.CurrModule + "/currencies/"},
- {Name: "Modify currency"},
- })
- }
- data := utils.MySql_shop_currency{
- A_id: 0,
- A_name: "",
- A_coefficient: 0,
- A_code: "",
- A_symbol: "",
- }
- if wrap.CurrSubModule == "currencies-modify" {
- if len(wrap.UrlArgs) != 3 {
- return "", "", ""
- }
- if !utils.IsNumeric(wrap.UrlArgs[2]) {
- return "", "", ""
- }
- err := wrap.DB.QueryRow(`
- SELECT
- id,
- name,
- coefficient,
- code,
- symbol
- FROM
- shop_currencies
- WHERE
- id = ?
- LIMIT 1;`,
- utils.StrToInt(wrap.UrlArgs[2]),
- ).Scan(
- &data.A_id,
- &data.A_name,
- &data.A_coefficient,
- &data.A_code,
- &data.A_symbol,
- )
- if *wrap.LogCpError(&err) != nil {
- return "", "", ""
- }
- }
- btn_caption := "Add"
- if wrap.CurrSubModule == "currencies-modify" {
- btn_caption = "Save"
- }
- content += builder.DataForm(wrap, []builder.DataFormField{
- {
- Kind: builder.DFKHidden,
- Name: "action",
- Value: "shop-currencies-modify",
- },
- {
- Kind: builder.DFKHidden,
- Name: "id",
- Value: utils.IntToStr(data.A_id),
- },
- {
- Kind: builder.DFKText,
- Caption: "Currency name",
- Name: "name",
- Value: data.A_name,
- Required: true,
- Min: "1",
- Max: "255",
- },
- {
- Kind: builder.DFKText,
- Caption: "Currency coefficient",
- Name: "coefficient",
- Value: "0",
- CallBack: func(field *builder.DataFormField) string {
- return `<div class="form-group n3">` +
- `<div class="row">` +
- `<div class="col-md-3">` +
- `<label for="lbl_coefficient">Currency coefficient</label>` +
- `</div>` +
- `<div class="col-md-9">` +
- `<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>` +
- `</div>` +
- `</div>` +
- `</div>`
- },
- },
- {
- Kind: builder.DFKText,
- Caption: "Currency code",
- Name: "code",
- Value: data.A_code,
- Required: true,
- Min: "1",
- Max: "10",
- },
- {
- Kind: builder.DFKText,
- Caption: "Currency symbol",
- Name: "symbol",
- Value: data.A_symbol,
- Required: true,
- Min: "1",
- Max: "5",
- },
- {
- Kind: builder.DFKSubmit,
- Value: btn_caption,
- Target: "add-edit-button",
- },
- })
- if wrap.CurrSubModule == "currencies-add" {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
- } else {
- sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
- }
- } else if wrap.CurrSubModule == "orders-modify" {
- content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
- {Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/orders/"},
- {Name: "Modify order"},
- })
- if len(wrap.UrlArgs) != 3 {
- return "", "", ""
- }
- if !utils.IsNumeric(wrap.UrlArgs[2]) {
- return "", "", ""
- }
- var curr_order_id int
- var curr_order_client_phone string
- var curr_order_update_datetime string
- var curr_order_currency_id int
- var curr_order_currency_name string
- var curr_order_currency_coefficient float64
- var curr_order_currency_code string
- var curr_order_currency_symbol string
- var curr_order_client_last_name string
- var curr_order_client_first_name string
- var curr_order_client_middle_name string
- var curr_order_create_datetime int
- var curr_order_client_email string
- var curr_order_client_delivery_comment string
- var curr_order_client_order_comment string
- var curr_order_status int
- var curr_order_total float64
- err := wrap.DB.QueryRow(`
- SELECT
- shop_orders.id,
- shop_orders.client_phone,
- shop_orders.update_datetime,
- shop_orders.currency_id,
- shop_orders.currency_name,
- shop_orders.currency_coefficient,
- shop_orders.currency_code,
- shop_orders.currency_symbol,
- shop_orders.client_last_name,
- shop_orders.client_first_name,
- shop_orders.client_middle_name,
- UNIX_TIMESTAMP(shop_orders.create_datetime) as create_datetime,
- shop_orders.client_email,
- shop_orders.client_delivery_comment,
- shop_orders.client_order_comment,
- shop_orders.status,
- shop_order_total.total
- FROM
- shop_orders
- LEFT JOIN (
- SELECT
- order_id,
- SUM(price * quantity) as total
- FROM
- shop_order_products
- GROUP BY
- order_id
- ) as shop_order_total ON shop_order_total.order_id = shop_orders.id
- WHERE
- shop_orders.id = ?
- LIMIT 1;`,
- utils.StrToInt(wrap.UrlArgs[2]),
- ).Scan(
- &curr_order_id,
- &curr_order_client_phone,
- &curr_order_update_datetime,
- &curr_order_currency_id,
- &curr_order_currency_name,
- &curr_order_currency_coefficient,
- &curr_order_currency_code,
- &curr_order_currency_symbol,
- &curr_order_client_last_name,
- &curr_order_client_first_name,
- &curr_order_client_middle_name,
- &curr_order_create_datetime,
- &curr_order_client_email,
- &curr_order_client_delivery_comment,
- &curr_order_client_order_comment,
- &curr_order_status,
- &curr_order_total,
- )
- if *wrap.LogCpError(&err) != nil {
- return "", "", ""
- }
- last_name := html.EscapeString(curr_order_client_last_name)
- first_name := html.EscapeString(curr_order_client_first_name)
- middle_name := html.EscapeString(curr_order_client_middle_name)
- phone := html.EscapeString(curr_order_client_phone)
- email := html.EscapeString(curr_order_client_email)
- order_id := `<span class="d-inline d-sm-none">#` + utils.IntToStr(curr_order_id) + `. </span>`
- name := ""
- if last_name != "" {
- name += " " + last_name
- }
- if first_name != "" {
- name += " " + first_name
- }
- if middle_name != "" {
- name += " " + middle_name
- }
- name = order_id + utils.Trim(name)
- contact := ""
- if email != "" {
- contact += " " + email
- }
- if phone != "" {
- contact += " (" + phone + ")"
- }
- contact = utils.Trim(contact)
- content += `<table id="cp-table-shop_orders" class="table data-table table-striped table-bordered table-hover table_shop_orders">
- <thead>
- <tr>
- <th scope="col" class="col_id d-none d-lg-table-cell">Order #</th>
- <th scope="col" class="col_client_last_name">Client / Contact</th>
- <th scope="col" class="col_create_datetime d-none d-lg-table-cell">Date / Time</th>
- <th scope="col" class="col_client_email">Status / Total</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="col_id d-none d-lg-table-cell">` + utils.IntToStr(curr_order_id) + `</td>
- <td class="col_client_last_name">
- <div>` + name + `</div>
- <div><small>` + contact + `</small></div>
- <div>
- <small>
- <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>
- </small>
- </div>
- </td>
- <td class="col_create_datetime d-none d-lg-table-cell">
- <div>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "02.01.2006") + `</div>
- <div><small>` + utils.UnixTimestampToFormat(int64(curr_order_create_datetime), "15:04:05") + `</small></div>
- </td>
- <td class="col_client_email">
- <div>` + this.shop_GetOrderStatus(curr_order_status) + `</div>
- <div><small>` + utils.Float64ToStr(curr_order_total) + " " + html.EscapeString(curr_order_currency_code) + `</small></div>
- </td>
- </tr>
- </tbody>
- </table>`
- content += `<table id="cp-table-shop_products" class="table data-table table-striped table-bordered table-hover mt-3 table_shop_products">
- <thead>
- <tr>
- <th scope="col" class="col_name">Product</th>
- <th scope="col" class="col_price d-none d-md-table-cell">Price</th>
- <th scope="col" class="col_quantity">Quantity</th>
- <th scope="col" class="col_total d-none d-md-table-cell">Total</th>
- </tr>
- </thead>
- <tbody>
- `
- rows, err := wrap.DB.Query(
- `SELECT
- shop_order_products.product_id,
- shop_products.name,
- shop_products.alias,
- shop_order_products.price,
- shop_order_products.quantity,
- (shop_order_products.price * shop_order_products.quantity) as total
- FROM
- shop_order_products
- LEFT JOIN shop_products ON shop_products.id = shop_order_products.product_id
- WHERE
- shop_order_products.order_id = ?
- ;`,
- curr_order_id,
- )
- if err == nil {
- defer rows.Close()
- var curr_product_id int
- var curr_product_name string
- var curr_product_alias string
- var curr_product_price float64
- var curr_product_quantity int
- var curr_product_total float64
- for rows.Next() {
- err = rows.Scan(
- &curr_product_id,
- &curr_product_name,
- &curr_product_alias,
- &curr_product_price,
- &curr_product_quantity,
- &curr_product_total,
- )
- if *wrap.LogCpError(&err) == nil {
- content += `<tr>
- <td class="col_name">
- <div><a href="/cp/shop/modify/` + utils.IntToStr(curr_product_id) + `/">` + html.EscapeString(curr_product_name) + ` ` + utils.IntToStr(curr_product_id) + `</a></div>
- <div><small><a href="/shop/` + html.EscapeString(curr_product_alias) + `/" target="_blank">/shop/` + html.EscapeString(curr_product_alias) + `/</a></small></div>
- </td>
- <td class="col_price d-none d-md-table-cell">
- <div>` + utils.Float64ToStr(curr_product_price) + `</div>
- <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
- </td>
- <td class="col_quantity">
- ` + utils.IntToStr(curr_product_quantity) + `
- </td>
- <td class="col_total d-none d-md-table-cell">
- <div>` + utils.Float64ToStr(curr_product_total) + `</div>
- <div><small>` + html.EscapeString(curr_order_currency_code) + `</small></div>
- </td>
- </tr>`
- }
- }
- }
- content += `</tbody>
- </table>`
- // Delivery
- content += `<div class="card mt-3">
- <div class="card-header"><b>Delivery</b></div>
- <ul class="list-group list-group-flush">
- <li class="list-group-item">`
- if utils.Trim(curr_order_client_delivery_comment) != "" {
- content += html.EscapeString(curr_order_client_delivery_comment)
- } else {
- content += `NO SET`
- }
- content += `</li>
- </ul>
- </div>`
- // Comment
- content += `<div class="card mt-3">
- <div class="card-header"><b>Comment</b></div>
- <ul class="list-group list-group-flush">
- <li class="list-group-item">`
- if utils.Trim(curr_order_client_order_comment) != "" {
- content += html.EscapeString(curr_order_client_order_comment)
- } else {
- content += `NO SET`
- }
- content += `</li>
- </ul>
- </div>`
- }
- return this.getSidebarModules(wrap), content, sidebar
- })
- }
|