Exemplo n.º 1
0
// 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>
}
Exemplo n.º 2
0
// 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)"},
			}))...,
		),
	}
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
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))
}