Skip to content

Commit

Permalink
added new search feature
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Jul 27, 2022
1 parent 9cb712c commit 7556bb2
Show file tree
Hide file tree
Showing 8 changed files with 1,140 additions and 958 deletions.
1,921 changes: 967 additions & 954 deletions coverage.out

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Ulbora/Level_Logger v1.0.2
github.com/Ulbora/dbinterface v1.0.5
github.com/Ulbora/dbinterface_mysql v1.0.7
github.com/Ulbora/six910-database-interface v1.2.2
github.com/Ulbora/six910-database-interface v1.2.3
)

require github.com/go-sql-driver/mysql v1.6.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/Ulbora/six910-database-interface v1.2.1 h1:wCx4DqoI+o8CPfX1+FY4+YZR9a
github.com/Ulbora/six910-database-interface v1.2.1/go.mod h1:HHC7AiKhsROflRoKg7gXL+de0ECcpaqgkhhJOtM0pQU=
github.com/Ulbora/six910-database-interface v1.2.2 h1:v7XNopLceQRYbfgGGRfeBnXhkxlc4vqF5ldmOE8hKj0=
github.com/Ulbora/six910-database-interface v1.2.2/go.mod h1:HHC7AiKhsROflRoKg7gXL+de0ECcpaqgkhhJOtM0pQU=
github.com/Ulbora/six910-database-interface v1.2.3 h1:pVG1H5WuvFgw0A4kSzs373fzV4mZpj9FmU5BmcW3M8I=
github.com/Ulbora/six910-database-interface v1.2.3/go.mod h1:HHC7AiKhsROflRoKg7gXL+de0ECcpaqgkhhJOtM0pQU=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
Expand Down
5 changes: 5 additions & 0 deletions mockDbMeths.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,11 @@ func (d *MockSix910Mysql) GetProductManufacturerListByProductName(name string, s
return d.MockManufacturerList
}

//GetProductManufacturerListByProductSearch GetProductManufacturerListByProductSearch
func (d *MockSix910Mysql) GetProductManufacturerListByProductSearch(attrs string, storeID int64) *[]string {
return d.MockManufacturerList
}

//GetProductByNameAndManufacturerName GetProductByNameAndManufacturerName
func (d *MockSix910Mysql) GetProductByNameAndManufacturerName(manf string, name string, storeID int64,
start int64, end int64) *[]mdb.Product {
Expand Down
6 changes: 6 additions & 0 deletions mockDb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,12 @@ func TestMockSix910Mysql_Mocks(t *testing.T) {
t.Fail()
}

sdb.MockManufacturerList = &[]string{"test1", "test2"}
psmanlst := si.GetProductManufacturerListByProductSearch("test", 4)
if len(*psmanlst) != 2 {
t.Fail()
}

manpdn := si.GetProductByNameAndManufacturerName("test", "tyest", 4, 0, 10)
if len(*manpdn) != 1 {
t.Fail()
Expand Down
42 changes: 40 additions & 2 deletions productSearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

// "fmt"

"strings"

"github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/six910-database-interface"
)
Expand Down Expand Up @@ -50,6 +52,37 @@ func (d *Six910Mysql) GetProductManufacturerListByProductName(name string, store
return &rtn
}

//GetProductManufacturerListByProductSearch GetProductManufacturerListByProductSearch
func (d *Six910Mysql) GetProductManufacturerListByProductSearch(attrs string, storeID int64) *[]string {
if !d.testConnection() {
d.DB.Connect()
}
var rtn = []string{}
var a []interface{}
var attrbs = strings.Split(attrs, " ")
var revind []string
var sdesc = "%"
for _, da := range attrbs {
sdesc += da + "%"
revind = append(revind, da)
}
var rsdesc = "%"
for i := len(revind) - 1; i >= 0; i-- {
rsdesc += revind[i] + "%"
}
a = append(a, sdesc, rsdesc, storeID)
rows := d.DB.GetList(getProductManufacturerListByProductSearch, a...)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
for r := range foundRows {
foundRow := foundRows[r]
manf := (foundRow)[0]
rtn = append(rtn, manf)
}
}
return &rtn
}

