added on local at 2026-07-01 22:09:38
| 1 | package MODS::ShopCart::Onboarding; | |
| 2 | #====================================================================== | |
| 3 | # ShopCart -- new-user sample data seeder | |
| 4 | # | |
| 5 | # Called from signup.cgi. Creates a sample storefront + 3 sample | |
| 6 | # products so the dashboard isn't empty. Idempotent. | |
| 7 | #====================================================================== | |
| 8 | use strict; use warnings; | |
| 9 | ||
| 10 | sub new { return bless {}, shift } | |
| 11 | ||
| 12 | sub seed_sample_data { | |
| 13 | my ($self, $db, $dbh, $DB, $user_id) = @_; | |
| 14 | return unless $user_id; | |
| 15 | ||
| 16 | # Skip if user already has a storefront | |
| 17 | my $r = $db->db_readwrite($dbh, qq~ | |
| 18 | SELECT COUNT(*) AS n FROM `${DB}`.storefronts WHERE user_id='$user_id' | |
| 19 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 20 | return if $r && $r->{n}; | |
| 21 | ||
| 22 | # Build a unique subdomain (storefronts.subdomain is UNIQUE) | |
| 23 | my $sub = "demo-u$user_id"; | |
| 24 | ||
| 25 | my $sf = $db->db_readwrite($dbh, qq~ | |
| 26 | INSERT INTO `${DB}`.storefronts | |
| 27 | SET user_id='$user_id', | |
| 28 | subdomain='$sub', | |
| 29 | name='My Demo Store (example)', | |
| 30 | tagline='Example storefront -- edit or replace with your real one.', | |
| 31 | about_text='This is your sample storefront. Replace with your brand story, switch the theme, point your domain. We auto-issue SSL.', | |
| 32 | cta_primary_label='Shop now', | |
| 33 | cta_secondary_label='About us' | |
| 34 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 35 | my $sfid = ($sf && $sf->{mysql_insertid}) ? $sf->{mysql_insertid} : 0; | |
| 36 | return unless $sfid; | |
| 37 | ||
| 38 | # Three sample products in different categories | |
| 39 | my @samples = ( | |
| 40 | { title => 'Sample Print - Articulated Dragon', | |
| 41 | slug => 'sample-articulated-dragon', | |
| 42 | tagline => 'Example product -- replace with your own.', | |
| 43 | price => 1499, kind => 'digital', category => 'Toys & Hobbies' }, | |
| 44 | { title => 'Sample Print - Modular Storage Bin', | |
| 45 | slug => 'sample-modular-bin', | |
| 46 | tagline => 'Example product -- replace with your own.', | |
| 47 | price => 799, kind => 'digital', category => 'Home & Office' }, | |
| 48 | { title => 'Sample Print - Tabletop Miniature Set', | |
| 49 | slug => 'sample-mini-set', | |
| 50 | tagline => 'Example bundle -- replace with your own.', | |
| 51 | price => 2499, kind => 'digital', category => 'Tabletop' }, | |
| 52 | ); | |
| 53 | ||
| 54 | foreach my $p (@samples) { | |
| 55 | my $t_q = $p->{title}; $t_q =~ s/'/''/g; | |
| 56 | my $s_q = $p->{slug} . '-u' . $user_id; # unique per user | |
| 57 | my $tg_q = $p->{tagline}; $tg_q =~ s/'/''/g; | |
| 58 | my $c_q = $p->{category}; $c_q =~ s/'/''/g; | |
| 59 | $db->db_readwrite($dbh, qq~ | |
| 60 | INSERT INTO `${DB}`.models | |
| 61 | SET user_id='$user_id', | |
| 62 | title='$t_q', | |
| 63 | slug='$s_q', | |
| 64 | tagline='$tg_q', | |
| 65 | base_price_cents='$p->{price}', | |
| 66 | currency='USD', | |
| 67 | category='$c_q', | |
| 68 | product_kind='$p->{kind}' | |
| 69 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 70 | } | |
| 71 | ||
| 72 | return 1; | |
| 73 | } | |
| 74 | ||
| 75 | 1; |