|
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
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
// Set Default values |
|
15
|
|
|
private static $defaults = array( |
|
16
|
|
|
'ProductLimit' => 10 |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
public function updateCMSFields(FieldList $fields){ |
|
20
|
|
|
|
|
21
|
|
|
// set TabSet names to avoid spaces from camel case |
|
22
|
|
|
$fields->addFieldToTab('Root', new TabSet('FoxyStripe', 'FoxyStripe')); |
|
23
|
|
|
|
|
24
|
|
|
// settings tab |
|
25
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Settings', array( |
|
26
|
|
|
// Store Details |
|
27
|
|
|
HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), |
|
28
|
|
|
LiteralField::create('DetailsIntro', _t( |
|
29
|
|
|
'FoxyStripeSiteConfig.DetailsIntro', |
|
30
|
|
|
'<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">FoxyCart store settings</a>.' |
|
31
|
|
|
)), |
|
32
|
|
|
TextField::create('StoreName') |
|
33
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Sub Domain')) |
|
34
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.StoreNameDescription', 'the sub domain for your FoxyCart store')), |
|
35
|
|
|
|
|
36
|
|
|
// Advanced Settings |
|
37
|
|
|
HeaderField::create('AdvanceHeader', _t('FoxyStripeSiteConfig.AdvancedHeader', 'Advanced Settings'), 3), |
|
38
|
|
|
LiteralField::create('AdvancedIntro', _t( |
|
39
|
|
|
'FoxyStripeSiteConfig.AdvancedIntro', |
|
40
|
|
|
'<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">FoxyCart advanced store settings</a>.</p>' |
|
41
|
|
|
)), |
|
42
|
|
|
ReadonlyField::create('DataFeedLink', _t('FoxyStripeSiteConfig.DataFeedLink', 'FoxyCart DataFeed URL'), self::getDataFeedLink()) |
|
43
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.DataFeedLinkDescription', 'copy/paste to FoxyCart')), |
|
44
|
|
|
CheckboxField::create('CartValidation') |
|
45
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.CartValidation', 'Enable Cart Validation')) |
|
46
|
|
|
->setDescription(_t( |
|
47
|
|
|
'FoxyStripeSiteConfig.CartValidationDescription', |
|
48
|
|
|
'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.' |
|
49
|
|
|
)), |
|
50
|
|
|
ReadonlyField::create('StoreKey') |
|
51
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.StoreKey', 'FoxyCart API Key')) |
|
52
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.StoreKeyDescription', 'copy/paste to FoxyCart')), |
|
53
|
|
|
ReadonlyField::create('SSOLink', _t('FoxyStripeSiteConfig.SSOLink', 'Single Sign On URL'), self::getSSOLink()) |
|
54
|
|
|
->setDescription(_t('FoxyStripeSiteConfig.SSOLinkDescription', 'copy/paste to FoxyCart')) |
|
55
|
|
|
)); |
|
56
|
|
|
|
|
57
|
|
|
// configuration warning |
|
58
|
|
View Code Duplication |
if(FoxyCart::store_name_warning()!==null){ |
|
|
|
|
|
|
59
|
|
|
$fields->insertBefore(LiteralField::create( |
|
60
|
|
|
"StoreSubDomainHeaderWarning", |
|
61
|
|
|
_t( |
|
62
|
|
|
'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', |
|
63
|
|
|
"<p class=\"message error\">Store sub-domain must be entered in the <a href=\"/admin/settings/\">site settings</a></p>" |
|
64
|
|
|
) |
|
65
|
|
|
), 'StoreDetails'); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// products tab |
|
69
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Products', array( |
|
70
|
|
|
HeaderField::create('ProductHeader', _t('FoxyStripeSiteConfig.ProductHeader', 'Products'), 3), |
|
71
|
|
|
CheckboxField::create('MultiGroup') |
|
72
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups')) |
|
73
|
|
|
->setDescription(_t( |
|
74
|
|
|
'FoxyStripeSiteConfig.MultiGroupDescription', |
|
75
|
|
|
'Allows products to be shown in multiple Product Groups' |
|
76
|
|
|
)), |
|
77
|
|
|
HeaderField::create('ProductGroupHD', _t('FoxyStripeSiteConfig.ProductGroupHD', 'Product Groups'), 3), |
|
78
|
|
|
NumericField::create('ProductLimit') |
|
79
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page')) |
|
80
|
|
|
->setDescription(_t( |
|
81
|
|
|
'FoxyStripeSiteConfig.ProductLimitDescription', |
|
82
|
|
|
'Number of Products to show per page on a Product Group' |
|
83
|
|
|
)), |
|
84
|
|
|
HeaderField::create('ProductQuantityHD', _t('FoxyStripeSiteConfig.ProductQuantityHD', 'Product Form Max Quantity'), 3), |
|
85
|
|
|
NumericField::create('MaxQuantity') |
|
86
|
|
|
->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity')) |
|
87
|
|
|
->setDescription(_t( |
|
88
|
|
|
'FoxyStripeSiteConfig.MaxQuantityDescription', |
|
89
|
|
|
'Sets max quantity for product form dropdown (add to cart form - default 10)' |
|
90
|
|
|
)) |
|
91
|
|
|
)); |
|
92
|
|
|
|
|
93
|
|
|
// categories tab |
|
94
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Categories', array( |
|
95
|
|
|
HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), |
|
96
|
|
|
LiteralField::create('CategoryDescrip', _t( |
|
97
|
|
|
'FoxyStripeSiteConfig.CategoryDescrip', |
|
98
|
|
|
'<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>' |
|
99
|
|
|
)), |
|
100
|
|
|
GridField::create( |
|
101
|
|
|
'ProductCategory', |
|
102
|
|
|
_t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), |
|
103
|
|
|
ProductCategory::get(), |
|
104
|
|
|
GridFieldConfig_RecordEditor::create() |
|
105
|
|
|
) |
|
106
|
|
|
)); |
|
107
|
|
|
|
|
108
|
|
|
// option groups tab |
|
109
|
|
|
$fields->addFieldsToTab('Root.FoxyStripe.Groups', array( |
|
110
|
|
|
HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), |
|
111
|
|
|
LiteralField::create('OptionGroupsDescrip', _t( |
|
112
|
|
|
'FoxyStripeSiteConfig.OptionGroupsDescrip', |
|
113
|
|
|
'<p>Product Option Groups allow you to name a set of product options.</p>' |
|
114
|
|
|
)), |
|
115
|
|
|
GridField::create( |
|
116
|
|
|
'OptionGroup', |
|
117
|
|
|
_t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), |
|
118
|
|
|
OptionGroup::get(), |
|
119
|
|
|
GridFieldConfig_RecordEditor::create() |
|
120
|
|
|
) |
|
121
|
|
|
)); |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
private static function getSSOLink() { |
|
126
|
|
|
return Director::absoluteBaseURL()."foxystripe/sso/"; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
private static function getDataFeedLink() { |
|
130
|
|
|
return Director::absoluteBaseURL()."foxystripe/"; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
// generate key on install |
|
134
|
|
|
public function requireDefaultRecords() { |
|
135
|
|
|
|
|
136
|
|
|
parent::requireDefaultRecords(); |
|
137
|
|
|
|
|
138
|
|
|
$siteConfig = SiteConfig::current_site_config(); |
|
139
|
|
|
|
|
140
|
|
|
if(!$siteConfig->StoreKey) { |
|
141
|
|
|
$key = FoxyCart::setStoreKey(); |
|
142
|
|
|
while(!ctype_alnum($key)){ |
|
143
|
|
|
$key = FoxyCart::setStoreKey(); |
|
144
|
|
|
} |
|
145
|
|
|
$siteConfig->StoreKey = $key; |
|
146
|
|
|
$siteConfig->write(); |
|
147
|
|
|
DB::alteration_message($siteConfig->ClassName.": created FoxyCart Store Key " . $key, 'created'); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.