Browse Source

Shop, return order info + products

Vova Tkach 5 years ago
parent
commit
ca55908322
4 changed files with 52 additions and 3 deletions
  1. 12 2
      engine/basket/basket.go
  2. 28 0
      engine/basket/session.go
  3. 11 0
      modules/module_shop_order.go
  4. 1 1
      utils/mysql_basket_structs.go

+ 12 - 2
engine/basket/basket.go

@@ -152,8 +152,18 @@ func (this *Basket) ProductsCount(p *SBParam) int {
 	return 0
 }
 
-func (this *Basket) GetAll(p *SBParam) *utils.MySql_basket_order {
-	// TODO: ...
+func (this *Basket) GetAll(p *SBParam) *utils.MySql_basket {
+	if p.Host != "" && p.SessionId != "" {
+		this.Lock()
+		defer this.Unlock()
+
+		if h, ok := this.hosts[p.Host]; ok == true {
+			if s, ok := h.sessions[p.SessionId]; ok == true {
+				return s.GetAll(p)
+			}
+		}
+	}
+
 	return nil
 }
 

+ 28 - 0
engine/basket/session.go

@@ -358,3 +358,31 @@ func (this *session) ClearBasket(p *SBParam) {
 func (this *session) ProductsCount() int {
 	return this.TotalCount
 }
+
+func (this *session) GetAll(p *SBParam) *utils.MySql_basket {
+	products := []utils.MySql_basket_product{}
+	for _, product := range this.Products {
+		products = append(products, utils.MySql_basket_product{
+			A_product_id: product.Id,
+			A_price:      this.makePrice(product.price, product.currency.Id),
+			A_quantity:   product.Quantity,
+		})
+	}
+
+	currency := utils.MySql_basket_currency{
+		Id:          this.Currency.Id,
+		Name:        this.Currency.Name,
+		Coefficient: this.Currency.Coefficient,
+		Code:        this.Currency.Code,
+		Symbol:      this.Currency.Symbol,
+	}
+
+	all := utils.MySql_basket{
+		Products:   &products,
+		Currency:   &currency,
+		TotalSum:   this.totalSum,
+		TotalCount: this.TotalCount,
+	}
+
+	return &all
+}

+ 11 - 0
modules/module_shop_order.go

@@ -1,6 +1,7 @@
 package modules
 
 import (
+	"fmt"
 	"strings"
 
 	"golang-fave/engine/basket"
@@ -76,6 +77,16 @@ func (this *Modules) RegisterAction_ShopOrder() *Action {
 			}
 		}
 
+		bdata := wrap.ShopBasket.GetAll(&basket.SBParam{
+			R:         wrap.R,
+			DB:        wrap.DB,
+			Host:      wrap.CurrHost,
+			Config:    wrap.Config,
+			SessionId: wrap.GetSessionId(),
+		})
+
+		fmt.Printf("bdata: %+v\n", (*bdata))
+
 		// var lastID int64 = 0
 		// if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
 		// 	// Insert row

+ 1 - 1
utils/mysql_basket_structs.go

@@ -14,7 +14,7 @@ type MySql_basket_product struct {
 	A_quantity   int
 }
 
-type MySql_basket_order struct {
+type MySql_basket struct {
 	Products   *[]MySql_basket_product
 	Currency   *MySql_basket_currency
 	TotalSum   float64