expand orders
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/ordersRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/productsRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||
@@ -18,6 +20,7 @@ import (
|
||||
type OrderService struct {
|
||||
ordersRepo ordersRepo.UIOrdersRepo
|
||||
cartsRepo cartsRepo.UICartsRepo
|
||||
productsRepo productsRepo.UIProductsRepo
|
||||
addressesService *addressesService.AddressesService
|
||||
emailService *emailService.EmailService
|
||||
}
|
||||
@@ -26,6 +29,7 @@ func New() *OrderService {
|
||||
return &OrderService{
|
||||
ordersRepo: ordersRepo.New(),
|
||||
cartsRepo: cartsRepo.New(),
|
||||
productsRepo: productsRepo.New(),
|
||||
addressesService: addressesService.New(),
|
||||
emailService: emailService.NewEmailService(),
|
||||
}
|
||||
@@ -82,8 +86,10 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
|
||||
name = *cart.Name
|
||||
}
|
||||
|
||||
base_price, tax_incl, tax_excl, err := s.getOrderTotalPrice(user_id, cart_id, country_id)
|
||||
|
||||
// all checks passed
|
||||
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
|
||||
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info, base_price, tax_incl, tax_excl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -143,3 +149,27 @@ func (s *OrderService) ChangeOrderStatus(user *model.Customer, order_id uint, st
|
||||
|
||||
return s.ordersRepo.ChangeOrderStatus(order_id, status)
|
||||
}
|
||||
|
||||
func (s *OrderService) getOrderTotalPrice(user_id uint, cart_id uint, country_id uint) (float64, float64, float64, error) {
|
||||
cart, err := s.cartsRepo.RetrieveCart(user_id, cart_id)
|
||||
if err != nil {
|
||||
return 0.0, 0.0, 0.0, err
|
||||
}
|
||||
|
||||
base_price := 0.0
|
||||
tax_incl := 0.0
|
||||
tax_excl := 0.0
|
||||
|
||||
for _, product := range cart.Products {
|
||||
prices, err := s.productsRepo.GetPrice(product.ProductID, product.ProductAttributeID, constdata.SHOP_ID, user_id, country_id, product.Amount)
|
||||
if err != nil {
|
||||
return 0.0, 0.0, 0.0, err
|
||||
}
|
||||
|
||||
base_price += prices.Base
|
||||
tax_incl += prices.FinalTaxIncl
|
||||
tax_excl += prices.FinalTaxExcl
|
||||
}
|
||||
|
||||
return base_price, tax_incl, tax_excl, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user