added on local at 2026-07-01 21:47:12
| 1 | package MODS::RePricer::Onboarding; | |
| 2 | #====================================================================== | |
| 3 | # RePricer -- new-user sample data seeder | |
| 4 | # | |
| 5 | # Called from signup.cgi. Creates 3 sample products (Amazon/eBay/Walmart) | |
| 6 | # + a sample account-scope rule so the dashboard isn't empty. Marks | |
| 7 | # reprice_enabled=0 so the worker won't try to push prices for fake SKUs. | |
| 8 | #====================================================================== | |
| 9 | use strict; use warnings; | |
| 10 | ||
| 11 | sub new { return bless {}, shift } | |
| 12 | ||
| 13 | sub seed_sample_data { | |
| 14 | my ($self, $db, $dbh, $DB, $user_id) = @_; | |
| 15 | return unless $user_id; | |
| 16 | ||
| 17 | # Skip if user already has products | |
| 18 | my $r = $db->db_readwrite($dbh, qq~ | |
| 19 | SELECT COUNT(*) AS n FROM `${DB}`.products WHERE user_id='$user_id' | |
| 20 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 21 | return if $r && $r->{n}; | |
| 22 | ||
| 23 | # Sample products. reprice_enabled=0 so the worker ignores them | |
| 24 | # until the user enables real repricing on real SKUs. | |
| 25 | my @samples = ( | |
| 26 | { sku => 'SAMPLE-AMZN-001', marketplace => 'amazon', asin => 'B0SAMPLE01', | |
| 27 | title => 'Sample product - Amazon (example)', | |
| 28 | price => 2999, cost => 1500, min => 1999, max => 4999, buybox => 1, position => 1 }, | |
| 29 | { sku => 'SAMPLE-EBAY-002', marketplace => 'ebay', asin => undef, | |
| 30 | title => 'Sample product - eBay (example)', | |
| 31 | price => 1799, cost => 800, min => 1299, max => 2999, buybox => 0, position => 3 }, | |
| 32 | { sku => 'SAMPLE-WMT-003', marketplace => 'walmart', asin => undef, | |
| 33 | title => 'Sample product - Walmart (example)', | |
| 34 | price => 3499, cost => 1700, min => 2499, max => 5999, buybox => 1, position => 1 }, | |
| 35 | ); | |
| 36 | ||
| 37 | foreach my $s (@samples) { | |
| 38 | my $sku_q = $s->{sku}; $sku_q =~ s/'/''/g; | |
| 39 | my $t_q = $s->{title}; $t_q =~ s/'/''/g; | |
| 40 | my $asin_sql = defined $s->{asin} ? "'$s->{asin}'" : 'NULL'; | |
| 41 | $db->db_readwrite($dbh, qq~ | |
| 42 | INSERT INTO `${DB}`.products | |
| 43 | SET user_id='$user_id', | |
| 44 | marketplace_account_id=0, | |
| 45 | marketplace='$s->{marketplace}', | |
| 46 | sku='$sku_q', | |
| 47 | asin=$asin_sql, | |
| 48 | title='$t_q', | |
| 49 | current_price_cents='$s->{price}', | |
| 50 | cost_cents='$s->{cost}', | |
| 51 | min_price_cents='$s->{min}', | |
| 52 | max_price_cents='$s->{max}', | |
| 53 | reprice_enabled=0, | |
| 54 | is_buybox_winner='$s->{buybox}', | |
| 55 | current_position='$s->{position}' | |
| 56 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 57 | } | |
| 58 | ||
| 59 | # Sample account-scope rule (inactive) so /repricing_rules.cgi isn't empty | |
| 60 | $db->db_readwrite($dbh, qq~ | |
| 61 | INSERT INTO `${DB}`.repricing_rules | |
| 62 | SET user_id='$user_id', | |
| 63 | scope='account', | |
| 64 | name='Beat the lowest competitor by 1c (example)', | |
| 65 | strategy='beat_lowest', | |
| 66 | step_amount_cents=1, | |
| 67 | cooldown_minutes=15 | |
| 68 | ~, $ENV{SCRIPT_NAME}, __LINE__); | |
| 69 | ||
| 70 | return 1; | |
| 71 | } | |
| 72 | ||
| 73 | 1; |