//GetProductByNameAndManufacturerName GetProductByNameAndManufacturerName
func (d *Six910Mysql) GetProductByNameAndManufacturerName(manf string, name string, storeID int64,
start int64, end int64) *[]mdb.Product {
Expand Down Expand Up @@ -121,13 +154,18 @@ func (d *Six910Mysql) ProductSearch(p *mdb.ProductSearch) *[]mdb.Product {
var rows *dbinterface.DbRows

if p.ProductID == 0 {
var revind []string
var sdesc = "%"
for _, da := range *(p).DescAttributes {
sdesc += da + "%"
revind = append(revind, da)
}
var rsdesc = "%"
for i := len(revind) - 1; i >= 0; i-- {
rsdesc += revind[i] + "%"
}
// fmt.Println("sdesc: ", sdesc)
var a []interface{}
a = append(a, sdesc, p.StoreID, p.Start, p.End)
a = append(a, sdesc, rsdesc, p.StoreID, p.Start, p.End)
rows = d.DB.GetList(productSearch, a...)
} else {
var a []interface{}
Expand Down
113 changes: 113 additions & 0 deletions productSearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,116 @@ func TestSix910Mysql_ProductSubSearch(t *testing.T) {

dbi.Close()
}

func TestSix910Mysql_GetProductManufacturerListByProductSearch(t *testing.T) {
var mydb mdb.MyDB
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "six910"
var dbi db.Database = &mydb

var sdb Six910Mysql
var l lg.Logger
l.LogLevel = lg.AllLevel
sdb.Log = &l
sdb.DB = dbi
dbi.Connect()

si := sdb.GetNew()

var str sdbi.Store
str.City = "test vill"
str.Company = "test com"
str.Currency = "USD"
str.Email = "[email protected]"
str.FirstName = "Tester"
str.LastName = "Bill"
str.LocalDomain = "localhost72:8080"
str.Logo = "some logo"
str.OauthClientID = 10
str.OauthSecret = "this is secret"
str.RemoteDomain = "www.someCart72.com"
str.State = "GA"
str.StoreName = "testers6 fantastic store"
str.StoreSlogan = "we test for less"
str.Zip = "30036"
str.Enabled = false
suc, sid := si.AddStore(&str)
if !suc || sid == 0 {
t.Fail()
}

var dis sdbi.Distributor
dis.Company = "abc supply"
dis.ContactName = "Ricky Bobby"
dis.Phone = "123-456-7891"
dis.StoreID = sid

dsuc, did := si.AddDistributor(&dis)
if !dsuc || did == 0 {
t.Fail()
}

var prod sdbi.Product
prod.Color = "red"
prod.Cost = 100.51
prod.Currency = "USD"
prod.Depth = 5.4
prod.Desc = "some long desc about product"
prod.DistributorID = did
prod.Dropship = false
prod.FreeShipping = true
prod.Gtin = "44555ggggg"
prod.Height = 22.3
prod.Image1 = "image1"
prod.Image2 = "image2"
prod.Image3 = "image3"
prod.Image4 = "image4"
prod.Manufacturer = "some mfg"
prod.Map = 150.99
prod.Msrp = 185.99
prod.MultiBox = false
prod.Name = "some top product that sale well"
//prod.ParentProductID
prod.Price = 170.99
prod.Promoted = true
prod.SalePrice = 160.99
prod.Searchable = true
prod.ShipSeparately = false
prod.ShippingMarkup = 3.40
prod.ShortDesc = "top product short desc"
prod.Size = "XL"
prod.Sku = "123456789"
prod.SpecialProcessing = true
prod.SpecialProcessingType = "CODE 4"
prod.Stock = 55
prod.StockAlert = 10
prod.StoreID = sid
prod.Thumbnail = "someimage"
prod.Visible = true
prod.Weight = 15.4
prod.Width = 22.4

dbi.Close()
psuc, pid := si.AddProduct(&prod)
if !psuc || pid == 0 {
t.Fail()
}

dbi.Close()
mlst := si.GetProductManufacturerListByProductSearch("top product", sid)
fmt.Println("mlst: ", mlst)
if len(*mlst) != 1 {
t.Fail()
}

dssuc := si.DeleteStore(sid)
fmt.Println("delete store in customer suc: ", dssuc)
if !dssuc {
t.Fail()
}

dbi.Close()

}
7 changes: 6 additions & 1 deletion queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ const (
" WHERE parient_product_id = 0 and name like ? and store_id = ? " +
" ORDER by manufacturer"

getProductManufacturerListByProductSearch = " SELECT DISTINCT manufacturer " +
" FROM product " +
" WHERE parient_product_id = 0 and (short_description like ? or short_description like ?) and store_id = ? " +
" ORDER by manufacturer"

//get product by manf name and name
// select *
// from product
Expand All @@ -276,7 +281,7 @@ const (
"size, color, parient_product_id, store_id, thumbnail, image1, image2, image3, " +
"image4, special_processing, special_processing_type, manufacturer_id, gender " +
"FROM product " +
"WHERE parient_product_id = 0 and short_description like ? and store_id = ? LIMIT ?, ? "
"WHERE parient_product_id = 0 and (short_description like ? or short_description like ?) and store_id = ? LIMIT ?, ? "
// short_description: '%value%value%'

subProductSearch = "SELECT id, sku, gtin, name, short_description, description, " +
Expand Down

0 comments on commit 7556bb2

Please sign in to comment.