Test/Role/Fixtures.pm

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