Test/Role/Fixtures.pm

filter: Statementstmt 100% 243 / 243 Branchbran 81.8% 54 / 66 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 30 / 30 Podpod 100% 5 / 5 totaltotal 96.5% 332 / 344 CC 37 SCAR 10.5
CC
37
Cov
96%
_build_taxes
5.0
_build_navigation
5.0
_build_states
4.1
CRAP 2.9
« Schema/Populate/Zone.pm ↑ Summary Schema/Result/Navigation.pm »
1 package Interchange6::Test::Role::Fixtures;
2 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Interchange6::Test::Role::Fixtures
7  
8 =cut
9  
10 3 ▶use Interchange6::Schema::Populate::CountryLocale;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Interchange6::Schema::Populate::MessageType;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Interchange6::Schema::Populate::StateLocale;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Interchange6::Schema::Populate::Zone;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Sub::Quote qw/quote_sub/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # accessors are ordered in this array based on the order in which
20 # clear_all_fixtures needs to receive them so that there are no FK issues in
21 # the database during row deletion
22  
23 3 my @accessors = qw(orders addresses shipment_rates taxes zones states
24 countries navigation price_modifiers roles inventory media products
25 attributes users message_types shipment_carriers);
26  
27 # Create all of the accessors and clearers. Builders should be defined later.
28  
29 3 foreach my $accessor (@accessors) {
30 51 has $accessor => (
31 is => 'lazy',
32 clearer => "_clear_$accessor",
33 predicate => 1,
34 );
35  
36 51 ▶ next if $accessor eq 'media'; # see below
Branch: 1 branch
BranchTrueFalseTotal
if $accessor eq "media" 3 48 51
37 48 ▶ next if $accessor eq 'orders'; # see below
Branch: 1 branch
BranchTrueFalseTotal
if $accessor eq "orders" 3 45 48
38 45 ▶ next if $accessor eq 'products'; # see below
Branch: 1 branch
BranchTrueFalseTotal
if $accessor eq "products" 3 42 45
39  
40 42 my $cref = q{
41 my $self = shift;
42 $self->$accessor->delete_all;
43 my $_clear_accessor = "_clear_$accessor";
44 $self->$_clear_accessor;
45 };
46 42 quote_sub "main::clear_$accessor", $cref, { '$accessor' => \$accessor };
47 }
48  
49 # clearing products is not so simple...
50  
51 sub clear_media {
52 2 ▶ my $self = shift;
Subroutine clear_media: called CC=1 SCAR=0.0
Pod documented
53  
54 2 my $schema = $self->ic6s_schema;
55 2 $schema->resultset('Media')->delete;
56 2 $schema->resultset('MediaDisplay')->delete;
57 2 $schema->resultset('MediaType')->delete;
58  
59 2 $self->_clear_media;
60 }
61  
62 sub clear_orders {
63 5 ▶ my $self = shift;
Subroutine clear_orders: called CC=1 SCAR=0.0
Pod documented
64 5 my $schema = $self->ic6s_schema;
65 5 $schema->resultset('OrderlinesShipping')->delete;
66 5 $schema->resultset('Shipment')->delete;
67 5 $schema->resultset('Orderline')->delete;
68 5 $schema->resultset('Order')->delete;
69 5 $self->_clear_orders;
70 }
71  
72 sub clear_products {
73 8 ▶ my $self = shift;
Subroutine clear_products: called CC=2 SCAR=6.9
Pod documented
74  
75 # find canonical products
76 8 my $rset = $self->products->search( { canonical_sku => undef } );
77 8 ▶ while ( my $product = $rset->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $product = $rset->next) 331 8 339
78 331 my $rset = $product->variants;
79  
80 # delete variants before canonical product
81 331 $product->variants->delete_all;
82 331 $product->delete;
83 }
84 8 $self->_clear_products;
85 }
86  
87 =head1 ATTRIBUTES
88  
89 Fixtures are not installed in the database until the attribute is called. This is achieved by all accessors being lazy and so builders exist for each accessor to install the fixtures on demand.
90  
91 =head2 addresses
92  
93 Depends on users, states (possibly) and countries.
94  
95 =cut
96  
97 sub _build_addresses {
98 4 ▶ my $self = shift;
Subroutine _build_addresses: called CC=3 SCAR=11.0
99 4 my $rset = $self->ic6s_schema->resultset('Address');
100  
101 4 my $user;
102  
103 # we must have users and countries before we can proceed
104 4 ▶ $self->users unless $self->has_users;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_users 0 4 4
105 4 ▶ $self->countries unless $self->has_countries;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_countries 1 3 4
106  
107 4 my $customers =
108 $self->users->search( { username => { like => 'customer%' } },
109 { order_by => 'username' } );
110  
111 4 $user = $customers->next;
112  
113 4 scalar $rset->populate(
114 [
115 [qw(users_id type address address_2 city country_iso_code)],
116 [ $user->id, 'billing', '42', 'Triq il-Kbira', 'Qormi', 'MT' ],
117 [ $user->id, 'shipping', '11', 'The Mall', 'London', 'GB' ],
118 [ $user->id, 'shipping', '143', 'Place Blanche', 'Paris', 'FR' ],
119 ]
120 );
121  
122 4 $user = $customers->next;
123  
124 4 my $state_on = $self->states->search(
125 {
126 country_iso_code => 'CA',
127 state_iso_code => 'ON'
128 },
129 { rows => 1 }
130 )->single;
131  
132 4 my $state_ny = $self->states->search(
133 {
134 country_iso_code => 'US',
135 state_iso_code => 'NY'
136 },
137 { rows => 1 }
138 )->single;
139  
140 4 scalar $rset->populate(
141 [
142 [
143 qw(users_id type address address_2 city states_id country_iso_code)
144 ],
145 [
146 $user->id, 'billing', '10', 'Yale Street',
147 'London', $state_on->id, 'CA'
148 ],
149 [
150 $user->id, 'billing', '2', 'Time Square',
151 'New York', $state_ny->id, 'US'
152 ],
153 [
154 $user->id, 'shipping', '134', 'Mill Street',
155 'Hancock', $state_ny->id, 'US'
156 ],
157 ]
158 );
159  
160 4 $user = $customers->next;
161  
162 4 scalar $rset->populate(
163 [
164 [qw(users_id type address address_2 city country_iso_code)],
165 [ $user->id, 'billing', '17', 'Allerhop', 'Wedemark', 'DE' ],
166 [ $user->id, 'shipping', '276', 'Büchel', 'Aachen', 'DE' ],
167 ]
168 );
169  
170 4 return $rset;
171 }
172  
173 =head2 countries
174  
175 Populated via L<Interchange6::Schema::Populate::CountryLocale>.
176  
177 =cut
178  
179 sub _build_countries {
180 4 ▶ my $self = shift;
Subroutine _build_countries: called CC=3 SCAR=11.0
181 4 my $rset = $self->ic6s_schema->resultset('Country');
182 4 ▶ if ( $rset->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->count == 0) 3 1 4
183 3 my $pop = Interchange6::Schema::Populate::CountryLocale->new->records;
184 3 ▶ $rset->populate($pop) or die "Failed to populate Country";
Branch: 1 branch
BranchTrueFalseTotal
$rset->populate($pop) or die "Failed to populate Country" 0 3 3
185 }
186 4 return $rset;
187 }
188  
189 =head2 roles
190  
191 =cut
192  
193 sub _build_roles {
194 4 ▶ my $self = shift;
Subroutine _build_roles: called CC=3 SCAR=11.0
195 4 my $rset = $self->ic6s_schema->resultset("Role");
196  
197 4 ▶ if ( $rset->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->count == 0) 3 1 4
198 3 my $pop = Interchange6::Schema::Populate::Role->new->records;
199 3 ▶ $rset->populate($pop) or die "Failed to populate Role";
Branch: 1 branch
BranchTrueFalseTotal
$rset->populate($pop) or die "Failed to populate Role" 0 3 3
200 }
201  
202 # Add a few additional roles
203 4 scalar $rset->populate(
204 [
205 { name => 'editor', label => 'Editor', description => 'Editor' },
206 { name => 'wholesale', label => 'Wholesale customer', description => 'Wholesale Customer.' },
207 { name => 'trade', label => 'Trade customer', description => 'Trade Customer.' },
208 ]
209 );
210 4 return $rset;
211 }
212  
213 =head2 orders
214  
215 =cut
216  
217 sub _build_orders {
218 3 ▶ my $self = shift;
Subroutine _build_orders: called CC=3 SCAR=11.0
219 3 my $schema = $self->ic6s_schema;
220  
221 # prereqs
222 3 ▶ $self->products unless $self->has_products;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_products 0 3 3
223 3 ▶ $self->addresses unless $self->has_addresses;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_addresses 0 3 3
224  
225 3 my $rset = $schema->resultset('Order');
226  
227 3 my $customer1 = $self->users->find( { username => 'customer1' } );
228  
229 3 my $billing_address =
230 $customer1->addresses->search( { type => 'billing' }, { rows => 1 } )
231 ->single;
232  
233 3 my $shipping_address =
234 $customer1->addresses->search( { type => 'shipping' }, { rows => 1 } )
235 ->single;
236  
237 3 my @orderlines = (
238 {
239 sku => 'os28112',
240 name => 'Garden Shovel',
241 description => '',
242 quantity => 1,
243 price => 13.99,
244 subtotal => 13.99,
245 },
246 {
247 sku => 'os28113',
248 name => 'The Claw Hand Rake',
249 description => '',
250 quantity => 2,
251 price => 14.99,
252 subtotal => 29.98,
253 },
254 );
255  
256 3 my $payment_order = {
257 users_id => $customer1->id,
258 amount => 56.47,
259 };
260  
261 3 $rset->create(
262 {
263 order_number => '122334',
264 order_date => DateTime->now,
265 users_id => $customer1->id,
266 email => $customer1->email,
267 shipping_addresses_id => $shipping_address->id,
268 billing_addresses_id => $billing_address->id,
269 orderlines => \@orderlines,
270 subtotal => 43.97,
271 shipping => 12.50,
272 total_cost => 56.47,
273 payment_orders => [$payment_order],
274 }
275 );
276  
277 3 my $customer2 = $self->users->find( { username => 'customer2' });
278  
279 3 $billing_address =
280 $customer2->addresses->search( { type => 'billing' }, { rows => 1 } )
281 ->single;
282  
283 3 $shipping_address =
284 $customer2->addresses->search( { type => 'shipping' }, { rows => 1 } )
285 ->single;
286  
287 3 $payment_order = {
288 users_id => $customer2->id,
289 amount => 56.47,
290 };
291  
292 3 $rset->create(
293 {
294 order_number => '122339',
295 order_date => DateTime->now,
296 users_id => $customer2->id,
297 email => $customer2->email,
298 shipping_addresses_id => $shipping_address->id,
299 billing_addresses_id => $billing_address->id,
300 orderlines => \@orderlines,
301 subtotal => 43.97,
302 shipping => 12.50,
303 total_cost => 56.47,
304 payment_orders => [$payment_order],
305 }
306 );
307  
308 3 return $rset;
309 }
310  
311 =head2 shipment_carriers
312  
313 =cut
314  
315 sub _build_shipment_carriers {
316 3 ▶ my $self = shift;
Subroutine _build_shipment_carriers: called CC=1 SCAR=0.0
317 3 my $rset = $self->ic6s_schema->resultset('ShipmentCarrier');
318  
319 3 $rset->create(
320 {
321 name => 'UPS',
322 account_number => '1U99999',
323 shipment_methods => [
324 {
325 name => '1DM',
326 title => 'Next Day Air Early AM',
327  
328 },
329 {
330 name => 'GNDRES',
331 title => 'Ground Residential',
332 }
333 ]
334 }
335 );
336 3 $rset->create(
337 {
338 name => 'KISS',
339 account_number => '1K99999',
340 shipment_methods => [
341 {
342 name => 'KISSFAST',
343 title => 'Keep it Simple and Stupid',
344 },
345 ]
346 }
347 );
348 3 return $rset;
349 }
350  
351 =head2 shipment_rates
352  
353 =cut
354  
355 sub _build_shipment_rates {
356 3 ▶ my $self = shift;
Subroutine _build_shipment_rates: called CC=3 SCAR=11.0
357 3 my $schema = $self->ic6s_schema;
358 3 my $rset = $schema->resultset('ShipmentRate');
359  
360 # prereqs
361 3 ▶ $self->shipment_carriers unless $self->has_shipment_carriers;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_shipment_carriers 1 2 3
362 3 ▶ $self->zones unless $self->has_zones;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_zones 1 2 3
363  
364 3 $rset->create(
365 {
366 zones_id => $self->zones->find( { zone => 'US lower 48' } )->id,
367 shipment_methods_id => $schema->resultset('ShipmentMethod')
368 ->search( { name => 'GNDRES' }, { rows => 1 } )->single->id,
369 min_value => 0,
370 max_value => 0,
371 value_type => 'weight',
372 value_unit => 'kg',
373 price => 9.95,
374 },
375 );
376 3 $rset->create(
377 {
378 zones_id => $self->zones->find( { zone => 'US lower 48' } )->id,
379 shipment_methods_id => $schema->resultset('ShipmentMethod')
380 ->search( { name => '1DM' }, { rows => 1 } )->single->id,
381 min_value => 0,
382 max_value => 0,
383 value_type => 'weight',
384 value_unit => 'kg',
385 price => 29.95,
386 },
387 );
388 3 return $rset;
389 }
390  
391 =head2 price_modifiers
392  
393 =cut
394  
395 sub _build_price_modifiers {
396 4 ▶ my $self = shift;
Subroutine _build_price_modifiers: called CC=3 SCAR=11.0
397 4 my $rset = $self->ic6s_schema->resultset('PriceModifier');
398  
399 # we must have roles and products before we can proceed
400 4 ▶ $self->products unless $self->has_products;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_products 2 2 4
401 4 ▶ $self->roles unless $self->has_roles;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_roles 1 3 4
402  
403 4 my $start = DateTime->new( year => 2000, month => 1, day => 1 );
404 4 my $end = DateTime->new( year => 2000, month => 12, day => 31 );
405  
406 4 my $product = $self->products->find(
407 { sku => 'G0001' });
408 4 my $role_user = $self->roles->find(
409 { name => 'user' });
410 4 my $role_trade = $self->roles->find(
411 { name => 'trade' });
412 4 my $role_wholesale = $self->roles->find(
413 { name => 'wholesale' });
414  
415 4 scalar $rset->populate(
416 [
417 [qw/sku quantity roles_id price start_date end_date/],
418 [ 'os28005', 10, undef, 8.49, undef, undef ],
419 [ 'os28005', 10, $role_user->id, 8.20, undef, undef ],
420 [ 'os28005', 20, $role_user->id, 8.00, undef, undef ],
421 [ 'os28005', 30, $role_user->id, 7.80, undef, undef ],
422 [ 'os28005', 1, $role_trade->id, 8, undef, undef ],
423 [ 'os28005', 10, $role_trade->id, 7.80, undef, undef ],
424 [ 'os28005', 20, $role_trade->id, 7.50, undef, undef ],
425 [ 'os28005', 50, $role_trade->id, 7, undef, undef ],
426 [ 'os28005', 1, $role_wholesale->id, 7, undef, undef ],
427 [ 'os28005', 10, $role_wholesale->id, 6.80, undef, undef ],
428 [ 'os28005', 20, $role_wholesale->id, 6.70, undef, undef ],
429 [ 'os28005', 50, $role_wholesale->id, 6.50, undef, undef ],
430 [ 'os28005', 200, $role_wholesale->id, 6.10, undef, undef ],
431 [ 'os28005', 1, undef, 7.50, $start, $end ],
432 [ 'os28005', 1, $role_trade->id, 6.90, $start, $end ],
433 [ 'os28006', 1, undef, 24.99, undef, undef ],
434 [ 'os28085-6', 1, undef, 34.99, undef, undef ],
435 ]
436 );
437 4 return $rset;
438 }
439  
440 =head2 products
441  
442 =cut
443  
444 sub _build_products {
445 8 ▶ my $self = shift;
Subroutine _build_products: called CC=3 SCAR=11.0
446 8 my $rset = $self->ic6s_schema->resultset('Product');
447  
448 # we must have attributes and message_types (for reviews)
449 8 ▶ $self->attributes unless $self->has_attributes;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_attributes 2 6 8
450 8 ▶ $self->message_types unless $self->has_message_types;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_message_types 2 6 8
451  
452 8 my @products = (
453 [qw(sku name short_description description price uri weight)],
454 [
455 "os28004",
456 qq(Ergo Roller),
457 qq(Ergo Roller),
458 qq(The special ergonomic design of our paint rollers has been recommended by physicians to ease the strain of repetitive movements. This unique roller design features "pores" to hold and evenly distribute more paint per wetting than any other brush.),
459 21.99,
460 "ergo-roller",
461 1
462 ],
463 [
464 "os28005",
465 qq(Trim Brush),
466 qq(Trim Brush),
467 qq(Our trim paint brushes are perfectly designed. The ergonomic look and feel will save hours of pain and the unique brush design allows paint to flow evenly and consistently.),
468 8.99,
469 "trim-brush",
470 1
471 ],
472 [
473 "os28006",
474 qq(Painters Brush Set),
475 qq(Painters Brush Set),
476 qq(This set includes 2" and 3" trim brushes and our ergonomically designer paint roller. A perfect choice for any painting project.),
477 29.99,
478 "painters-brush-set",
479 1
480 ],
481 [
482 "os28007",
483 qq(Disposable Brush Set),
484 qq(Disposable Brush Set),
485 qq(This set of disposable foam brushes is ideal for any staining project. The foam design holds the maximum amount of stain and the wood handle allows you to preview the color before you apply it. This set includes a brush for all needs. 1/2", 1", 2", 3" are included.),
486 14.99,
487 "disposable-brush-set",
488 1
489 ],
490 [
491 "os28008",
492 qq(Painters Ladder),
493 qq(Painters Ladder),
494 qq(This 6' painters ladder is perfect for getting around in almost any room. The paint tray is reinforced to hold up to a 5 gallon paint bucket. The only time you'll have to get down is to move your ladder!),
495 29.99,
496 "painters-ladder",
497 3
498 ],
499 [
500 "os28009",
501 qq(Brush Set),
502 qq(Brush Set),
503 qq(This Hand Brush set includes our carpenters hand brush and a flat handled brush for the bigger cleanups. Both brushes are made of the finest horsehair and are ideal for all surfaces.),
504 9.99,
505 "brush-set",
506 1
507 ],
508 [
509 "os28011",
510 qq(Spackling Knife),
511 qq(Spackling Knife),
512 qq(A must have for all painters! This spackling knife is ergonomically designed for ease of use and boasts a newly designed finish to allow easy clean up.),
513 14.99,
514 "spackling-knife",
515 1
516 ],
517 [
518 "os28044",
519 qq(Framing Hammer),
520 qq(Framing Hammer),
521 qq(Enjoy the perfect feel and swing of our line of hammers. This framing hammer is ideal for the most discriminating of carpenters. The handle is perfectly shaped to fit the hand and the head is weighted to get the most out of each swing.),
522 19.99,
523 "framing-hammer",
524 2
525 ],
526 [
527 "os28057a",
528 qq(16 Penny Nails),
529 qq(16 Penny Nails),
530 qq(Try our high quality 16 penny titanium nails for a lifetime of holding power. Box count about 100 nails.),
531 14.99,
532 "16-penny-nails",
533 1
534 ],
535 [
536 "os28057b",
537 qq(8 Penny Nails),
538 qq(8 Penny Nails),
539 qq(Our 8 penny nails are perfect for those hard to reach spots. Made of titanium they are guaranteed to last as long as your project. Box count about 200 nails.),
540 12.99,
541 "8-penny-nails",
542 1
543 ],
544 [
545 "os28057c",
546 qq(10 Penny Nails),
547 qq(10 Penny Nails),
548 qq(Perfect for all situations our titanium 10 Penny nails should be a part of every project. Box count about 100 nails.),
549 13.99,
550 "10-penny-nails",
551 1
552 ],
553 [
554 "os28062",
555 qq(Electricians Plier Set),
556 qq(Electricians Plier Set),
557 qq(This electricians set includes heavy duty needle-nose pliers and wire cutters. The needle-nose pliers have an extended tip making them easy to get into those hard to reach places, and the cutters are equipped with spring action so they bounce back ready for the next cut.),
558 24.99,
559 "electricians-plier-set",
560 1
561 ],
562 [
563 "os28064",
564 qq(Mechanics Wrench Set),
565 qq(Mechanics Wrench Set),
566 qq(This 5 piece set is ideal for all mechanics. Available in standard and metric sizes these tools are guaranteed to cover all of your needs.),
567 19.99,
568 "mechanics-wrench-set",
569 2
570 ],
571 [
572 "os28065",
573 qq(Mechanics Pliers),
574 qq(Mechanics Pliers),
575 qq(Our mechanics pliers are available in multiple sizes for all of your needs. From 1/4" to 3" in diameter.),
576 18.99,
577 "mechanics-pliers",
578 2
579 ],
580 [
581 "os28066",
582 qq(Big L Carpenters Square),
583 qq(Big L Carpenters Square),
584 qq(The "Big L" is a must for every carpenter. Designed for ease of use, this square is perfect for measuring and marking cuts, ensuring that you get the right cut every time!),
585 14.99,
586 "big-l-carpenters-square",
587 1
588 ],
589 [
590 "os28068a",
591 qq(Breathe Right Face Mask),
592 qq(Breathe Right Face Mask),
593 qq(The unique design of our "Breathe Right" face mask is a must for all applications. Our patented micro-fiber insures that 90% of all dust and harmful materials are filtered out before you breathe them in. EDITED),
594 5.99,
595 "breathe-right-face-mask",
596 1
597 ],
598 [
599 "os28068b",
600 qq(The Bug Eye Wear),
601 qq(The Bug Eye Wear),
602 qq(Nothing protects your vision like "The Bug". The unique design of these safety goggles is practically impenetrable and our special venting technology will make you forget you even have them on.),
603 12.00,
604 "the-bug-eye-wear",
605 1
606 ],
607 [
608 "os28069",
609 qq(Flat Top Toolbox),
610 qq(Flat Top Toolbox),
611 qq(This heavy weight tool box is perfect for any handy person. The lift out top is perfect for a carry along, and there is plenty of open space for larger tool storage.),
612 44.99,
613 "flat-top-toolbox",
614 2
615 ],
616 [
617 "os28070",
618 qq(Electricians Tool Belt),
619 qq(Electricians Tool Belt),
620 qq(This tool belt is perfectly designed for the specialized tools of the electrical trade. There is even a pocket for your voltage meter in this 100% leather belt!),
621 39.99,
622 "electricians-tool-belt",
623 1
624 ],
625 [
626 "os28072",
627 qq(Deluxe Hand Saw),
628 qq(Deluxe Hand Saw),
629 qq(Our deluxe hand saw is perfect for precision work. This saw features an ergonomic handle and carbide tipped teeth. Available in 2', 2.5', and 3' lengths.),
630 17.99,
631 "deluxe-hand-saw",
632 1
633 ],
634 [
635 "os28073",
636 qq(Mini-Sledge),
637 qq(Mini-Sledge),
638 qq(Our mini-sledge hammer is superior for smaller jobs that require a little more power. Give this one a try on landscaping stakes and concrete frames.),
639 24.99,
640 "mini-sledge",
641 3
642 ],
643 [
644 "os28074",
645 qq(Rubber Mallet),
646 qq(Rubber Mallet),
647 qq(Perfectly weighted and encased in rubber this mallet is designed for ease of use in all applications.),
648 24.99,
649 "rubber-mallet",
650 2
651 ],
652 [
653 "os28075",
654 qq(Modeling Hammer),
655 qq(Modeling Hammer),
656 qq(Ideal for the hobbiest this modeling hammer is made for the delicate work. Fits easily into small spaces and the smaller head size is perfect for intricate projects.),
657 14.99,
658 "modeling-hammer",
659 2
660 ],
661 [
662 "os28076",
663 qq(Digger Hand Trencher),
664 qq(Digger Hand Trencher),
665 qq(The "Digger" is a gardeners dream. Specially designed for moving dirt it boasts two different styles of blade. Use the one side for trenching, or use the other side with it's wider angle to get hard to handle roots out of the ground. Available in 3" size only.),
666 18.99,
667 "digger-hand-trencher",
668 1
669 ],
670 [
671 "os28077",
672 qq(Carpenter's Tool Belt),
673 qq(Carpenter's Tool Belt),
674 qq(Specially designed this tool belt comes with all of the carpenter's necessities. Made of 100% leather this tool belt boasts a hammer hockey, tape measure hockey, and cordless drill holster. Multiple pockets will allow you to eliminate those extra trips back to the tool box.),
675 39.99,
676 "carpenter-foots-tool-belt",
677 1
678 ],
679 [
680 "os28080",
681 qq(The Blade Hand Planer),
682 qq(The Blade Hand Planer),
683 qq(The perfect precision hand planer. Our patented blade technology insures that you will never have to change or sharpen the blade. Available in 1", 1.5", and 2" widths.),
684 19.99,
685 "the-blade-hand-planer",
686 1
687 ],
688 [
689 "os28081",
690 qq(Steel Wool),
691 qq(Steel Wool),
692 qq(Available in all different weights this steel wool is more durable than any other. Perfect for stain removal or smoothing hard to reach surfaces.),
693 8.99,
694 "steel-wool",
695 1
696 ],
697 [
698 "os28082",
699 qq(24" Level),
700 qq(24" Level),
701 qq(Certified accuracy, High strength, long life, Built-in rubber grips for usefulness. Easy to clean.),
702 34.99,
703 "24-inch-level",
704 1
705 ],
706 [
707 "os28084",
708 qq(Tape Measure),
709 qq(Tape Measure),
710 qq(No matter what you need to measure you are sure to find the ideal tape measure here. All of our tape measures are spring loaded for fast retraction and all lock in place for extended measuring. Available in 10', 16', 24', and 36'.),
711 19.99,
712 "tape-measure",
713 1
714 ],
715 [
716 "os28085",
717 qq(Big A A-Frame Ladder),
718 qq(Big A A-Frame Ladder),
719 qq(The "Big A" is the ideal A-Frame ladder. Available in both 6' and 12' heights you are sure to find the one that meets your needs. The treads of both sides are reinforced for climbing making placement a breeze.),
720 36.99,
721 "big-a-a-frame-ladder",
722 3
723 ],
724 [
725 "os28086",
726 qq(Folding Ruler),
727 qq(Folding Ruler),
728 qq(This 6' folding ruler is a perfect fit in almost any toolbox. Only 12" folded this measuring tool is handy and portable.),
729 12.99,
730 "folding-ruler",
731 1
732 ],
733 [
734 "os28087",
735 qq(Sanders Multi-Pac),
736 qq(Sanders Multi-Pac),
737 qq(This multi-pack of sand paper includes all levels of sand paper from a very fine grit to a very course grit. Ideal for all applications!),
738 11.99,
739 "sanders-multi-pac",
740 1
741 ],
742 [
743 "os28108",
744 qq(Hand Brush),
745 qq(Hand Brush),
746 qq(This carpenters hand brush is ideal for the small clean ups needed for precision work. Made of refined horse hair it is perfect for even the most sensitive of materials.),
747 5.99,
748 "hand-brush",
749 1
750 ],
751 [
752 "os28109",
753 qq(Mini-Spade),
754 qq(Mini-Spade),
755 qq(This mini-spade is perfect hole digging, tree planting, or trenching. The easy grip handle allows more control over thrust and direction. Available in 4' only),
756 24.99,
757 "mini-spade",
758 2
759 ],
760 [
761 "os28110",
762 qq(Mighty Mouse Tin Snips),
763 qq(Mighty Mouse Tin Snips),
764 qq(Small and ready to go these tin snips are ideal for cutting patches and vent holes. With the patented blades they are also perfect for cutting aluminum flashing. Available in 3" length only.),
765 14.99,
766 "mighty-mouse-tin-snips",
767 1
768 ],
769 [
770 "os28111",
771 qq(Hedge Shears),
772 qq(Hedge Shears),
773 qq(A perfect fit for all users these 10" hedge shears are designed to make the most out of every cut. The ergonomic handle design will allow hours of cutting time so you can tackle those really big projects. One size only),
774 19.99,
775 "hedge-shears",
776 1
777 ],
778 [
779 "os28112",
780 qq(Garden Shovel),
781 qq(Garden Shovel),
782 qq(The blade on this garden shovel is 7" inches long making it ideal for the potting enthusiast. Ergonomic design makes for ease of use with this tool.),
783 13.99,
784 "garden-shovel",
785 2
786 ],
787 [
788 "os28113",
789 qq(The Claw Hand Rake),
790 qq(The Claw Hand Rake),
791 qq(Extend the reach of your potting with "The Claw". Perfect for agitating soil in the most difficult places this 3 tine tool is ideal for every gardener. Small and Large sizes available.),
792 14.99,
793 "the-claw-hand-rake",
794 1
795 ],
796 [
797 "os29000", qq(3' Step Ladder),
798 qq(3' Step Ladder), qq(),
799 44.99, "3-foot-step-ladder",
800 0
801 ],
802 [
803 "sv13213",
804 "Painting Service",
805 "Let our professional painters do the work for you",
806 "If you don't have time for DIY then why not take advantage of our professional painting service. Fixed hourly rates for any job",
807 75,
808 "professional-painting-service",
809 0
810 ]
811 );
812  
813 8 scalar $rset->populate( [@products] );
814  
815 # sv13213 is inventory_exempt
816 8 $rset->find( { sku => "sv13213" } )->update( { inventory_exempt => 1 } );
817  
818 8 $rset->find( { sku => "os28057a" } )
819 ->add_attribute( { type => 'simple', name => 'length' }, '3.5 inches' );
820  
821 8 $rset->find( { sku => "os28057b" } )
822 ->add_attribute( { type => 'simple', name => 'length' }, '2.5 inches' );
823  
824 8 $rset->find( { sku => "os28057c" } )
825 ->add_attribute( { type => 'simple', name => 'length' }, '3.0 inches' );
826  
827 8 $rset->find( { sku => "os28057a" } )
828 ->add_attribute( { type => 'simple', name => 'box_quantity' }, '100' );
829  
830 8 $rset->find( { sku => "os28057b" } )
831 ->add_attribute( { type => 'simple', name => 'box_quantity' }, '200' );
832  
833 8 $rset->find( { sku => "os28057c" } )
834 ->add_attribute( { type => 'simple', name => 'box_quantity' }, '100' );
835  
836 8 $rset->find( { sku => "os28085" } )->add_variants(
837 {
838 sku => 'os28085-6',
839 price => 36.99,
840 uri => 'big-a-a-frame-ladder-6-foot-high',
841 height => '6 foot',
842 },
843 {
844 sku => 'os28085-12',
845 price => 54.99,
846 uri => 'big-a-a-frame-ladder-12-foot-high',
847 height => '12 foot',
848 },
849 );
850 8 $rset->find( { sku => "os28080" } )->add_variants(
851 {
852 sku => 'os28080-1',
853 price => 19.99,
854 uri => 'the-blade-hand-planer-one-inch-wide',
855 width => '1.0 inch',
856 },
857 {
858 sku => 'os28080-1HLF',
859 price => 20.99,
860 uri => 'the-blade-hand-planer-one-and-a-half-inches-wide',
861 width => '1.5 inch',
862 },
863 {
864 sku => 'os28080-2',
865 price => 21.99,
866 uri => 'the-blade-hand-planer-two-inches-wide',
867 width => '2.0 inch',
868 },
869 );
870 8 $rset->find( { sku => "os28072" } )->add_variants(
871 {
872 sku => 'os28072-2',
873 price => 16.99,
874 uri => 'deluxe-hand-saw-two-foot',
875 length => '2 foot',
876 },
877 {
878 sku => 'os28072-2HLF',
879 price => 17.99,
880 uri => 'deluxe-hand-saw-two-and-a-half-foot',
881 length => '2.5 foot',
882 },
883 {
884 sku => 'os28072-3',
885 price => 18.99,
886 uri => 'deluxe-hand-saw-three-foot',
887 length => '3 foot',
888 },
889 );
890 8 $rset->find( { sku => "os28065" } )->add_variants(
891 {
892 diameter => '1/4 inch',
893 sku => 'os28065-QTR',
894 uri => 'mechanics-pliers-quarter-inch-diameter',
895 },
896 {
897 diameter => '1/2 inch',
898 sku => 'os28065-HLF',
899 uri => 'mechanics-pliers-half-inch-diameter',
900 },
901 {
902 diameter => '1 inch',
903 sku => 'os28065-1',
904 uri => 'mechanics-pliers-1-inch-diameter',
905 },
906 {
907 diameter => '2 inches',
908 sku => 'os28065-2',
909 uri => 'mechanics-pliers-2-inch-diameter',
910 },
911 {
912 diameter => '3 inches',
913 sku => 'os28065-3',
914 uri => 'mechanics-pliers-3-inch-diameter',
915 },
916 );
917 8 $rset->find( { sku => "os28084" } )->add_variants(
918 {
919 length => '10 foot',
920 sku => 'os28084-10',
921 uri => 'tape-measure-10-foot-long',
922 price => 10.99,
923 },
924 {
925 length => '16 foot',
926 sku => 'os28084-16',
927 uri => 'tape-measure-16-foot-long',
928 price => 12.99,
929 },
930 {
931 length => '24 foot',
932 sku => 'os28084-24',
933 uri => 'tape-measure-24-foot-long',
934 price => 15.99,
935 },
936 {
937 length => '36 foot',
938 sku => 'os28084-36',
939 uri => 'tape-measure-36-foot-long',
940 price => 19.99,
941 },
942 );
943 8 $rset->find( { sku => "os28004" } )->add_variants(
944 {
945 roller => 'camel',
946 color => 'black',
947 sku => 'os28004-CAM-BLK',
948 uri => 'ergo-roller-camel-hair-black',
949 price => 16,
950 },
951 {
952 roller => 'camel',
953 color => 'white',
954 sku => 'os28004-CAM-WHT',
955 uri => 'ergo-roller-camel-hair-white',
956 price => 16,
957 },
958 {
959 roller => 'human',
960 color => 'black',
961 sku => 'os28004-HUM-BLK',
962 uri => 'ergo-roller-human-hair-black',
963 price => 16.5,
964 },
965 {
966 roller => 'human',
967 color => 'white',
968 sku => 'os28004-HUM-WHT',
969 uri => 'ergo-roller-human-hair-white',
970 price => 16.5,
971 },
972 {
973 roller => 'synthetic',
974 color => 'black',
975 sku => 'os28004-SYN-BLK',
976 uri => 'ergo-roller-synthetic-black',
977 price => 12.25,
978 },
979 {
980 roller => 'synthetic',
981 color => 'white',
982 sku => 'os28004-SYN-WHT',
983 uri => 'ergo-roller-synthetic-white',
984 price => 12.25,
985 },
986 );
987  
988 8 $rset->find( { sku => "os28066" } )->add_variants(
989 {
990 handle => 'ebony',
991 blade => 'plastic',
992 sku => 'os28066-E-P',
993 uri => 'big-l-carpenters-square-ebony-handle-plastic-blade',
994 price => 32.55,
995 },
996 {
997 handle => 'ebony',
998 blade => 'steel',
999 sku => 'os28066-E-S',
1000 uri => 'big-l-carpenters-square-ebony-handle-steel-blade',
1001 price => 33.99,
1002 },
1003 {
1004 handle => 'ebony',
1005 blade => 'titanium',
1006 sku => 'os28066-E-T',
1007 uri => 'big-l-carpenters-square-ebony-handle-titanium-blade',
1008 price => 133.99,
1009 },
1010 {
1011 handle => 'wood',
1012 blade => 'plastic',
1013 sku => 'os28066-W-P',
1014 uri => 'big-l-carpenters-square-wood-handle-plastic-blade',
1015 price => 12.55,
1016 },
1017 {
1018 handle => 'wood',
1019 blade => 'steel',
1020 sku => 'os28066-W-S',
1021 uri => 'big-l-carpenters-square-wood-handle-steel-blade',
1022 price => 11.99,
1023 },
1024 {
1025 handle => 'wood',
1026 blade => 'titanium',
1027 sku => 'os28066-W-T',
1028 uri => 'big-l-carpenters-square-wood-handle-titanium-blade',
1029 price => 113.99,
1030 },
1031 );
1032  
1033 # add some reviews
1034  
1035 8 my $product = $rset->find('os28066');
1036 8 my $customer1 =
1037 $self->users->search( { username => 'customer1' }, { rows => 1 } )
1038 ->single;
1039  
1040 8 $product->set_reviews(
1041 {
1042 title => "fantastic",
1043 content => "really amazing",
1044 rating => 5,
1045 author_users_id => $customer1->id,
1046 public => 1,
1047 approved => 1,
1048 },
1049 {
1050 title => "great",
1051 content => "there is so much I wan to say",
1052 rating => 4.8,
1053 author_users_id => $customer1->id,
1054 public => 1,
1055 approved => 1,
1056 },
1057 {
1058 title => "brilliant",
1059 content => "let me carp on about this great product",
1060 rating => 4.7,
1061 author_users_id => $customer1->id,
1062 public => 1,
1063 approved => 1,
1064 },
1065 {
1066 title => "fantastic",
1067 content => "public but not approved",
1068 rating => 4,
1069 author_users_id => $customer1->id,
1070 public => 1,
1071 approved => 0,
1072 },
1073 {
1074 title => "fantastic",
1075 content => "approved but not public",
1076 rating => 4,
1077 author_users_id => $customer1->id,
1078 public => 0,
1079 approved => 1,
1080 },
1081 {
1082 title => "really good",
1083 content => "does what it says on the tin",
1084 rating => 4.3,
1085 author_users_id => $customer1->id,
1086 public => 1,
1087 approved => 1,
1088 },
1089 {
1090 title => "amazing",
1091 content => "so good I bought one for my dad",
1092 rating => 3.8,
1093 author_users_id => $customer1->id,
1094 public => 1,
1095 approved => 1,
1096 },
1097 {
1098 title => "not bad",
1099 content => "better available on the market but not at this price",
1100 rating => 3,
1101 author_users_id => $customer1->id,
1102 public => 1,
1103 approved => 1,
1104 },
1105 {
1106 title => "total junk",
1107 content => "product is completely worthless",
1108 rating => 0,
1109 author_users_id => $customer1->id,
1110 public => 0,
1111 approved => 0,
1112 },
1113 );
1114  
1115 8 return $rset;
1116 }
1117  
1118 =head2 attributes
1119  
1120 Colours, sizes and heights for products.
1121  
1122 FIXME: attributes for other things to be added?
1123  
1124 =cut
1125  
1126 sub _build_attributes {
1127 4 ▶ my $self = shift;
Subroutine _build_attributes: called CC=1 SCAR=0.0
1128 4 my $rset = $self->ic6s_schema->resultset('Attribute');
1129  
1130 # generic product attributes
1131 4 $rset->create(
1132 {
1133 name => 'box_quantity',
1134 title => 'Qty in box',
1135 type => 'simple',
1136 attribute_values => [
1137 { value => '100', title => '100' },
1138 { value => '200', title => '200' },
1139 ]
1140 }
1141 );
1142 4 $rset->create(
1143 {
1144 name => 'length',
1145 title => 'Length',
1146 type => 'simple',
1147 attribute_values => [
1148 { value => '2.5 inches', title => q(2½") },
1149 { value => '3.0 inches', title => q(3") },
1150 { value => '3.5 inches', title => q(3½") },
1151 ]
1152 }
1153 );
1154  
1155 # variants
1156 4 $rset->create(
1157 {
1158 name => 'width',
1159 title => 'Width',
1160 type => 'variant',
1161 priority => 1,
1162 attribute_values => [
1163 { priority => 40, value => '1.0 inch', title => q(1") },
1164 { priority => 30, value => '1.5 inch', title => q(1.5") },
1165 { priority => 20, value => '2.0 inch', title => q(2") },
1166 ]
1167 }
1168 );
1169 4 $rset->create(
1170 {
1171 name => 'diameter',
1172 title => 'Diameter',
1173 type => 'variant',
1174 priority => 1,
1175 attribute_values => [
1176 { priority => 80, value => '1/4 inch', title => q(1/4") },
1177 { priority => 70, value => '1/2 inch', title => q(1/2") },
1178 { priority => 60, value => '1 inch', title => q(1") },
1179 { priority => 50, value => '2 inches', title => q(2") },
1180 { priority => 40, value => '3 inches', title => q(3") },
1181 ]
1182 }
1183 );
1184 4 $rset->create(
1185 {
1186 name => 'height',
1187 title => 'Height',
1188 type => 'variant',
1189 priority => 2,
1190 attribute_values => [
1191 { priority => 800, value => '2 foot', title => "2'" },
1192 { priority => 750, value => '2.5 foot', title => "2.5'" },
1193 { priority => 700, value => '3 foot', title => "3'" },
1194 { priority => 650, value => '6 foot', title => "6'" },
1195 { priority => 600, value => '10 foot', title => "10'" },
1196 { priority => 550, value => '12 foot', title => "12'" },
1197 { priority => 500, value => '16 foot', title => "16'" },
1198 { priority => 450, value => '24 foot', title => "24'" },
1199 { priority => 400, value => '36 foot', title => "36'" },
1200 ]
1201 }
1202 );
1203 4 $rset->create(
1204 {
1205 name => 'length',
1206 title => 'Length',
1207 type => 'variant',
1208 priority => 1,
1209 attribute_values => [
1210 { priority => 80, value => '2 foot', title => "2'" },
1211 { priority => 85, value => '2.5 foot', title => "2.5'" },
1212 { priority => 80, value => '3 foot', title => "3'" },
1213 { priority => 75, value => '10 foot', title => "10'" },
1214 { priority => 70, value => '16 foot', title => "16'" },
1215 { priority => 65, value => '24 foot', title => "24'" },
1216 { priority => 60, value => '36 foot', title => "36'" },
1217 ]
1218 }
1219 );
1220 4 $rset->create(
1221 {
1222 name => 'color',
1223 title => 'Color',
1224 type => 'variant',
1225 priority => 1,
1226 attribute_values => [
1227 { value => 'black', title => 'Black' },
1228 { value => 'white', title => 'White' },
1229 ]
1230 }
1231 );
1232 4 $rset->create(
1233 {
1234 name => 'roller',
1235 title => 'Roller',
1236 type => 'variant',
1237 priority => 2,
1238 attribute_values => [
1239 { value => 'camel', title => 'Camel hair' },
1240 { value => 'human', title => 'Human hair' },
1241 { value => 'synthetic', title => 'Synthetic' },
1242 ]
1243 }
1244 );
1245 4 $rset->create(
1246 {
1247 name => 'handle',
1248 title => 'Handle',
1249 type => 'variant',
1250 priority => 2,
1251 attribute_values => [
1252 { value => 'ebony', title => 'Ebony' },
1253 { value => 'wood', title => 'Wood' },
1254 ]
1255 }
1256 );
1257 4 $rset->create(
1258 {
1259 name => 'blade',
1260 title => 'Blade',
1261 type => 'variant',
1262 priority => 1,
1263 attribute_values => [
1264 { value => 'plastic', title => 'Plastic' },
1265 { value => 'steel', title => 'Steel' },
1266 { value => 'titanium', title => 'Titanium' },
1267 ]
1268 }
1269 );
1270  
1271 4 return $rset;
1272 }
1273  
1274 =head2 inventory
1275  
1276 =cut
1277  
1278 sub _build_inventory {
1279 3 ▶ my $self = shift;
Subroutine _build_inventory: called CC=2 SCAR=7.0
1280 3 my $rset = $self->ic6s_schema->resultset('Inventory');
1281  
1282 # we must have products before we can proceed
1283 3 ▶ $self->products unless $self->has_products;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_products 0 3 3
1284  
1285 3 my @inventory = (
1286 [qw(sku quantity )],
1287 [ "os28004-CAM-BLK", 34, ],
1288 [ "os28004-CAM-WHT", 27, ],
1289 [ "os28004-HUM-BLK", 19, ],
1290 [ "os28004-HUM-WHT", 131, ],
1291 [ "os28004-SYN-BLK", 0, ],
1292 [ "os28004-SYN-WHT", 42, ],
1293 [ "os28005", 100, ],
1294 [ "os28006", 90, ],
1295 [ "os28007", 85, ],
1296 [ "os28008", 100, ],
1297 [ "os28009", 0, ],
1298 [ "os28011", 40, ],
1299 [ "os28044", 3, ],
1300 [ "os28057a", 100, ],
1301 [ "os28057b", 29, ],
1302 [ "os28057c", 50, ],
1303 [ "os28062", 88, ],
1304 [ "os28064", 94, ],
1305 [ 'os28065-QTR', 103, ],
1306 [ 'os28065-HLF', 87, ],
1307 [ 'os28065-1', 3, ],
1308 [ 'os28065-2', 0, ],
1309 [ 'os28065-3', 49, ],
1310 [ "os28066-E-P", 98, ],
1311 [ "os28066-E-S", 67, ],
1312 [ "os28066-E-T", 42, ],
1313 [ "os28066-W-P", 103, ],
1314 [ "os28066-W-S", 7, ],
1315 # os28066-W-T intentionally not added to inventory
1316 [ "os28068a", 100, ],
1317 [ "os28068b", 99, ],
1318 [ "os28069", 100, ],
1319 [ "os28070", 0, ],
1320 [ 'os28072-2', 19, ],
1321 [ 'os28072-2HLF', 47, ],
1322 [ 'os28072-3', 23, ],
1323 [ "os28073", 0, ],
1324 [ "os28074", 95, ],
1325 [ "os28075", 100, ],
1326 [ "os28076", 100, ],
1327 [ "os28077", 97, ],
1328 [ 'os28080-1', 67, ],
1329 [ 'os28080-1HLF', 32, ],
1330 [ 'os28080-2', 145, ],
1331 [ "os28081", 100, ],
1332 [ "os28082", 99, ],
1333 [ "os28084-10", 56, ],
1334 [ "os28084-16", 9, ],
1335 [ "os28084-24", 0, ],
1336 [ "os28084-36", 45, ],
1337 [ 'os28085-6', 3, ],
1338 [ 'os28085-12', 0, ],
1339 [ "os28086", 100, ],
1340 [ "os28087", 30, ],
1341 [ "os28108", 90, ],
1342 [ "os28109", 100, ],
1343 [ "os28110", 99, ],
1344 [ "os28111", 99, ],
1345 [ "os28112", 100, ],
1346 [ "os28113", 100, ],
1347 # os29000 intentionally not added to inventory
1348 );
1349  
1350 3 scalar $rset->populate( [@inventory] );
1351  
1352 3 return $rset;
1353 }
1354  
1355 =head2 media
1356  
1357 =cut
1358  
1359 sub _build_media {
1360 2 ▶ my $self = shift;
Subroutine _build_media: called CC=3 SCAR=11.0
1361 2 my $schema = $self->ic6s_schema;
1362  
1363 2 my $imagetype =
1364 $schema->resultset('MediaType')->create( { type => 'image' } );
1365  
1366 2 foreach my $display (qw/image_detail image_thumb/) {
1367 4 $imagetype->add_to_media_displays(
1368 {
1369 type => $display,
1370 name => $display,
1371 path => "/images/$display",
1372 }
1373 );
1374 }
1375  
1376 2 my $products = $self->products;
1377 2 ▶ while ( my $product = $products->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $product = $products->next) 138 2 140
1378 138 $product->add_to_media(
1379 {
1380 file => $product->sku . ".gif",
1381 uri => $product->sku . ".gif",
1382 mime_type => 'image/gif',
1383 media_type => { type => 'image' }
1384 }
1385 );
1386 }
1387  
1388 2 return $schema->resultset('Media');
1389 }
1390  
1391 =head2 message_types
1392  
1393 Populated via L<Interchange6::Schema::Populate::MessageType>.
1394  
1395 =cut
1396  
1397 sub _build_message_types {
1398 3 ▶ my $self = shift;
Subroutine _build_message_types: called CC=3 SCAR=11.0
1399 3 my $rset = $self->ic6s_schema->resultset('MessageType');
1400  
1401 3 ▶ if ( $rset->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->count == 0) 2 1 3
1402 2 my $pop = Interchange6::Schema::Populate::MessageType->new->records;
1403 2 ▶ scalar $rset->populate($pop)
Branch: 1 branch
BranchTrueFalseTotal
scalar $rset->populate($pop) or die "Failed to populate MessageType" 0 2 2
1404 or die "Failed to populate MessageType";
1405 }
1406 3 return $rset;
1407 }
1408  
1409 =head2 navigation
1410  
1411 =cut
1412  
1413 sub _build_navigation {
1414 4 ▶ my $self = shift;
Subroutine _build_navigation: called CC=5 SCAR=16.1
1415 4 my $rset = $self->ic6s_schema->resultset('Navigation');
1416  
1417 # we must have products before we can proceed
1418 4 ▶ $self->products unless $self->has_products;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_products 1 3 4
1419  
1420 4 scalar $rset->populate(
1421 [
1422 [ 'uri', 'type', 'scope', 'name', 'priority' ],
1423 [ 'hand-tools', 'nav', 'menu-main', 'Hand Tools', 90 ],
1424 [ 'hardware', 'nav', 'menu-main', 'Hardware', 80 ],
1425 [ 'ladders', 'nav', 'menu-main', 'Ladders', 70 ],
1426 [ 'measuring-tools', 'nav', 'menu-main', 'Measuring Tools', 60 ],
1427 [
1428 'painting-supplies', 'nav', 'menu-main', 'Painting Supplies',
1429 50
1430 ],
1431 [ 'safety-equipment', 'nav', 'menu-main', 'Safety Equipment', 40 ],
1432 [ 'tool-storage', 'nav', 'menu-main', 'Tool Storage', 30 ],
1433 ]
1434 );
1435  
1436 4 my %navs;
1437 4 ▶ while ( my $nav = $rset->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nav = $rset->next) 28 4 32
1438 28 $nav->add_attribute( template => 'category' );
1439 28 $navs{ $nav->uri } = $nav->id;
1440 }
1441  
1442 my @navigation = (
1443 [
1444 'hand-tools/brushes', 'nav',
1445 'menu-main', 'Brushes',
1446 $navs{'hand-tools'}, [qw( os28009 os28108 )]
1447 ],
1448 [
1449 'hand-tools/hammers', 'nav',
1450 'menu-main', 'Hammers',
1451 $navs{'hand-tools'}, [qw( os28044 os28073 os28075 os28074 )]
1452 ],
1453 [
1454 'hand-tools/hand-planes', 'nav',
1455 'menu-main', 'Hand Planes',
1456 $navs{'hand-tools'}, [qw( os28080 )]
1457 ],
1458 [
1459 'hand-tools/hand-saws', 'nav',
1460 'menu-main', 'Hand Saws',
1461 $navs{'hand-tools'}, [qw( os28072 )]
1462 ],
1463 [
1464 'hand-tools/picks-and-hatchets', 'nav',
1465 'menu-main', 'Picks & Hatchets',
1466 $navs{'hand-tools'}, [qw( os28076 os28113 )]
1467 ],
1468 [
1469 'hand-tools/pliers', 'nav',
1470 'menu-main', 'Pliers',
1471 $navs{'hand-tools'}, [qw( os28062 os28065 )]
1472 ],
1473 [
1474 'hand-tools/shears', 'nav',
1475 'menu-main', 'Shears',
1476 $navs{'hand-tools'}, [qw( os28111 os28110 )]
1477 ],
1478 [
1479 'hand-tools/shovels', 'nav',
1480 'menu-main', 'Shovels',
1481 $navs{'hand-tools'}, [qw( os28112 os28109 )]
1482 ],
1483 [
1484 'hand-tools/wrenches', 'nav',
1485 'menu-main', 'Wrenches',
1486 $navs{'hand-tools'}, [qw( os28064 )]
1487 ],
1488 [
1489 'hardware/nails', 'nav',
1490 'menu-main', 'Nails',
1491 $navs{'hardware'}, [qw( os28057c os28057a os28057b )]
1492 ],
1493 [
1494 'ladders/ladders', 'nav',
1495 'menu-main', 'Ladders',
1496 $navs{'ladders'}, [qw( os28085 os28008 )]
1497 ],
1498 [
1499 'ladders/step-tools', 'nav',
1500 'menu-main', 'Step Tools',
1501 $navs{'ladders'}, [qw( os29000 )]
1502 ],
1503 [
1504 'measuring-tools/levels', 'nav',
1505 'menu-main', 'Levels',
1506 $navs{'measuring-tools'}, [qw( os28082 )]
1507 ],
1508 [
1509 'measuring-tools/rulers', 'nav',
1510 'menu-main', 'Rulers',
1511 $navs{'measuring-tools'}, [qw( os28086 )]
1512 ],
1513 [
1514 'measuring-tools/squares', 'nav',
1515 'menu-main', 'Squares',
1516 $navs{'measuring-tools'}, [qw( os28066 )]
1517 ],
1518 [
1519 'measuring-tools/tape-measures', 'nav',
1520 'menu-main', 'Tape Measures',
1521 $navs{'measuring-tools'}, [qw( os28084 )]
1522 ],
1523 [
1524 'painting-supplies/paintbrushes', 'nav',
1525 'menu-main', 'Paintbrushes',
1526 $navs{'painting-supplies'}, [qw( os28007 os28006 os28005 )]
1527 ],
1528 [
1529 'painting-supplies/putty-knives', 'nav',
1530 'menu-main', 'Putty Knives',
1531 $navs{'painting-supplies'}, [qw( os28011 )]
1532 ],
1533 [
1534 'painting-supplies/rollers', 'nav',
1535 'menu-main', 'Rollers',
1536 $navs{'painting-supplies'}, [qw( os28004 )]
1537 ],
1538 [
1539 'painting-supplies/sandpaper', 'nav',
1540 'menu-main', 'Sand Paper',
1541 $navs{'painting-supplies'}, [qw( os28087 os28081 )]
1542 ],
1543 [
1544 'safety-equipment/breathing-protection', 'nav',
1545 'menu-main', 'Breathing Protection',
1546 $navs{'safety-equipment'}, [qw( os28068a )]
1547 ],
1548 [
1549 'safety-equipment/eye-protection', 'nav',
1550 'menu-main', 'Eye Protection',
1551 $navs{'safety-equipment'}, [qw( os28068b )]
1552 ],
1553 [
1554 'tool-storage/tool-belts', 'nav',
1555 'menu-main', 'Tool Belts',
1556 $navs{'tool-storage'}, [qw( os28077 os28070 )]
1557 ],
1558 [
1559 'tool-storage/toolboxes', 'nav',
1560 'menu-main', 'Toolboxes',
1561 4 $navs{'tool-storage'}, [qw( os28069 )]
1562 ],
1563 );
1564  
1565 4 foreach my $nav (@navigation) {
1566 my $nav_result = $rset->create(
1567 {
1568 uri => $nav->[0],
1569 type => $nav->[1],
1570 scope => $nav->[2],
1571 name => $nav->[3],
1572 parent_id => $nav->[4],
1573 navigation_products =>
1574 96 [ map { { "sku" => $_, priority => 100 } } @{ $nav->[5] } ],
1575 }
1576 );
1577  
1578 # add navigation_product links to parent nav as well
1579 96 my $parent = $nav_result->parent;
1580 96 foreach my $sku ( @{ $nav->[5] } ) {
1581 156 $parent->add_to_navigation_products(
1582 { sku => $sku, navigation_id => $parent->id } );
1583 }
1584 }
1585  
1586 4 return $rset;
1587 }
1588  
1589 =head2 states
1590  
1591 Populated via L<Interchange6::Schema::Populate::StateLocale>.
1592  
1593 =cut
1594  
1595 sub _build_states {
1596 4 ▶ my $self = shift;
Subroutine _build_states: called CC=4 SCAR=14.0
1597 4 my $rset = $self->ic6s_schema->resultset('State');
1598  
1599 # we must have countries before we can proceed
1600 4 ▶ $self->countries unless $self->has_countries;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_countries 0 4 4
1601  
1602 4 ▶ if ( $rset->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->count == 0) 3 1 4
1603 3 my $pop = Interchange6::Schema::Populate::StateLocale->new->records;
1604 3 ▶ scalar $rset->populate($pop) or die "Failed to populate State";
Branch: 1 branch
BranchTrueFalseTotal
scalar $rset->populate($pop) or die "Failed to populate State" 0 3 3
1605 }
1606 4 return $rset;
1607 }
1608  
1609 =head2 taxes
1610  
1611 =cut
1612  
1613 sub _build_taxes {
1614 4 ▶ my $self = shift;
Subroutine _build_taxes: called CC=5 SCAR=16.1
1615 4 my %countries;
1616 4 my $rset = $self->ic6s_schema->resultset('Tax');
1617  
1618 # we must have countries and states before we can proceed
1619 4 ▶ $self->countries unless $self->has_countries;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_countries 0 4 4
1620 4 ▶ $self->states unless $self->has_states;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_states 0 4 4
1621  
1622 # EU Standard rate VAT
1623 4 my @data = (
1624 [ 'BE', 21, '1996-01-01' ],
1625 [ 'BG', 20, '1999-01-01' ],
1626 [ 'CZ', 21, '2013-01-01' ],
1627 [ 'DK', 25, '1992-01-01' ],
1628 [ 'DE', 19, '2007-01-01' ],
1629 [ 'EE', 20, '2009-07-01' ],
1630 [ 'GR', 23, '2011-01-01' ],
1631 [ 'ES', 21, '2012-09-01' ],
1632 [ 'FR', 20, '2014-01-01' ],
1633 [ 'HR', 25, '2012-03-01' ],
1634 [ 'IE', 23, '2012-01-01' ],
1635 [ 'IT', 22, '2013-10-01' ],
1636 [ 'CY', 19, '2014-01-13' ],
1637 [ 'LV', 21, '2009-01-01' ],
1638 [ 'LT', 21, '2009-09-01' ],
1639 [ 'LU', 15, '1992-01-01' ],
1640 [ 'HU', 27, '2012-01-01' ],
1641 [ 'MT', 18, '2004-01-01' ],
1642 [ 'NL', 21, '2012-10-01' ],
1643 [ 'AT', 20, '1984-01-01' ],
1644 [ 'PL', 23, '2011-01-01' ],
1645 [ 'PT', 23, '2011-01-01' ],
1646 [ 'RO', 24, '2010-07-01' ],
1647 [ 'SI', 22, '2013-07-01' ],
1648 [ 'SK', 20, '2011-01-01' ],
1649 [ 'FI', 24, '2013-01-01' ],
1650 [ 'SE', 25, '1990-07-01' ],
1651 [ 'GB', 20, '2011-01-04' ],
1652 );
1653 4 foreach my $aref (@data) {
1654  
1655 112 my ( $code, $rate, $from ) = @{$aref};
1656  
1657 112 my $c_name =
1658 $self->countries->find( { country_iso_code => $code } )->name;
1659  
1660 112 $rset->create(
1661 {
1662 tax_name => "$code VAT Standard",
1663 description => "$c_name VAT Standard Rate",
1664 percent => $rate,
1665 country_iso_code => $code,
1666 valid_from => $from,
1667 }
1668 );
1669 }
1670  
1671 # Canada GST/PST/HST/QST
1672 4 my %data = (
1673 BC => [ 'PST', 7 ],
1674 MB => [ 'RST', 8 ],
1675 NB => [ 'HST', 13 ],
1676 NL => [ 'HST', 13 ],
1677 NS => [ 'HST', 15 ],
1678 ON => [ 'HST', 13 ],
1679 PE => [ 'HST', 14 ],
1680 QC => [ 'QST', 9.975 ],
1681 SK => [ 'PST', 10 ],
1682 );
1683 4 foreach my $code ( sort keys %data ) {
1684  
1685 36 my $state = $self->states->find(
1686 { country_iso_code => 'CA', state_iso_code => $code } );
1687  
1688 $rset->create(
1689 {
1690 tax_name => "CA $code $data{$code}[0]",
1691 description => "CA " . $state->name . " $data{$code}[0]",
1692 36 percent => $data{$code}[1],
1693 country_iso_code => 'CA',
1694 states_id => $state->states_id
1695 }
1696 );
1697 }
1698  
1699 4 return $rset;
1700 }
1701  
1702 =head2 users
1703  
1704 [qw( username email password )],
1705 [ 'customer1', 'customer1@example.com', 'c1passwd' ],
1706 [ 'customer2', 'customer2@example.com', 'c1passwd' ],
1707 [ 'customer3', 'customer3@example.com', 'c1passwd' ],
1708 [ 'admin1', 'admin1@example.com', 'a1passwd' ],
1709 [ 'admin2', 'admin2@example.com', 'a2passwd' ],
1710  
1711 =cut
1712  
1713 sub _build_users {
1714 7 ▶ my $self = shift;
Subroutine _build_users: called CC=2 SCAR=6.9
1715 7 my $rset = $self->ic6s_schema->resultset('User');
1716  
1717 # we must have roles before we can proceed
1718 7 ▶ $self->roles unless $self->has_roles;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_roles 3 4 7
1719  
1720 7 scalar $rset->populate(
1721 [
1722 [qw( username email password first_name last_name)],
1723 [
1724 'customer1', 'customer1@example.com',
1725 'c1passwd', "Customer",
1726 "One"
1727 ],
1728 [
1729 'customer2', 'customer2@example.com',
1730 'c1passwd', "Customer",
1731 "Two"
1732 ],
1733 [
1734 'customer3', 'customer3@example.com',
1735 'c1passwd', "Customer",
1736 "Three"
1737 ],
1738 [ 'admin1', 'admin1@example.com', 'a1passwd', "Admin", "One" ],
1739 [ 'admin2', 'admin2@example.com', 'a2passwd', "Admin", "Two" ],
1740 ]
1741 );
1742 7 return $rset;
1743 }
1744  
1745 =head2 zones
1746  
1747 Populated via L<Interchange6::Schema::Populate::Zone>.
1748  
1749 =cut
1750  
1751 sub _build_zones {
1752 3 ▶ my $self = shift;
Subroutine _build_zones: called CC=3 SCAR=11.0
1753 3 my $rset = $self->ic6s_schema->resultset('Zone');
1754  
1755 3 ▶ if ( $rset->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->count == 0) 2 1 3
1756 # we need to pass min value of states_id to ::Populate::Zone
1757 # also kicks in states and countries builders if not already set
1758  
1759 2 my $min_states_id = $self->states->search(
1760 {},
1761 {
1762 select => [ { min => 'states_id' } ],
1763 as => ['min_id'],
1764 }
1765 )->first->get_column('min_id');
1766  
1767 2 my $pop =
1768 Interchange6::Schema::Populate::Zone->new(
1769 states_id_initial_value => $min_states_id )->records;
1770  
1771 2 ▶ scalar $rset->populate($pop) or die "Failed to populate Zone";
Branch: 1 branch
BranchTrueFalseTotal
scalar $rset->populate($pop) or die "Failed to populate Zone" 0 2 2
1772 }
1773 3 return $rset;
1774 }
1775  
1776 =head1 METHODS
1777  
1778 All attributes have a corresponding C<clear_$attribute> method which deletes all rows from the corresponding table and clears the accessor. Each also has a C<has_$attribute> accessor which returns true if the accessor has been set and false otherwise. All attributes are created lazy and are set on access. The full list of clear/has methods are:
1779  
1780 =over
1781  
1782 =item * clear_addresses
1783  
1784 =item * clear_attributes
1785  
1786 =item * clear_countries
1787  
1788 =item * clear_inventory
1789  
1790 =item * clear_media
1791  
1792 =item * clear_message_types
1793  
1794 =item * clear_navigation
1795  
1796 =item * clear_orders
1797  
1798 =item * clear_price_modifiers
1799  
1800 =item * clear_products
1801  
1802 =item * clear_roles
1803  
1804 =item * clear_shipment_carriers
1805  
1806 =item * clear_shipment_rates
1807  
1808 =item * clear_states
1809  
1810 =item * clear_taxes
1811  
1812 =item * clear_users
1813  
1814 =item * clear_zones
1815  
1816 =item * has_addresses
1817  
1818 =item * has_attributes
1819  
1820 =item * has_countries
1821  
1822 =item * has_inventory
1823  
1824 =item * has_media
1825  
1826 =item * has_message_types
1827  
1828 =item * has_navigation
1829  
1830 =item * has_orders
1831  
1832 =item * has_price_modifiers
1833  
1834 =item * has_products
1835  
1836 =item * has_roles
1837  
1838 =item * has_shipment_carriers
1839  
1840 =item * has_shipment_rates
1841  
1842 =item * has_states
1843  
1844 =item * has_taxes
1845  
1846 =item * has_users
1847  
1848 =item * has_zones
1849  
1850 =back
1851  
1852 =head2 clear_all_fixtures
1853  
1854 This additional method calls all of the clear_$accessor methods.
1855  
1856 =cut
1857  
1858 sub clear_all_fixtures {
1859 2 ▶ my $self = shift;
Subroutine clear_all_fixtures: called CC=2 SCAR=6.9
Pod documented
1860 2 foreach my $accessor (@accessors) {
1861 34 my $clear_accessor = "clear_$accessor";
1862 34 $self->$clear_accessor;
1863 }
1864 }
1865  
1866 =head2 load_all_fixtures
1867  
1868 Loads all fixtures.
1869  
1870 =cut
1871  
1872 sub load_all_fixtures {
1873 1 ▶ my $self = shift;
Subroutine load_all_fixtures: called CC=2 SCAR=6.9
Pod documented
1874 # do this in reverse orser
1875 1 my @a = @accessors;
1876 1 ▶ while ( scalar @a > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @a > 0) 17 1 18
1877 17 my $accessor = pop @a;
1878 17 $self->$accessor;
1879 }
1880 }
1881  
1882 3 1;
« Schema/Populate/Zone.pm ↑ Summary Schema/Result/Navigation.pm »