1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class FoxyStripeSiteConfig extends DataExtension{ |
4
|
|
|
|
5
|
|
|
private static $db = array( |
6
|
|
|
'StoreName' => 'Varchar(255)', |
7
|
|
|
'StoreKey' => 'Varchar(60)', |
8
|
|
|
'MultiGroup' => 'Boolean', |
9
|
|
|
'ProductLimit' => 'Int', |
10
|
|
|
'CartValidation' => 'Boolean', |
11
|
|
|
'MaxQuantity' => 'Int', |
12
|
|
|
'CustomSSL' => 'Boolean', |
13
|
|
|
'RemoteDomain' => 'Varchar(255)', |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
// Set Default values |
17
|
|
|
private static $defaults = array( |
18
|
|
|
'ProductLimit' => 10 |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
public function updateCMSFields(FieldList $fields){ |
22
|
|
|
|
23
|
|
|
// set TabSet names to avoid spaces from camel case |
24
|
|
|
$fields->addFieldToTab('Root', new TabSet('FoxyStripe', 'FoxyStripe')); |
25
|
|
|
|
26
|
|
|
// settings tab |
27
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Settings', array( |
28
|
|
|
// Store Details |
29
|
|
|
HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), |
30
|
|
|
LiteralField::create('DetailsIntro', _t( |
31
|
|
|
'FoxyStripeSiteConfig.DetailsIntro', |
32
|
|
|
'<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">FoxyCart store settings</a>.' |
33
|
|
|
)), |
34
|
|
|
CheckboxField::create('CustomSSL', 'Use custom SSL'), |
35
|
|
|
TextField::create('RemoteDomain', 'Store remote domain') |
36
|
|
|
->setDescription('custom subdomain for FoxyCart') |
37
|
|
|
->displayIf('CustomSSL')->isChecked()->end(), |
38
|
|
|
TextField::create('StoreName') |
39
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Sub Domain')) |
40
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.StoreNameDescription', 'the sub domain for your FoxyCart store')) |
41
|
|
|
->hideIf('CustomSSL')->isChecked()->end(), |
42
|
|
|
|
43
|
|
|
// Advanced Settings |
44
|
|
|
HeaderField::create('AdvanceHeader', _t('FoxyStripeSiteConfig.AdvancedHeader', 'Advanced Settings'), 3), |
45
|
|
|
LiteralField::create('AdvancedIntro', _t( |
46
|
|
|
'FoxyStripeSiteConfig.AdvancedIntro', |
47
|
|
|
'<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">FoxyCart advanced store settings</a>.</p>' |
48
|
|
|
)), |
49
|
|
|
ReadonlyField::create('DataFeedLink', _t('FoxyStripeSiteConfig.DataFeedLink', 'FoxyCart DataFeed URL'), self::getDataFeedLink()) |
50
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.DataFeedLinkDescription', 'copy/paste to FoxyCart')), |
51
|
|
|
CheckboxField::create('CartValidation') |
52
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.CartValidation', 'Enable Cart Validation')) |
53
|
|
|
->setDescription(_t( |
54
|
|
|
'FoxyStripeSiteConfig.CartValidationDescription', |
55
|
|
|
'You must <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures#use_cart_validation" target="_blank">enable cart validation</a> in the FoxyCart admin.' |
56
|
|
|
)), |
57
|
|
|
ReadonlyField::create('StoreKey') |
58
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.StoreKey', 'FoxyCart API Key')) |
59
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.StoreKeyDescription', 'copy/paste to FoxyCart')), |
60
|
|
|
ReadonlyField::create('SSOLink', _t('FoxyStripeSiteConfig.SSOLink', 'Single Sign On URL'), self::getSSOLink()) |
61
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.SSOLinkDescription', 'copy/paste to FoxyCart')) |
62
|
|
|
)); |
63
|
|
|
|
64
|
|
|
// configuration warning |
65
|
|
|
if(FoxyCart::store_name_warning()!==null){ |
66
|
|
|
$fields->insertBefore(LiteralField::create( |
67
|
|
|
"StoreSubDomainHeaderWarning", |
68
|
|
|
_t( |
69
|
|
|
'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', |
70
|
|
|
"<p class=\"message error\">Store sub-domain must be entered in the <a href=\"/admin/settings/\">site settings</a></p>" |
71
|
|
|
) |
72
|
|
|
), 'StoreDetails'); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// products tab |
76
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Products', array( |
77
|
|
|
HeaderField::create('ProductHeader', _t('FoxyStripeSiteConfig.ProductHeader', 'Products'), 3), |
78
|
|
|
CheckboxField::create('MultiGroup') |
79
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups')) |
80
|
|
|
->setDescription(_t( |
81
|
|
|
'FoxyStripeSiteConfig.MultiGroupDescription', |
82
|
|
|
'Allows products to be shown in multiple Product Groups' |
83
|
|
|
)), |
84
|
|
|
HeaderField::create('ProductGroupHD', _t('FoxyStripeSiteConfig.ProductGroupHD', 'Product Groups'), 3), |
85
|
|
|
NumericField::create('ProductLimit') |
86
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page')) |
87
|
|
|
->setDescription(_t( |
88
|
|
|
'FoxyStripeSiteConfig.ProductLimitDescription', |
89
|
|
|
'Number of Products to show per page on a Product Group' |
90
|
|
|
)), |
91
|
|
|
HeaderField::create('ProductQuantityHD', _t('FoxyStripeSiteConfig.ProductQuantityHD', 'Product Form Max Quantity'), 3), |
92
|
|
|
NumericField::create('MaxQuantity') |
93
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity')) |
94
|
|
|
->setDescription(_t( |
95
|
|
|
'FoxyStripeSiteConfig.MaxQuantityDescription', |
96
|
|
|
'Sets max quantity for product form dropdown (add to cart form - default 10)' |
97
|
|
|
)) |
98
|
|
|
)); |
99
|
|
|
|
100
|
|
|
// categories tab |
101
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Categories', array( |
102
|
|
|
HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), |
103
|
|
|
LiteralField::create('CategoryDescrip', _t( |
104
|
|
|
'FoxyStripeSiteConfig.CategoryDescrip', |
105
|
|
|
'<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be accomplished by product options alone, including category specific coupon codes, shipping and handling fees, and email receipts. <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">Learn More</a></p><p>Categories you\'ve created in FoxyStripe must also be created in your <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" target="_blank">FoxyCart Categories</a> admin panel.</p>' |
106
|
|
|
)), |
107
|
|
|
GridField::create( |
108
|
|
|
'ProductCategory', |
109
|
|
|
_t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), |
110
|
|
|
ProductCategory::get(), |
111
|
|
|
GridFieldConfig_RecordEditor::create() |
112
|
|
|
) |
113
|
|
|
)); |
114
|
|
|
|
115
|
|
|
// option groups tab |
116
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Groups', array( |
117
|
|
|
HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), |
118
|
|
|
LiteralField::create('OptionGroupsDescrip', _t( |
119
|
|
|
'FoxyStripeSiteConfig.OptionGroupsDescrip', |
120
|
|
|
'<p>Product Option Groups allow you to name a set of product options.</p>' |
121
|
|
|
)), |
122
|
|
|
GridField::create( |
123
|
|
|
'OptionGroup', |
124
|
|
|
_t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), |
125
|
|
|
OptionGroup::get(), |
126
|
|
|
GridFieldConfig_RecordEditor::create() |
127
|
|
|
) |
128
|
|
|
)); |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
private static function getSSOLink() { |
133
|
|
|
return Director::absoluteBaseURL()."foxystripe/sso/"; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
private static function getDataFeedLink() { |
137
|
|
|
return Director::absoluteBaseURL()."foxystripe/"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// generate key on install |
141
|
3 |
|
public function requireDefaultRecords() { |
142
|
|
|
|
143
|
3 |
|
parent::requireDefaultRecords(); |
144
|
|
|
|
145
|
3 |
|
$siteConfig = SiteConfig::current_site_config(); |
146
|
|
|
|
147
|
3 |
|
if(!$siteConfig->StoreKey) { |
148
|
3 |
|
$key = FoxyCart::setStoreKey(); |
149
|
3 |
|
while(!ctype_alnum($key)){ |
150
|
|
|
$key = FoxyCart::setStoreKey(); |
151
|
|
|
} |
152
|
3 |
|
$siteConfig->StoreKey = $key; |
153
|
3 |
|
$siteConfig->write(); |
154
|
3 |
|
DB::alteration_message($siteConfig->ClassName.": created FoxyCart Store Key " . $key, 'created'); |
155
|
3 |
|
} |
156
|
3 |
|
} |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: