コード例 #1
0
ファイル: models.go プロジェクト: joao-parana/csfw
// NewConfigPriceScope defines the base currency scope
// ("Currency Setup" > "Currency Options" > "Base Currency").
// can be 0 = Global or 1 = Website
// See constants PriceScopeGlobal and PriceScopeWebsite.
func NewConfigPriceScope(path string, opts ...model.Option) configPriceScope {
	return configPriceScope{
		Int: model.NewInt(path, append(opts, model.WithSourceByInt(source.Ints{
			0: {PriceScopeGlobal, "Global Scope"},
			1: {PriceScopeWebsite, "Website Scope"},
		}))...),
	}

	//<source_model>Magento\Catalog\Model\Config\Source\Price\Scope</source_model>
}
コード例 #2
0
ファイル: config_models.go プロジェクト: joao-parana/csfw
// NewConfigRedirectToBase creates a new type.
func NewConfigRedirectToBase(path string, opts ...model.Option) ConfigRedirectToBase {
	return ConfigRedirectToBase{
		Int: model.NewInt(
			path,
			append(opts, model.WithSourceByInt(source.Ints{
				0: {0, "No"},
				1: {1, "Yes (302 Found)"},                // old from Magento
				2: {http.StatusFound, "Yes (302 Found)"}, // new correct
				3: {http.StatusMovedPermanently, "Yes (301 Moved Permanently)"},
			}))...,
		),
	}
}
コード例 #3
0
ファイル: primitives_test.go プロジェクト: joao-parana/csfw
func TestRecursiveOption(t *testing.T) {
	t.Parallel()
	b := model.NewInt(
		"web/cors/int",
		model.WithConfigStructure(configStructure),
		model.WithSourceByString("a", "A", "b", "b"),
	)

	assert.Exactly(t, source.NewByString("a", "A", "b", "b"), b.Source)

	previous := b.Option(model.WithSourceByString(
		"1", "One", "2", "Two",
	))
	assert.Exactly(t, source.NewByString("1", "One", "2", "Two"), b.Source)

	b.Option(previous)
	assert.Exactly(t, source.NewByString("a", "A", "b", "b"), b.Source)
}
コード例 #4
0
ファイル: primitives_test.go プロジェクト: joao-parana/csfw
func TestInt(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrWebsites.FQPathInt64(10, "web/cors/int")
	b := model.NewInt("web/cors/int", model.WithConfigStructure(configStructure))

	assert.Empty(t, b.Options())

	assert.Exactly(t, 2015, b.Get(config.NewMockGetter().NewScoped(0, 0, 0)))

	assert.Exactly(t, 2016, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: 2016,
		}),
	).NewScoped(10, 0, 0)))

	mw := &config.MockWrite{}
	assert.NoError(t, b.Write(mw, 1, scope.WebsiteID, 10))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "1", mw.ArgValue.(string))
}