PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.23
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.23
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / database / Seeder / AttributeSeeder.php

AttributeSeeder.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.23, at database/Seeder/AttributeSeeder.php

271 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Database\Seeder;
4
5 use FluentCart\App\Models\AttributeGroup;
6 use FluentCart\App\Models\AttributeTerm;
7
8 class AttributeSeeder
9 {
10 public static function seed()
11 {
12 if (AttributeGroup::count() > 2) {
13 return;
14 }
15
16 $groups = [
17 [
18 'title' => 'Digital Product Licensing',
19 'slug' => 'plugin-license',
20 'description' => 'Digital product license types.',
21 ],
22 [
23 'title' => 'License Period',
24 'slug' => 'plugin-license-period',
25 'description' => 'Plugin license period i.e. - annual, lifetime.',
26 ],
27 [
28 'title' => 'Cloth sizes',
29 'slug' => 'cloth-size',
30 'description' => 'Clothes sizes',
31 ],
32 [
33 'title' => 'Cloth color',
34 'slug' => 'cloth-color',
35 'description' => 'Clothes color',
36 ],
37 [
38 'title' => 'Cloth attributes',
39 'slug' => 'cloth-attributes',
40 'description' => 'Clothes logo, collar, long sleeve',
41 ],
42 ];
43
44 $attr = [
45 'plugin-license' => [
46 [
47 'serial' => 1,
48 'group_id' => 1,
49 'title' => 'Single License',
50 'slug' => 'single-license',
51 ],
52 [
53 'serial' => 2,
54 'group_id' => 1,
55 'title' => '1 Site License',
56 'slug' => '1-site-license',
57 ],
58 [
59 'serial' => 3,
60 'group_id' => 1,
61 'title' => '5 Sites License',
62 'slug' => '5-site-license',
63 ],
64 [
65 'serial' => 4,
66 'group_id' => 1,
67 'title' => '50 Sites License',
68 'slug' => '50-site-license',
69 ],
70 [
71 'serial' => 5,
72 'group_id' => 1,
73 'title' => 'Agency License',
74 'slug' => 'agency-license',
75 ],
76 [
77 'serial' => 6,
78 'group_id' => 1,
79 'title' => 'Unlimited License',
80 'slug' => 'unlimited-license',
81 ],
82 ],
83 'plugin-license-period' => [
84 [
85 'serial' => 1,
86 'group_id' => 1,
87 'title' => 'Monthly',
88 'slug' => 'monthly',
89 ],
90 [
91 'serial' => 3,
92 'group_id' => 1,
93 'title' => 'Annual',
94 'slug' => 'annual',
95 ],
96 [
97 'serial' => 4,
98 'group_id' => 1,
99 'title' => 'Lifetime',
100 'slug' => 'lifetime',
101 ],
102 ],
103 'cloth-size' => [
104 [
105 'serial' => 1,
106 'group_id' => 1,
107 'title' => 'XS',
108 'slug' => 'extra-small',
109 ],
110 [
111 'serial' => 2,
112 'group_id' => 1,
113 'title' => 'S',
114 'slug' => 'small',
115 ],
116 [
117 'serial' => 3,
118 'group_id' => 1,
119 'title' => 'M',
120 'slug' => 'medium',
121 ],
122 [
123 'serial' => 4,
124 'group_id' => 1,
125 'title' => 'L',
126 'slug' => 'large',
127 ],
128 [
129 'serial' => 5,
130 'group_id' => 1,
131 'title' => 'XL',
132 'slug' => 'extra-large',
133 ],
134 [
135 'serial' => 6,
136 'group_id' => 1,
137 'title' => 'XXL',
138 'slug' => 'extra-extra-large',
139 ],
140 [
141 'serial' => 7,
142 'group_id' => 1,
143 'title' => '3XL',
144 'slug' => 'extra-3-large',
145 ],
146 ],
147 'cloth-color' => [
148 [
149 'serial' => 1,
150 'group_id' => 1,
151 'title' => 'Red',
152 'slug' => 'red',
153 ],
154 [
155 'serial' => 2,
156 'group_id' => 1,
157 'title' => 'Green',
158 'slug' => 'green',
159 ],
160 [
161 'serial' => 3,
162 'group_id' => 1,
163 'title' => 'Yellow',
164 'slug' => 'yellow',
165 ],
166 [
167 'serial' => 4,
168 'group_id' => 1,
169 'title' => 'Grey',
170 'slug' => 'grey',
171 ],
172 [
173 'serial' => 5,
174 'group_id' => 1,
175 'title' => 'Black',
176 'slug' => 'black',
177 ],
178 [
179 'serial' => 6,
180 'group_id' => 1,
181 'title' => 'White',
182 'slug' => 'white',
183 ],
184 [
185 'serial' => 7,
186 'group_id' => 1,
187 'title' => 'Gold',
188 'slug' => 'gold',
189 ],
190 ],
191 'cloth-attributes' => [
192 [
193 'serial' => 1,
194 'group_id' => 1,
195 'title' => 'Logo',
196 'slug' => 'with-logo',
197 ],
198 [
199 'serial' => 2,
200 'group_id' => 1,
201 'title' => 'Without Logo',
202 'slug' => 'without-logo',
203 ],
204 [
205 'serial' => 3,
206 'group_id' => 1,
207 'title' => 'Collar',
208 'slug' => 'with-collar',
209 ],
210 [
211 'serial' => 4,
212 'group_id' => 1,
213 'title' => 'Long sleeve',
214 'slug' => 'long-sleeve',
215 ],
216 [
217 'serial' => 5,
218 'group_id' => 1,
219 'title' => 'Sleeveless',
220 'slug' => 'sleeveless',
221 ],
222 [
223 'serial' => 6,
224 'group_id' => 1,
225 'title' => 'Short sleeve',
226 'slug' => 'short-sleeve',
227 ],
228 [
229 'serial' => 7,
230 'group_id' => 1,
231 'title' => 'High collar',
232 'slug' => 'high-collar',
233 ],
234 ],
235 ];
236
237
238 AttributeGroup::insert($groups);
239
240 $grs = AttributeGroup::get();
241
242 if (defined('WP_CLI') && WP_CLI) {
243 $progress = \WP_CLI\Utils\make_progress_bar('%CSeeding Attributed', count($grs));
244 }
245
246 foreach ($grs as $gr) {
247 if (isset($attr[$gr->slug])) {
248
249 $tmp = [];
250
251 foreach ($attr[$gr->slug] as $item) {
252
253 $item['group_id'] = $gr->id;
254 $tmp[] = $item;
255 }
256
257 AttributeTerm::insert($tmp);
258 if (defined('WP_CLI') && WP_CLI) {
259 $progress->tick();
260 }
261 }
262 }
263 if (defined('WP_CLI') && WP_CLI) {
264 $progress->tick();
265 $progress->finish();
266 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
267 echo \WP_CLI::colorize('%n');
268 }
269 }
270 }
271