Пример #1
0
func TestGroupSliceMerge(t *testing.T) {

	tests := []struct {
		have    []*config.Group
		wantErr error
		want    string
	}{
		{
			have: []*config.Group{
				{
					ID: "b",
					Fields: config.FieldSlice{
						&config.Field{ID: "c", Default: `c`, Type: config.TypeMultiselect},
					},
				},
				{
					ID: "b",
					Fields: config.FieldSlice{
						&config.Field{ID: "d", Default: `d`, Comment: "Ring of fire", Type: config.TypeObscure},
						&config.Field{ID: "c", Default: `haha`, Type: config.TypeSelect, Scope: scope.NewPerm(scope.DefaultID, scope.WebsiteID)},
					},
				},
				{
					ID: "b",
					Fields: config.FieldSlice{
						&config.Field{ID: "d", Default: `overriddenD`, Label: "Sect2Group2Label4", Comment: "LOTR"},
						&config.Field{ID: "c", Default: `overriddenHaha`, Type: config.TypeHidden},
					},
				},
			},
			wantErr: nil,
			want:    `[{"ID":"b","Fields":[{"ID":"c","Type":"hidden","Scope":["Default","Website"],"Default":"overriddenHaha"},{"ID":"d","Type":"obscure","Label":"Sect2Group2Label4","Comment":"LOTR","Default":"overriddenD"}]}]` + "\n",
		},
		{
			have:    nil,
			wantErr: nil,
			want:    `null` + "\n",
		},
	}

	for i, test := range tests {
		var baseGsl config.GroupSlice
		haveErr := baseGsl.Merge(test.have...)
		if test.wantErr != nil {
			assert.Len(t, baseGsl, 0)
			assert.Error(t, haveErr)
			assert.Contains(t, haveErr.Error(), test.wantErr)
		} else {
			assert.NoError(t, haveErr)
			j := baseGsl.ToJSON()
			if j != test.want {
				t.Errorf("\nIndex: %d\nExpected: %s\nActual:   %s\n", i, test.want, j)
			}
		}
	}
}
Пример #2
0
			&config.Group{
				ID:        "ups",
				Label:     `UPS`,
				Comment:   ``,
				SortOrder: 100,
				Scope:     scope.PermAll,
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `carriers/ups/access_license_number`,
						ID:           "access_license_number",
						Label:        `Access License Number`,
						Comment:      ``,
						Type:         config.TypeObscure,
						SortOrder:    30,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
						Default:      nil,
						BackendModel: nil, // Magento\Config\Model\Config\Backend\Encrypted // @todo Magento\Config\Model\Config\Backend\Encrypted
						SourceModel:  nil,
					},

					&config.Field{
						// Path: `carriers/ups/active`,
						ID:           "active",
						Label:        `Enabled for Checkout`,
						Comment:      ``,
						Type:         config.TypeSelect,
						SortOrder:    10,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
						Default:      false,
Пример #3
0
						Scope:        scope.PermAll,
						Default:      16,
						BackendModel: nil,
						SourceModel:  nil,
					},
				},
			},
		},
	},

	// Hidden Configuration, may be visible somewhere else ...
	&config.Section{
		ID: "general",
		Groups: config.GroupSlice{
			&config.Group{
				ID: "validator_data",
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `general/validator_data/input_types`,
						ID:      "input_types",
						Type:    config.TypeHidden,
						Visible: config.VisibleNo,
						Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
						Default: `{"swatch_visual":"swatch_visual","swatch_text":"swatch_text"}`,
					},
				},
			},
		},
	},
)
Пример #4
0
	"github.com/corestoreio/csfw/config/scope"
)

