當前位置: 首頁>>代碼示例>>Golang>>正文


Golang store.TableWebsiteSlice類代碼示例

本文整理匯總了Golang中github.com/corestoreio/csfw/store.TableWebsiteSlice的典型用法代碼示例。如果您正苦於以下問題:Golang TableWebsiteSlice類的具體用法?Golang TableWebsiteSlice怎麽用?Golang TableWebsiteSlice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TableWebsiteSlice類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getAttributeValuesForWebsites

// getAttributeValuesForWebsites creates a map where the key is the attribute ID and
// each part of the StringEntities slice are the full attribute values for a website ID.
func getAttributeValuesForWebsites(ctx *context) map[string][]codegen.StringEntities {

	var tws store.TableWebsiteSlice
	tws.Load(ctx.dbrConn.NewSession(nil), func(sb *dbr.SelectBuilder) *dbr.SelectBuilder {
		return sb.Where("website_id > 0")
	})

	// key contains the attributeID as a string
	var aws = make(map[string][]codegen.StringEntities)
	tew, err := ctx.aat.TableEavWebsite()
	codegen.LogFatal(err)
	if tew != nil { // only for those who have a wbesite specific table
		for _, w := range tws {
			aCollection, err := codegen.LoadStringEntities(ctx.db, getAttrSelect(ctx, w.WebsiteID))
			codegen.LogFatal(err)
			for _, row := range aCollection {
				if aid, ok := row["attribute_id"]; ok {
					if nil == aws[aid] {
						aws[aid] = make([]codegen.StringEntities, 0, 200) // up to 200 websites at once
					}
					aws[aid] = append(aws[aid], row)
				} else {
					codegen.LogFatal(errgo.Newf("Column attribute_id not found in collection %#v\n", aCollection))
				}
			}
		}
	}
	return aws
}
開發者ID:bom-d-van,項目名稱:csfw,代碼行數:31,代碼來源:attributes.go

示例2: TestTableWebsiteSliceLoad

func TestTableWebsiteSliceLoad(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()
	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)
	var websites store.TableWebsiteSlice
	websites.Load(dbrSess)
	assert.True(t, websites.Len() > 2)
	for _, s := range websites {
		assert.True(t, len(s.Code.String) > 1)
	}
}
開發者ID:bom-d-van,項目名稱:csfw,代碼行數:11,代碼來源:website_test.go

示例3: TestTableWebsiteSliceLoad

func TestTableWebsiteSliceLoad(t *testing.T) {
	dbc := csdb.MustConnectTest()
	defer dbc.Close()
	dbrSess := dbc.NewSession()

	var websites store.TableWebsiteSlice
	websites.SQLSelect(dbrSess)
	assert.True(t, websites.Len() >= 2)
	for _, s := range websites {
		assert.True(t, len(s.Code.String) > 1)
	}
}
開發者ID:hafeez3000,項目名稱:csfw,代碼行數:12,代碼來源:website_test.go

示例4: TestTableWebsiteSlice

func TestTableWebsiteSlice(t *testing.T) {
	websites := store.TableWebsiteSlice{
		&store.TableWebsite{WebsiteID: 0, Code: dbr.NewNullString("admin"), Name: dbr.NewNullString("Admin"), SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NewNullBool(false)},
		&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
		nil,
		&store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)},
	}
	assert.True(t, websites.Len() == 4)

	w1, err := websites.FindByWebsiteID(999)
	assert.Nil(t, w1)
	assert.EqualError(t, store.ErrIDNotFoundTableWebsiteSlice, err.Error())

	w2, err := websites.FindByWebsiteID(2)
	assert.NotNil(t, w2)
	assert.NoError(t, err)
	assert.Equal(t, int64(2), w2.WebsiteID)

	w3, err := websites.FindByCode("euro")
	assert.NotNil(t, w3)
	assert.NoError(t, err)
	assert.Equal(t, "euro", w3.Code.String)

	w4, err := websites.FindByCode("corestore")
	assert.Nil(t, w4)
	assert.EqualError(t, store.ErrIDNotFoundTableWebsiteSlice, err.Error())

	wf1 := websites.Filter(func(w *store.TableWebsite) bool {
		return w != nil && w.WebsiteID == 1
	})
	assert.EqualValues(t, "Europe", wf1[0].Name.String)
}
開發者ID:levcom,項目名稱:csfw,代碼行數:32,代碼來源:website_test.go

示例5: TestTableWebsiteSlice

func TestTableWebsiteSlice(t *testing.T) {
	websites := store.TableWebsiteSlice{
		&store.TableWebsite{WebsiteID: 0, Code: dbr.NullString{NullString: sql.NullString{String: "admin", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Admin", Valid: true}}, SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: true}}},
		&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}},
		nil,
		&store.TableWebsite{WebsiteID: 2, Code: dbr.NullString{NullString: sql.NullString{String: "oz", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "OZ", Valid: true}}, SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: true}}},
	}
	assert.True(t, websites.Len() == 4)

	w1, err := websites.FindByID(999)
	assert.Nil(t, w1)
	assert.EqualError(t, store.ErrWebsiteNotFound, err.Error())

	w2, err := websites.FindByID(2)
	assert.NotNil(t, w2)
	assert.NoError(t, err)
	assert.Equal(t, int64(2), w2.WebsiteID)

	w3, err := websites.FindByCode("euro")
	assert.NotNil(t, w3)
	assert.NoError(t, err)
	assert.Equal(t, "euro", w3.Code.String)

	w4, err := websites.FindByCode("corestore")
	assert.Nil(t, w4)
	assert.EqualError(t, store.ErrWebsiteNotFound, err.Error())

	wf1 := websites.Filter(func(w *store.TableWebsite) bool {
		return w.WebsiteID == 1
	})
	assert.EqualValues(t, "Europe", wf1[0].Name.String)
}
開發者ID:postfix,項目名稱:csfw,代碼行數:32,代碼來源:website_test.go


注:本文中的github.com/corestoreio/csfw/store.TableWebsiteSlice類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。