shop.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. package fetdata
  2. import (
  3. "math"
  4. "sort"
  5. "strings"
  6. "golang-fave/engine/utils"
  7. "golang-fave/engine/wrapper"
  8. )
  9. type ShopPagination struct {
  10. Num string
  11. Link string
  12. Current bool
  13. Dots bool
  14. }
  15. type Shop struct {
  16. wrap *wrapper.Wrapper
  17. category *ShopCategory
  18. product *ShopProduct
  19. products []*ShopProduct
  20. productsCount int
  21. productsPerPage int
  22. productsMaxPage int
  23. productsCurrPage int
  24. pagination []*ShopPagination
  25. paginationPrev *ShopPagination
  26. paginationNext *ShopPagination
  27. bufferCats map[int]*utils.MySql_shop_category
  28. }
  29. func (this *Shop) load() *Shop {
  30. if this == nil {
  31. return this
  32. }
  33. if (*this.wrap.Config).Modules.Enabled.Shop == 0 {
  34. return this
  35. }
  36. sql_nums := `
  37. SELECT
  38. COUNT(*)
  39. FROM
  40. fave_shop_products
  41. WHERE
  42. active = 1 AND
  43. parent_id IS NULL
  44. ;
  45. `
  46. sql_rows := `
  47. SELECT
  48. fave_shop_products.id,
  49. fave_shop_products.user,
  50. fave_shop_products.currency,
  51. fave_shop_products.price,
  52. fave_shop_products.price_old,
  53. fave_shop_products.gname,
  54. fave_shop_products.name,
  55. fave_shop_products.alias,
  56. fave_shop_products.vendor,
  57. fave_shop_products.quantity,
  58. fave_shop_products.category,
  59. fave_shop_products.briefly,
  60. fave_shop_products.content,
  61. UNIX_TIMESTAMP(fave_shop_products.datetime) as datetime,
  62. fave_shop_products.active,
  63. fave_users.id,
  64. fave_users.first_name,
  65. fave_users.last_name,
  66. fave_users.email,
  67. fave_users.admin,
  68. fave_users.active,
  69. fave_shop_currencies.id,
  70. fave_shop_currencies.name,
  71. fave_shop_currencies.coefficient,
  72. fave_shop_currencies.code,
  73. fave_shop_currencies.symbol,
  74. cats.id,
  75. cats.user,
  76. cats.name,
  77. cats.alias,
  78. cats.lft,
  79. cats.rgt,
  80. cats.depth,
  81. cats.parent_id
  82. FROM
  83. fave_shop_products
  84. LEFT JOIN fave_users ON fave_users.id = fave_shop_products.user
  85. LEFT JOIN fave_shop_currencies ON fave_shop_currencies.id = fave_shop_products.currency
  86. LEFT JOIN (
  87. SELECT
  88. main.id,
  89. main.user,
  90. main.name,
  91. main.alias,
  92. main.lft,
  93. main.rgt,
  94. main.depth,
  95. parent.id AS parent_id
  96. FROM
  97. (
  98. SELECT
  99. node.id,
  100. node.user,
  101. node.name,
  102. node.alias,
  103. node.lft,
  104. node.rgt,
  105. (COUNT(parent.id) - 1) AS depth
  106. FROM
  107. fave_shop_cats AS node,
  108. fave_shop_cats AS parent
  109. WHERE
  110. node.lft BETWEEN parent.lft AND parent.rgt
  111. GROUP BY
  112. node.id
  113. ORDER BY
  114. node.lft ASC
  115. ) AS main
  116. LEFT JOIN (
  117. SELECT
  118. node.id,
  119. node.user,
  120. node.name,
  121. node.alias,
  122. node.lft,
  123. node.rgt,
  124. (COUNT(parent.id) - 0) AS depth
  125. FROM
  126. fave_shop_cats AS node,
  127. fave_shop_cats AS parent
  128. WHERE
  129. node.lft BETWEEN parent.lft AND parent.rgt
  130. GROUP BY
  131. node.id
  132. ORDER BY
  133. node.lft ASC
  134. ) AS parent ON
  135. parent.depth = main.depth AND
  136. main.lft > parent.lft AND
  137. main.rgt < parent.rgt
  138. WHERE
  139. main.id > 1
  140. ORDER BY
  141. main.lft ASC
  142. ) AS cats ON cats.id = fave_shop_products.category
  143. WHERE
  144. fave_shop_products.active = 1 AND
  145. fave_shop_products.parent_id IS NULL
  146. ORDER BY
  147. fave_shop_products.quantity DESC,
  148. fave_shop_products.id DESC
  149. LIMIT ?, ?;
  150. `
  151. // Category selected
  152. if this.category != nil {
  153. var cat_ids []string
  154. if rows, err := this.wrap.DB.Query(
  155. this.wrap.R.Context(),
  156. `SELECT
  157. node.id
  158. FROM
  159. fave_shop_cats AS node,
  160. fave_shop_cats AS parent
  161. WHERE
  162. node.lft BETWEEN parent.lft AND parent.rgt AND
  163. node.id > 1 AND
  164. parent.id = ?
  165. GROUP BY
  166. node.id
  167. ORDER BY
  168. node.lft ASC
  169. ;`,
  170. this.category.Id(),
  171. ); err == nil {
  172. defer rows.Close()
  173. for rows.Next() {
  174. var cat_id string
  175. if err := rows.Scan(&cat_id); *this.wrap.LogCpError(&err) == nil {
  176. cat_ids = append(cat_ids, cat_id)
  177. }
  178. }
  179. }
  180. sql_nums = `
  181. SELECT
  182. COUNT(*)
  183. FROM
  184. (
  185. SELECT
  186. COUNT(*)
  187. FROM
  188. fave_shop_products
  189. LEFT JOIN fave_shop_cat_product_rel ON fave_shop_cat_product_rel.product_id = fave_shop_products.id
  190. WHERE
  191. fave_shop_products.active = 1 AND
  192. fave_shop_products.parent_id IS NULL AND
  193. fave_shop_cat_product_rel.category_id IN (` + strings.Join(cat_ids, ", ") + `)
  194. GROUP BY
  195. fave_shop_products.id
  196. ) AS tbl
  197. ;
  198. `
  199. sql_rows = `
  200. SELECT
  201. fave_shop_products.id,
  202. fave_shop_products.user,
  203. fave_shop_products.currency,
  204. fave_shop_products.price,
  205. fave_shop_products.price_old,
  206. fave_shop_products.gname,
  207. fave_shop_products.name,
  208. fave_shop_products.alias,
  209. fave_shop_products.vendor,
  210. fave_shop_products.quantity,
  211. fave_shop_products.category,
  212. fave_shop_products.briefly,
  213. fave_shop_products.content,
  214. UNIX_TIMESTAMP(fave_shop_products.datetime) AS datetime,
  215. fave_shop_products.active,
  216. fave_users.id,
  217. fave_users.first_name,
  218. fave_users.last_name,
  219. fave_users.email,
  220. fave_users.admin,
  221. fave_users.active,
  222. fave_shop_currencies.id,
  223. fave_shop_currencies.name,
  224. fave_shop_currencies.coefficient,
  225. fave_shop_currencies.code,
  226. fave_shop_currencies.symbol,
  227. cats.id,
  228. cats.user,
  229. cats.name,
  230. cats.alias,
  231. cats.lft,
  232. cats.rgt,
  233. cats.depth,
  234. cats.parent_id
  235. FROM
  236. fave_shop_products
  237. LEFT JOIN fave_shop_cat_product_rel ON fave_shop_cat_product_rel.product_id = fave_shop_products.id
  238. LEFT JOIN fave_users ON fave_users.id = fave_shop_products.user
  239. LEFT JOIN fave_shop_currencies ON fave_shop_currencies.id = fave_shop_products.currency
  240. LEFT JOIN (
  241. SELECT
  242. main.id,
  243. main.user,
  244. main.name,
  245. main.alias,
  246. main.lft,
  247. main.rgt,
  248. main.depth,
  249. parent.id AS parent_id
  250. FROM
  251. (
  252. SELECT
  253. node.id,
  254. node.user,
  255. node.name,
  256. node.alias,
  257. node.lft,
  258. node.rgt,
  259. (COUNT(parent.id) - 1) AS depth
  260. FROM
  261. fave_shop_cats AS node,
  262. fave_shop_cats AS parent
  263. WHERE
  264. node.lft BETWEEN parent.lft AND parent.rgt
  265. GROUP BY
  266. node.id
  267. ORDER BY
  268. node.lft ASC
  269. ) AS main
  270. LEFT JOIN (
  271. SELECT
  272. node.id,
  273. node.user,
  274. node.name,
  275. node.alias,
  276. node.lft,
  277. node.rgt,
  278. (COUNT(parent.id) - 0) AS depth
  279. FROM
  280. fave_shop_cats AS node,
  281. fave_shop_cats AS parent
  282. WHERE
  283. node.lft BETWEEN parent.lft AND parent.rgt
  284. GROUP BY
  285. node.id
  286. ORDER BY
  287. node.lft ASC
  288. ) AS parent ON
  289. parent.depth = main.depth AND
  290. main.lft > parent.lft AND
  291. main.rgt < parent.rgt
  292. WHERE
  293. main.id > 1
  294. ORDER BY
  295. main.lft ASC
  296. ) AS cats ON cats.id = fave_shop_products.category
  297. WHERE
  298. fave_shop_products.active = 1 AND
  299. fave_shop_products.parent_id IS NULL AND
  300. fave_shop_cat_product_rel.category_id IN (` + strings.Join(cat_ids, ", ") + `)
  301. GROUP BY
  302. fave_shop_products.id,
  303. cats.parent_id
  304. ORDER BY
  305. fave_shop_products.quantity DESC,
  306. fave_shop_products.id DESC
  307. LIMIT ?, ?;
  308. `
  309. }
  310. product_ids := []string{}
  311. if err := this.wrap.DB.QueryRow(this.wrap.R.Context(), sql_nums).Scan(&this.productsCount); *this.wrap.LogCpError(&err) == nil {
  312. if this.category == nil {
  313. this.productsPerPage = (*this.wrap.Config).Shop.Pagination.Index
  314. } else {
  315. this.productsPerPage = (*this.wrap.Config).Shop.Pagination.Category
  316. }
  317. this.productsMaxPage = int(math.Ceil(float64(this.productsCount) / float64(this.productsPerPage)))
  318. this.productsCurrPage = this.wrap.GetCurrentPage(this.productsMaxPage)
  319. offset := this.productsCurrPage*this.productsPerPage - this.productsPerPage
  320. if rows, err := this.wrap.DB.Query(this.wrap.R.Context(), sql_rows, offset, this.productsPerPage); err == nil {
  321. defer rows.Close()
  322. for rows.Next() {
  323. rp := utils.MySql_shop_product{}
  324. ru := utils.MySql_user{}
  325. rc := utils.MySql_shop_currency{}
  326. ro := utils.MySql_shop_category{}
  327. if err := rows.Scan(
  328. &rp.A_id,
  329. &rp.A_user,
  330. &rp.A_currency,
  331. &rp.A_price,
  332. &rp.A_price_old,
  333. &rp.A_gname,
  334. &rp.A_name,
  335. &rp.A_alias,
  336. &rp.A_vendor,
  337. &rp.A_quantity,
  338. &rp.A_category,
  339. &rp.A_briefly,
  340. &rp.A_content,
  341. &rp.A_datetime,
  342. &rp.A_active,
  343. &ru.A_id,
  344. &ru.A_first_name,
  345. &ru.A_last_name,
  346. &ru.A_email,
  347. &ru.A_admin,
  348. &ru.A_active,
  349. &rc.A_id,
  350. &rc.A_name,
  351. &rc.A_coefficient,
  352. &rc.A_code,
  353. &rc.A_symbol,
  354. &ro.A_id,
  355. &ro.A_user,
  356. &ro.A_name,
  357. &ro.A_alias,
  358. &ro.A_lft,
  359. &ro.A_rgt,
  360. &ro.A_depth,
  361. &ro.A_parent,
  362. ); *this.wrap.LogCpError(&err) == nil {
  363. product_ids = append(product_ids, utils.IntToStr(rp.A_id))
  364. this.products = append(this.products, &ShopProduct{
  365. wrap: this.wrap,
  366. object: &rp,
  367. user: &User{wrap: this.wrap, object: &ru},
  368. currency: &ShopCurrency{wrap: this.wrap, object: &rc},
  369. category: &ShopCategory{wrap: this.wrap, object: &ro},
  370. })
  371. }
  372. }
  373. }
  374. }
  375. // Product images
  376. product_images := map[int][]*ShopProductImage{}
  377. if len(product_ids) > 0 {
  378. if rows, err := this.wrap.DB.Query(
  379. this.wrap.R.Context(),
  380. `SELECT
  381. fave_shop_product_images.product_id,
  382. fave_shop_product_images.filename
  383. FROM
  384. fave_shop_product_images
  385. WHERE
  386. fave_shop_product_images.product_id IN (`+strings.Join(product_ids, ", ")+`)
  387. ORDER BY
  388. fave_shop_product_images.ord ASC
  389. ;`,
  390. ); err == nil {
  391. defer rows.Close()
  392. for rows.Next() {
  393. img := utils.MySql_shop_product_image{}
  394. if err := rows.Scan(
  395. &img.A_product_id,
  396. &img.A_filename,
  397. ); *this.wrap.LogCpError(&err) == nil {
  398. product_images[img.A_product_id] = append(product_images[img.A_product_id], &ShopProductImage{wrap: this.wrap, object: &img})
  399. }
  400. }
  401. }
  402. }
  403. for index, product := range this.products {
  404. if pimgs, ok := product_images[product.Id()]; ok {
  405. this.products[index].images = pimgs
  406. }
  407. }
  408. // Build pagination
  409. if true {
  410. for i := 1; i < this.productsCurrPage; i++ {
  411. if this.productsCurrPage >= 5 && i > 1 && i < this.productsCurrPage-1 {
  412. continue
  413. }
  414. if this.productsCurrPage >= 5 && i > 1 && i < this.productsCurrPage {
  415. this.pagination = append(this.pagination, &ShopPagination{
  416. Dots: true,
  417. })
  418. }
  419. link := this.wrap.R.URL.Path
  420. if i > 1 {
  421. link = link + "?p=" + utils.IntToStr(i)
  422. }
  423. this.pagination = append(this.pagination, &ShopPagination{
  424. Num: utils.IntToStr(i),
  425. Link: link,
  426. Current: false,
  427. })
  428. }
  429. // Current page
  430. link := this.wrap.R.URL.Path
  431. if this.productsCurrPage > 1 {
  432. link = link + "?p=" + utils.IntToStr(this.productsCurrPage)
  433. }
  434. this.pagination = append(this.pagination, &ShopPagination{
  435. Num: utils.IntToStr(this.productsCurrPage),
  436. Link: link,
  437. Current: true,
  438. })
  439. for i := this.productsCurrPage + 1; i <= this.productsMaxPage; i++ {
  440. if this.productsCurrPage < this.productsMaxPage-3 && i == this.productsCurrPage+3 {
  441. this.pagination = append(this.pagination, &ShopPagination{
  442. Dots: true,
  443. })
  444. }
  445. if this.productsCurrPage < this.productsMaxPage-3 && i > this.productsCurrPage+1 && i <= this.productsMaxPage-1 {
  446. continue
  447. }
  448. link := this.wrap.R.URL.Path
  449. if i > 1 {
  450. link = link + "?p=" + utils.IntToStr(i)
  451. }
  452. this.pagination = append(this.pagination, &ShopPagination{
  453. Num: utils.IntToStr(i),
  454. Link: link,
  455. Current: false,
  456. })
  457. }
  458. } else {
  459. for i := 1; i <= this.productsMaxPage; i++ {
  460. link := this.wrap.R.URL.Path
  461. if i > 1 {
  462. link = link + "?p=" + utils.IntToStr(i)
  463. }
  464. this.pagination = append(this.pagination, &ShopPagination{
  465. Num: utils.IntToStr(i),
  466. Link: link,
  467. Current: i == this.productsCurrPage,
  468. })
  469. }
  470. }
  471. // Pagination prev/next
  472. if this.productsMaxPage > 1 {
  473. link := this.wrap.R.URL.Path
  474. if this.productsCurrPage-1 > 1 {
  475. link = this.wrap.R.URL.Path + "?p=" + utils.IntToStr(this.productsCurrPage-1)
  476. }
  477. this.paginationPrev = &ShopPagination{
  478. Num: utils.IntToStr(this.productsCurrPage - 1),
  479. Link: link,
  480. Current: this.productsCurrPage <= 1,
  481. }
  482. if this.productsCurrPage >= 1 && this.productsCurrPage < this.productsMaxPage {
  483. link = this.wrap.R.URL.Path + "?p=" + utils.IntToStr(this.productsCurrPage+1)
  484. } else {
  485. link = this.wrap.R.URL.Path + "?p=" + utils.IntToStr(this.productsMaxPage)
  486. }
  487. this.paginationNext = &ShopPagination{
  488. Num: utils.IntToStr(this.productsCurrPage + 1),
  489. Link: link,
  490. Current: this.productsCurrPage >= this.productsMaxPage,
  491. }
  492. }
  493. return this
  494. }
  495. func (this *Shop) preload_cats() {
  496. if (*this.wrap.Config).Modules.Enabled.Shop == 0 {
  497. return
  498. }
  499. if this.bufferCats == nil {
  500. this.bufferCats = map[int]*utils.MySql_shop_category{}
  501. if rows, err := this.wrap.DB.Query(
  502. this.wrap.R.Context(),
  503. `SELECT
  504. main.id,
  505. main.user,
  506. main.name,
  507. main.alias,
  508. main.lft,
  509. main.rgt,
  510. main.depth,
  511. parent.id AS parent_id
  512. FROM
  513. (
  514. SELECT
  515. node.id,
  516. node.user,
  517. node.name,
  518. node.alias,
  519. node.lft,
  520. node.rgt,
  521. (COUNT(parent.id) - 1) AS depth
  522. FROM
  523. fave_shop_cats AS node,
  524. fave_shop_cats AS parent
  525. WHERE
  526. node.lft BETWEEN parent.lft AND parent.rgt
  527. GROUP BY
  528. node.id
  529. ORDER BY
  530. node.lft ASC
  531. ) AS main
  532. LEFT JOIN (
  533. SELECT
  534. node.id,
  535. node.user,
  536. node.name,
  537. node.alias,
  538. node.lft,
  539. node.rgt,
  540. (COUNT(parent.id) - 0) AS depth
  541. FROM
  542. fave_shop_cats AS node,
  543. fave_shop_cats AS parent
  544. WHERE
  545. node.lft BETWEEN parent.lft AND parent.rgt
  546. GROUP BY
  547. node.id
  548. ORDER BY
  549. node.lft ASC
  550. ) AS parent ON
  551. parent.depth = main.depth AND
  552. main.lft > parent.lft AND
  553. main.rgt < parent.rgt
  554. WHERE
  555. main.id > 1
  556. ORDER BY
  557. main.lft ASC
  558. ;
  559. `); err == nil {
  560. defer rows.Close()
  561. for rows.Next() {
  562. row := utils.MySql_shop_category{}
  563. if err := rows.Scan(
  564. &row.A_id,
  565. &row.A_user,
  566. &row.A_name,
  567. &row.A_alias,
  568. &row.A_lft,
  569. &row.A_rgt,
  570. &row.A_depth,
  571. &row.A_parent,
  572. ); *this.wrap.LogCpError(&err) == nil {
  573. this.bufferCats[row.A_id] = &row
  574. if _, ok := this.bufferCats[row.A_parent]; ok {
  575. this.bufferCats[row.A_parent].A_childs = true
  576. }
  577. }
  578. }
  579. }
  580. }
  581. }
  582. func (this *Shop) Category() *ShopCategory {
  583. if this == nil {
  584. return nil
  585. }
  586. return this.category
  587. }
  588. func (this *Shop) Product() *ShopProduct {
  589. if this == nil {
  590. return nil
  591. }
  592. return this.product
  593. }
  594. func (this *Shop) HaveProducts() bool {
  595. if this == nil {
  596. return false
  597. }
  598. if len(this.products) <= 0 {
  599. return false
  600. }
  601. return true
  602. }
  603. func (this *Shop) Products() []*ShopProduct {
  604. if this == nil {
  605. return []*ShopProduct{}
  606. }
  607. return this.products
  608. }
  609. func (this *Shop) ProductsCount() int {
  610. if this == nil {
  611. return 0
  612. }
  613. return this.productsCount
  614. }
  615. func (this *Shop) ProductsPerPage() int {
  616. if this == nil {
  617. return 0
  618. }
  619. return this.productsPerPage
  620. }
  621. func (this *Shop) ProductsMaxPage() int {
  622. if this == nil {
  623. return 0
  624. }
  625. return this.productsMaxPage
  626. }
  627. func (this *Shop) ProductsCurrPage() int {
  628. if this == nil {
  629. return 0
  630. }
  631. return this.productsCurrPage
  632. }
  633. func (this *Shop) Pagination() []*ShopPagination {
  634. if this == nil {
  635. return []*ShopPagination{}
  636. }
  637. return this.pagination
  638. }
  639. func (this *Shop) PaginationPrev() *ShopPagination {
  640. if this == nil {
  641. return nil
  642. }
  643. return this.paginationPrev
  644. }
  645. func (this *Shop) PaginationNext() *ShopPagination {
  646. if this == nil {
  647. return nil
  648. }
  649. return this.paginationNext
  650. }
  651. func (this *Shop) Currencies() []*ShopCurrency {
  652. result := []*ShopCurrency{}
  653. if (*this.wrap.Config).Modules.Enabled.Shop != 0 {
  654. for _, currency := range *this.wrap.ShopGetAllCurrencies() {
  655. obj := currency
  656. result = append(result, (&ShopCurrency{wrap: this.wrap, object: &obj}).load())
  657. }
  658. sort.Slice(result, func(i, j int) bool { return result[i].Id() < result[j].Id() })
  659. }
  660. return result
  661. }
  662. func (this *Shop) CurrentCurrency() *ShopCurrency {
  663. obj := *this.wrap.ShopGetCurrentCurrency()
  664. return (&ShopCurrency{wrap: this.wrap, object: &obj}).load()
  665. }
  666. func (this *Shop) Categories(parent, depth int) []*ShopCategory {
  667. this.preload_cats()
  668. depth_tmp := 0
  669. result := []*ShopCategory{}
  670. if (*this.wrap.Config).Modules.Enabled.Shop != 0 {
  671. for _, cat := range this.bufferCats {
  672. if parent <= 1 {
  673. if depth <= 0 {
  674. result = append(result, (&ShopCategory{wrap: this.wrap, object: cat}).load(&this.bufferCats))
  675. } else {
  676. if cat.A_depth <= depth {
  677. result = append(result, (&ShopCategory{wrap: this.wrap, object: cat}).load(&this.bufferCats))
  678. }
  679. }
  680. } else {
  681. if cat.A_parent == parent {
  682. if depth_tmp == 0 {
  683. depth_tmp = cat.A_depth
  684. }
  685. if depth <= 0 {
  686. result = append(result, (&ShopCategory{wrap: this.wrap, object: cat}).load(&this.bufferCats))
  687. } else {
  688. if (cat.A_depth - depth_tmp + 1) <= depth {
  689. result = append(result, (&ShopCategory{wrap: this.wrap, object: cat}).load(&this.bufferCats))
  690. }
  691. }
  692. }
  693. }
  694. }
  695. sort.Slice(result, func(i, j int) bool { return result[i].Left() < result[j].Left() })
  696. }
  697. return result
  698. }