var PackageConfiguration = config.NewConfiguration(
	&config.Section{
		ID:        "system",
		Label:     "",
		SortOrder: 0,
		Scope:     nil,
		Groups: config.GroupSlice{
			&config.Group{
				ID:        "backup",
				Label:     `Scheduled Backup Settings`,
				Comment:   ``,
				SortOrder: 500,
				Scope:     scope.NewPerm(scope.DefaultID),
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `system/backup/enabled`,
						ID:           "enabled",
						Label:        `Enable Scheduled Backup`,
						Comment:      ``,
						Type:         config.TypeSelect,
						SortOrder:    10,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(scope.DefaultID),
						Default:      nil,
						BackendModel: nil,
						SourceModel:  nil, // Magento\Config\Model\Config\Source\Yesno
					},
Пример #5
0
	"github.com/corestoreio/csfw/config/scope"
)

var PackageConfiguration = config.MustNewConfiguration(
	&config.Section{
		ID:        "sales",
		Label:     "",
		SortOrder: 0,
		Scope:     nil,
		Groups: config.GroupSlice{
			&config.Group{
				ID:        "msrp",
				Label:     `Minimum Advertised Price`,
				Comment:   ``,
				SortOrder: 110,
				Scope:     scope.NewPerm(scope.DefaultID, scope.WebsiteID),
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `sales/msrp/enabled`,
						ID:           "enabled",
						Label:        `Enable MAP`,
						Comment:      `<strong style="color:red">Warning!</strong> Enabling MAP by default will hide all product prices on Storefront.`,
						Type:         config.TypeSelect,
						SortOrder:    10,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
						Default:      false,
						BackendModel: nil,
						SourceModel:  nil, // Magento\Config\Model\Config\Source\Yesno
					},
Пример #6
0
func init() {
	PackageConfiguration = config.MustNewConfiguration(
		&config.Section{
			ID:        "general",
			Label:     "General",
			SortOrder: 10,
			Scope:     scope.PermAll,

			Groups: config.GroupSlice{
				&config.Group{
					ID:        "single_store_mode",
					Label:     `Single-Store Mode`,
					Comment:   ``,
					SortOrder: 150,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/single_store_mode/enabled`,
							ID:           "enabled",
							Label:        `Enable Single-Store Mode`,
							Comment:      `This setting will not be taken into account if system has more than one store view.`,
							Type:         config.TypeSelect,
							SortOrder:    10,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      nil,
							BackendModel: nil,
							SourceModel:  configsource.YesNo, // Magento\Config\Model\Config\Source\Yesno
						},
					},
				},

				&config.Group{
					ID:        "store_information",
					Label:     `Store Information`,
					Comment:   ``,
					SortOrder: 100,
					Scope:     scope.PermAll,
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/store_information/name`,
							ID:           "name",
							Label:        `Store Name`,
							Comment:      ``,
							Type:         config.TypeText,
							SortOrder:    10,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `general/store_information/phone`,
							ID:           "phone",
							Label:        `Store Phone Number`,
							Comment:      ``,
							Type:         config.TypeText,
							SortOrder:    20,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil,
						},
					},
				},
			},
		},

		&config.Section{
			ID:        "web",
			Label:     "Web",
			SortOrder: 20,
			Scope:     scope.PermAll,
			Groups: config.GroupSlice{
				&config.Group{
					ID:        "url",
					Label:     `Url Options`,
					Comment:   ``,
					SortOrder: 3,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `web/url/use_store`,
							ID:           "use_store",
							Label:        `Add Store Code to Urls`,
							Comment:      `<strong style="color:red">Warning!</strong> When using Store Code in URLs, in some cases system may not work properly if URLs without Store Codes are specified in the third party services (e.g. PayPal etc.).`,
							Type:         config.TypeSelect,
							SortOrder:    10,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      nil,
							BackendModel: nil,                // Magento\Config\Model\Config\Backend\Store
							SourceModel:  configsource.YesNo, // Magento\Config\Model\Config\Source\Yesno
						},

						&config.Field{
							// Path: `web/url/redirect_to_base`,
							ID:           "redirect_to_base",
							Label:        `Auto-redirect to Base URL`,
							Comment:      `I.e. redirect from http://example.com/store/ to http://www.example.com/store/`,
							Type:         config.TypeSelect,
							SortOrder:    20,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      nil,
							BackendModel: nil,
							SourceModel:  configsource.Redirect, // Magento\Config\Model\Config\Source\Web\Redirect
						},
					},
				},

				&config.Group{
					ID:        "unsecure",
					Label:     `Base URLs`,
					Comment:   `Any of the fields allow fully qualified URLs that end with '/' (slash) e.g. http://example.com/magento/`,
					SortOrder: 10,
					Scope:     scope.PermAll,
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `web/unsecure/base_url`,
							ID:           "base_url",
							Label:        `Base URL`,
							Comment:      `Specify URL or {{base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    10,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/unsecure/base_link_url`,
							ID:           "base_link_url",
							Label:        `Base Link URL`,
							Comment:      `May start with {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    20,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/unsecure/base_static_url`,
							ID:           "base_static_url",
							Label:        `Base URL for Static View Files`,
							Comment:      `May be empty or start with {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    25,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/unsecure/base_media_url`,
							ID:           "base_media_url",
							Label:        `Base URL for User Media Files`,
							Comment:      `May be empty or start with {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    40,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},
					},
				},

				&config.Group{
					ID:        "secure",
					Label:     `Base URLs (Secure)`,
					Comment:   `Any of the fields allow fully qualified URLs that end with '/' (slash) e.g. https://example.com/magento/`,
					SortOrder: 20,
					Scope:     scope.PermAll,
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `web/secure/base_url`,
							ID:           "base_url",
							Label:        `Secure Base URL`,
							Comment:      `Specify URL or {{base_url}}, or {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    10,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/secure/base_link_url`,
							ID:           "base_link_url",
							Label:        `Secure Base Link URL`,
							Comment:      `May start with {{secure_base_url}} or {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    20,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/secure/base_static_url`,
							ID:           "base_static_url",
							Label:        `Secure Base URL for Static View Files`,
							Comment:      `May be empty or start with {{secure_base_url}}, or {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    25,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/secure/base_media_url`,
							ID:           "base_media_url",
							Label:        `Secure Base URL for User Media Files`,
							Comment:      `May be empty or start with {{secure_base_url}}, or {{unsecure_base_url}} placeholder.`,
							Type:         config.TypeText,
							SortOrder:    40,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Baseurl
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `web/secure/use_in_frontend`,
							ID:           "use_in_frontend",
							Label:        `Use Secure URLs on Storefront`,
							Comment:      `Enter https protocol to use Secure URLs on Storefront.`,
							Type:         config.TypeSelect,
							SortOrder:    50,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      false,
							BackendModel: nil,                // Magento\Config\Model\Config\Backend\Secure
							SourceModel:  configsource.YesNo, // Magento\Config\Model\Config\Source\Yesno
						},

						&config.Field{
							// Path: `web/secure/use_in_adminhtml`,
							ID:           "use_in_adminhtml",
							Label:        `Use Secure URLs in Admin`,
							Comment:      `Enter https protocol to use Secure URLs in Admin.`,
							Type:         config.TypeSelect,
							SortOrder:    60,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      false,
							BackendModel: nil,                // Magento\Config\Model\Config\Backend\Secure
							SourceModel:  configsource.YesNo, // Magento\Config\Model\Config\Source\Yesno
						},

						&config.Field{
							// Path: `web/secure/offloader_header`,
							ID:           "offloader_header",
							Label:        `Offloader header`,
							Comment:      ``,
							Type:         config.TypeText,
							SortOrder:    70,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      "SSL_OFFLOADED",
							BackendModel: nil,
							SourceModel:  nil,
						},
					},
				},
			},
		},
		&config.Section{
			ID: "catalog",
			Groups: config.GroupSlice{
				&config.Group{
					ID: "price",
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `catalog/price/scope`,
							ID:      "scope",
							Default: PriceScopeGlobal,
						},
					},
				},
			},
		},
	)
}
Пример #7
0
func init() {
	PackageConfiguration = config.NewConfiguration(
		&config.Section{
			ID:        "currency",
			Label:     "Currency Setup",
			SortOrder: 60,
			Scope:     scope.PermAll,
			Groups: config.GroupSlice{
				&config.Group{
					ID:        "options",
					Label:     `Currency Options`,
					Comment:   ``,
					SortOrder: 30,
					Scope:     scope.PermAll,
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `currency/options/base`,
							ID:           "base",
							Label:        `Base Currency`,
							Comment:      `Base currency is used for all online payment transactions. If you have more than one store view, the base currency scope is defined by the catalog price scope ("Catalog" > "Price" > "Catalog Price Scope").`,
							Type:         config.TypeSelect,
							SortOrder:    1,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
							Default:      `USD`,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Currency\Base
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Locale\Currency
						},

						&config.Field{
							// Path: `currency/options/default`,
							ID:           "default",
							Label:        `Default Display Currency`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    2,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      `USD`,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Currency\DefaultCurrency
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Locale\Currency
						},

						&config.Field{
							// Path: `currency/options/allow`,
							ID:           "allow",
							Label:        `Allowed Currencies`,
							Comment:      ``,
							Type:         config.TypeMultiselect,
							SortOrder:    3,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      `USD,EUR`,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Currency\Allow
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Locale\Currency
						},
					},
				},

				&config.Group{
					ID:        "webservicex",
					Label:     `Webservicex`,
					Comment:   ``,
					SortOrder: 40,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `currency/webservicex/timeout`,
							ID:           "timeout",
							Label:        `Connection Timeout in Seconds`,
							Comment:      ``,
							Type:         config.TypeText,
							SortOrder:    0,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      100,
							BackendModel: nil,
							SourceModel:  nil,
						},
					},
				},

				&config.Group{
					ID:        "import",
					Label:     `Scheduled Import Settings`,
					Comment:   ``,
					SortOrder: 50,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `currency/import/enabled`,
							ID:           "enabled",
							Label:        `Enabled`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    1,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      false,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Yesno
						},

						&config.Field{
							// Path: `currency/import/error_email`,
							ID:           "error_email",
							Label:        `Error Email Recipient`,
							Comment:      ``,
							Type:         config.TypeText,
							SortOrder:    5,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil,
						},

						&config.Field{
							// Path: `currency/import/error_email_identity`,
							ID:           "error_email_identity",
							Label:        `Error Email Sender`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    6,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
							Default:      `general`,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Email\Identity
						},

						&config.Field{
							// Path: `currency/import/error_email_template`,
							ID:           "error_email_template",
							Label:        `Error Email Template`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    7,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID, scope.WebsiteID),
							Default:      `currency_import_error_email_template`,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Email\Template
						},

						&config.Field{
							// Path: `currency/import/frequency`,
							ID:           "frequency",
							Label:        `Frequency`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    4,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Cron\Model\Config\Source\Frequency
						},

						&config.Field{
							// Path: `currency/import/service`,
							ID:           "service",
							Label:        `Service`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    2,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil, // Magento\Config\Model\Config\Backend\Currency\Cron
							SourceModel:  nil, // Magento\Directory\Model\Currency\Import\Source\Service
						},

						&config.Field{
							// Path: `currency/import/time`,
							ID:           "time",
							Label:        `Start Time`,
							Comment:      ``,
							Type:         config.TypeTime,
							SortOrder:    3,
							Visible:      config.VisibleYes,
							Scope:        scope.PermAll,
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil,
						},
					},
				},
			},
		},
		&config.Section{
			ID: "system",
			Groups: config.GroupSlice{
				&config.Group{
					ID:        "currency",
					Label:     `Currency`,
					Comment:   ``,
					SortOrder: 50,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `system/currency/installed`,
							ID:           "installed",
							Label:        `Installed Currencies`,
							Comment:      ``,
							Type:         config.TypeMultiselect,
							SortOrder:    1,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      `AZN,AZM,AFN,ALL,DZD,AOA,ARS,AMD,AWG,AUD,BSD,BHD,BDT,BBD,BYR,BZD,BMD,BTN,BOB,BAM,BWP,BRL,GBP,BND,BGN,BUK,BIF,KHR,CAD,CVE,CZK,KYD,CLP,CNY,COP,KMF,CDF,CRC,HRK,CUP,DKK,DJF,DOP,XCD,EGP,SVC,GQE,ERN,EEK,ETB,EUR,FKP,FJD,GMD,GEK,GEL,GHS,GIP,GTQ,GNF,GYD,HTG,HNL,HKD,HUF,ISK,INR,IDR,IRR,IQD,ILS,JMD,JPY,JOD,KZT,KES,KWD,KGS,LAK,LVL,LBP,LSL,LRD,LYD,LTL,MOP,MKD,MGA,MWK,MYR,MVR,LSM,MRO,MUR,MXN,MDL,MNT,MAD,MZN,MMK,NAD,NPR,ANG,TRL,TRY,NZD,NIC,NGN,KPW,NOK,OMR,PKR,PAB,PGK,PYG,PEN,PHP,PLN,QAR,RHD,RON,ROL,RUB,RWF,SHP,STD,SAR,RSD,SCR,SLL,SGD,SKK,SBD,SOS,ZAR,KRW,LKR,SDG,SRD,SZL,SEK,CHF,SYP,TWD,TJS,TZS,THB,TOP,TTD,TND,TMM,USD,UGX,UAH,AED,UYU,UZS,VUV,VEB,VEF,VND,CHE,CHW,XOF,XPF,WST,YER,ZMK,ZWD`,
							BackendModel: nil,                    // Magento\Config\Model\Config\Backend\Locale
							SourceModel:  NewSourceCurrencyAll(), // Magento\Config\Model\Config\Source\Locale\Currency\All
						},
					},
				},
			},
		},
		&config.Section{
			ID: "general",
			Groups: config.GroupSlice{
				&config.Group{
					ID: "country",
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/country/optional_zip_countries`,
							ID:           "optional_zip_countries",
							Label:        `Zip/Postal Code is Optional for`,
							Comment:      ``,
							Type:         config.TypeMultiselect,
							SortOrder:    3,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      `HK,IE,MO,PA,GB`,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Directory\Model\Config\Source\Country
						},
					},
				},

				&config.Group{
					ID:        "region",
					Label:     `State Options`,
					Comment:   ``,
					SortOrder: 4,
					Scope:     scope.NewPerm(scope.DefaultID),
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/region/state_required`,
							ID:           "state_required",
							Label:        `State is Required for`,
							Comment:      ``,
							Type:         config.TypeMultiselect,
							SortOrder:    1,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Directory\Model\Config\Source\Country
						},

						&config.Field{
							// Path: `general/region/display_all`,
							ID:           "display_all",
							Label:        `Allow to Choose State if It is Optional for Country`,
							Comment:      ``,
							Type:         config.TypeSelect,
							SortOrder:    8,
							Visible:      config.VisibleYes,
							Scope:        scope.NewPerm(scope.DefaultID),
							Default:      nil,
							BackendModel: nil,
							SourceModel:  nil, // Magento\Config\Model\Config\Source\Yesno
						},
					},
				},
			},
		},

		// Hidden Configuration, may be visible somewhere else ...
		&config.Section{
			ID: "general",
			Groups: config.GroupSlice{
				&config.Group{
					ID: "country",
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/country/allow`,
							ID:      "allow",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `AF,AL,DZ,AS,AD,AO,AI,AQ,AG,AR,AM,AW,AU,AT,AX,AZ,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BL,BT,BO,BA,BW,BV,BR,IO,VG,BN,BG,BF,BI,KH,CM,CA,CD,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CK,CR,HR,CU,CY,CZ,DK,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,GF,PF,TF,GA,GM,GE,DE,GG,GH,GI,GR,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,HN,HK,HU,IS,IM,IN,ID,IR,IQ,IE,IL,IT,CI,JE,JM,JP,JO,KZ,KE,KI,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,ME,MF,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,FX,MX,FM,MD,MC,MN,MS,MA,MZ,MM,NA,NR,NP,NL,AN,NC,NZ,NI,NE,NG,NU,NF,KP,MP,NO,OM,PK,PW,PA,PG,PY,PE,PH,PN,PL,PS,PT,PR,QA,RE,RO,RS,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,SN,SC,SL,SG,SK,SI,SB,SO,ZA,GS,KR,ES,LK,SD,SR,SJ,SZ,SE,CH,SY,TL,TW,TJ,TZ,TH,TG,TK,TO,TT,TN,TR,TM,TC,TV,VI,UG,UA,AE,GB,US,UM,UY,UZ,VU,VA,VE,VN,WF,EH,YE,ZM,ZW`,
						},

						&config.Field{
							// Path: `general/country/default`,
							ID:      "default",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `US`,
						},
					},
				},

				&config.Group{
					ID: "locale",
					Fields: config.FieldSlice{
						&config.Field{
							// Path: `general/locale/datetime_format_long`,
							ID:      "datetime_format_long",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%A, %B %e %Y [%I:%M %p]`,
						},

						&config.Field{
							// Path: `general/locale/datetime_format_medium`,
							ID:      "datetime_format_medium",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%a, %b %e %Y [%I:%M %p]`,
						},

						&config.Field{
							// Path: `general/locale/datetime_format_short`,
							ID:      "datetime_format_short",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%m/%d/%y [%I:%M %p]`,
						},

						&config.Field{
							// Path: `general/locale/date_format_long`,
							ID:      "date_format_long",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%A, %B %e %Y`,
						},

						&config.Field{
							// Path: `general/locale/date_format_medium`,
							ID:      "date_format_medium",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%a, %b %e %Y`,
						},

						&config.Field{
							// Path: `general/locale/date_format_short`,
							ID:      "date_format_short",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `%m/%d/%y`,
						},

						&config.Field{
							// Path: `general/locale/language`,
							ID:      "language",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `en`,
						},

						&config.Field{
							// Path: `general/locale/code`,
							ID:      "code",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `en_US`,
						},

						&config.Field{
							// Path: `general/locale/timezone`,
							ID:      "timezone",
							Type:    config.TypeHidden,
							Visible: config.VisibleNo,
							Scope:   scope.NewPerm(scope.DefaultID), // @todo search for that
							Default: `America/Los_Angeles`,
						},
					},
				},
			},
		},
	)
}
Пример #8
0
	"github.com/corestoreio/csfw/config/scope"
)

