File Coverage

blib/lib/Interchange6/Test/Role/Fixtures.pm
Criterion Covered Total %
statement 230 230 100.0
branch 34 42 80.9
condition n/a
subroutine 28 28 100.0
pod 5 5 100.0
total 297 305 97.3


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