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 TestIntCSV(t *testing.T) {
	t.Parallel()
	defer debugLogBuf.Reset()
	defer infoLogBuf.Reset()

	b := model.NewIntCSV(
		"web/cors/int_slice",
		model.WithConfigStructure(configStructure),
		model.WithSourceByInt(source.Ints{
			{2014, "Year 2014"},
			{2015, "Year 2015"},
			{2016, "Year 2016"},
			{2017, "Year 2017"},
		}),
	)

	assert.Len(t, b.Options(), 4)

	assert.Exactly(t, []int{2014, 2015, 2016}, b.Get(config.NewMockGetter().NewScoped(0, 0, 4)))
	assert.Exactly(t, "web/cors/int_slice", b.String())

	wantPath := scope.StrStores.FQPathInt64(4, "web/cors/int_slice")
	assert.Exactly(t, []int{}, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "3015,3016",
		}),
	).NewScoped(0, 0, 4)))

	assert.Contains(t, debugLogBuf.String(), "The value '3015' cannot be found within the allowed Options")
	assert.Contains(t, debugLogBuf.String(), "The value '3016' cannot be found within the allowed Options")

	assert.Exactly(t, []int{2015, 2017}, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "2015,2017",
		}),
	).NewScoped(0, 0, 4)))

	mw := &config.MockWrite{}
	b.Source.Merge(source.NewByInt(source.Ints{
		{2018, "Year 2018"},
	}))
	assert.NoError(t, b.Write(mw, []int{2016, 2017, 2018}, scope.StoreID, 4))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "2016,2017,2018", mw.ArgValue.(string))

	//t.Log("\n", debugLogBuf.String())

}