var PackageConfiguration = config.NewConfiguration(
	&config.Section{
		ID:        "customer",
		Label:     "",
		SortOrder: 130,
		Scope:     scope.PermAll,
		Groups: config.GroupSlice{
			&config.Group{
				ID:        "online_customers",
				Label:     `Online Customers Options`,
				Comment:   ``,
				SortOrder: 10,
				Scope:     scope.NewPerm(config.IDScopeDefault),
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `customer/online_customers/online_minutes_interval`,
						ID:           "online_minutes_interval",
						Label:        `Online Minutes Interval`,
						Comment:      `Leave empty for default (15 minutes).`,
						Type:         config.TypeText,
						SortOrder:    1,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(config.IDScopeDefault),
						Default:      nil,
						BackendModel: nil,
						SourceModel:  nil,
					},
				},
Пример #9
0
	"github.com/corestoreio/csfw/config/scope"
)

var PackageConfiguration = config.MustNewConfiguration(
	&config.Section{
		ID:        "payment_services",
		Label:     "Payment Services",
		SortOrder: 450,
		Scope:     scope.PermAll,
		Groups: config.GroupSlice{
			&config.Group{
				ID:        "centinel",
				Label:     `3D Secure Credit Card Validation`,
				Comment:   ``,
				SortOrder: 1,
				Scope:     scope.NewPerm(config.IDScopeDefault, config.IDScopeWebsite),
				Fields: config.FieldSlice{
					&config.Field{
						// Path: `payment_services/centinel/processor_id`,
						ID:           "processor_id",
						Label:        `Processor ID`,
						Comment:      ``,
						Type:         config.TypeText,
						SortOrder:    10,
						Visible:      config.VisibleYes,
						Scope:        scope.NewPerm(config.IDScopeDefault, config.IDScopeWebsite),
						Default:      nil,
						BackendModel: nil,
						SourceModel:  nil,
					},
Пример #10
0
func TestSectionSliceMerge(t *testing.T) {

	// Got stuck in comparing JSON?
	// Use a Webservice to compare the JSON output!

	tests := []struct {
		have    []config.SectionSlice
		wantErr string
		want    string
		wantLen int
	}{
		0: {
			have: []config.SectionSlice{
				nil,
				{
					nil,
					&config.Section{
						ID: "a",
						Groups: config.GroupSlice{
							nil,
							&config.Group{
								ID: "b",
								Fields: config.FieldSlice{
									&config.Field{ID: "c", Default: `c`},
								},
							},
							&config.Group{
								ID: "b",
								Fields: config.FieldSlice{
									&config.Field{ID: "d", Default: `d`},
								},
							},
						},
					},
				},
				{
					&config.Section{ID: "a", Label: "LabelA", Groups: nil},
				},
			},
			wantErr: "",
			want:    `[{"ID":"a","Label":"LabelA","Groups":[{"ID":"b","Fields":[{"ID":"c","Default":"c"},{"ID":"d","Default":"d"}]}]}]` + "\n",
			wantLen: 2,
		},
		1: {
			have: []config.SectionSlice{
				{
					&config.Section{
						ID:    "a",
						Label: "SectionLabelA",
						Groups: config.GroupSlice{
							&config.Group{
								ID:    "b",
								Scope: scope.NewPerm(scope.DefaultID),
								Fields: config.FieldSlice{
									&config.Field{ID: "c", Default: `c`},
								},
							},
							nil,
						},
					},
				},
				{
					&config.Section{
						ID:    "a",
						Scope: scope.NewPerm(scope.DefaultID, scope.WebsiteID),
						Groups: config.GroupSlice{
							&config.Group{ID: "b", Label: "GroupLabelB1"},
							nil,
							&config.Group{ID: "b", Label: "GroupLabelB2"},
							&config.Group{
								ID: "b2",
								Fields: config.FieldSlice{
									&config.Field{ID: "d", Default: `d`},
								},
							},
						},
					},
				},
			},
			wantErr: "",
			want:    `[{"ID":"a","Label":"SectionLabelA","Scope":["Default","Website"],"Groups":[{"ID":"b","Label":"GroupLabelB2","Scope":["Default"],"Fields":[{"ID":"c","Default":"c"}]},{"ID":"b2","Fields":[{"ID":"d","Default":"d"}]}]}]` + "\n",
			wantLen: 2,
		},
		2: {
			have: []config.SectionSlice{
				{
					&config.Section{ID: "a", Label: "SectionLabelA", SortOrder: 20, Permission: 22},
				},
				{
					&config.Section{ID: "a", Scope: scope.NewPerm(scope.DefaultID, scope.WebsiteID), SortOrder: 10, Permission: 3},
				},
			},
			wantErr: "",
			want:    `[{"ID":"a","Label":"SectionLabelA","Scope":["Default","Website"],"SortOrder":10,"Permission":3,"Groups":null}]` + "\n",
		},
		3: {
			have: []config.SectionSlice{
				{
					&config.Section{
						ID:    "a",
						Label: "SectionLabelA",
						Groups: config.GroupSlice{
							&config.Group{
								ID:      "b",
								Label:   "SectionAGroupB",
								Comment: "SectionAGroupBComment",
								Scope:   scope.NewPerm(scope.DefaultID),
							},
						},
					},
				},
				{
					&config.Section{
						ID:        "a",
						SortOrder: 1000,
						Scope:     scope.NewPerm(scope.DefaultID, scope.WebsiteID),
						Groups: config.GroupSlice{
							&config.Group{ID: "b", Label: "GroupLabelB1", Scope: scope.PermAll},
							&config.Group{ID: "b", Label: "GroupLabelB2", Comment: "Section2AGroup3BComment", SortOrder: 100},
							&config.Group{ID: "b2"},
						},
					},
				},
			},
			wantErr: "",
			want:    `[{"ID":"a","Label":"SectionLabelA","Scope":["Default","Website"],"SortOrder":1000,"Groups":[{"ID":"b","Label":"GroupLabelB2","Comment":"Section2AGroup3BComment","Scope":["Default","Website","Store"],"SortOrder":100,"Fields":null},{"ID":"b2","Fields":null}]}]` + "\n",
		},
		4: {
			have: []config.SectionSlice{
				{
					&config.Section{
						ID: "a",
						Groups: config.GroupSlice{
							&config.Group{
								ID:    "b",
								Label: "b1",
								Fields: config.FieldSlice{
									&config.Field{ID: "c", Default: `c`, Type: config.TypeMultiselect, SortOrder: 1001},
								},
							},
							&config.Group{
								ID:    "b",
								Label: "b2",
								Fields: config.FieldSlice{
									nil,
									&config.Field{ID: "d", Default: `d`, Comment: "Ring of fire", Type: config.TypeObscure},
									&config.Field{ID: "c", Default: `haha`, Type: config.TypeSelect, Scope: scope.NewPerm(scope.DefaultID, scope.WebsiteID)},
								},
							},
						},
					},
				},
				{
					&config.Section{
						ID: "a",
						Groups: config.GroupSlice{
							&config.Group{
								ID:    "b",
								Label: "b3",
								Fields: config.FieldSlice{
									&config.Field{ID: "d", Default: `overriddenD`, Label: "Sect2Group2Label4", Comment: "LOTR"},
									&config.Field{ID: "c", Default: `overriddenHaha`, Type: config.TypeHidden},
								},
							},
						},
					},
				},
			},
			wantErr: "",
			want:    `[{"ID":"a","Groups":[{"ID":"b","Label":"b3","Fields":[{"ID":"c","Type":"hidden","Scope":["Default","Website"],"SortOrder":1001,"Default":"overriddenHaha"},{"ID":"d","Type":"obscure","Label":"Sect2Group2Label4","Comment":"LOTR","Default":"overriddenD"}]}]}]` + "\n",
			wantLen: 2,
		},
		5: {
			have: []config.SectionSlice{
				{
					&config.Section{
						ID: "a",
						Groups: config.GroupSlice{
							&config.Group{
								ID: "b",
								Fields: config.FieldSlice{
									&config.Field{
										ID:      "c",
										Default: `c`,
										Type:    config.TypeMultiselect,
									},
								},
							},
						},
					},
				},
				{
					nil,
					&config.Section{
						ID: "a",
						Groups: config.GroupSlice{
							&config.Group{
								ID: "b",
								Fields: config.FieldSlice{
									nil,
									&config.Field{
										ID:        "c",
										Default:   `overridenC`,
										Type:      config.TypeSelect,
										Label:     "Sect2Group2Label4",
										Comment:   "LOTR",
										SortOrder: 100,
										Visible:   config.VisibleYes,
									},
								},
							},
						},
					},
				},
			},
			wantErr: "",
			wantLen: 1,
			want:    `[{"ID":"a","Groups":[{"ID":"b","Fields":[{"ID":"c","Type":"select","Label":"Sect2Group2Label4","Comment":"LOTR","SortOrder":100,"Visible":true,"Default":"overridenC"}]}]}]` + "\n",
		},
	}

	for i, test := range tests {

		if len(test.have) == 0 {
			test.want = "null\n"
		}

		var baseSl config.SectionSlice
		haveErr := baseSl.MergeMultiple(test.have...)
		if test.wantErr != "" {
			assert.Len(t, baseSl, 0)
			assert.Error(t, haveErr)
			assert.Contains(t, haveErr.Error(), test.wantErr)
		} else {
			assert.NoError(t, haveErr)
			j := baseSl.ToJSON()
			if j != test.want {
				t.Errorf("\nIndex: %d\nExpected: %s\nActual:   %s\n", i, test.want, j)
			}
		}
		assert.Exactly(t, test.wantLen, baseSl.TotalFields(), "Index %d", i)
	}
}