Diff -- /var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_attic/cart_remove.cgi
Diff

/var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_attic/cart_remove.cgi

added on local at 2026-07-01 21:47:31

Added
+76
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to d93ee859468e
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# RePricer -- remove an item from the cart.
4#
5# POST params:
6# cart_item_id = which cart_items row to delete
7#
8# Returns JSON { success: 1, count: N } with the remaining cart count.
9# Auth is the cart_token cookie -- buyer must own the row.
10#======================================================================
11use strict;
12use warnings;
13
14use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
15use CGI;
16use MODS::DBConnect;
17use MODS::RePricer::Config;
18use MODS::RePricer::Cart;
19
20$| = 1;
21
22my $q = CGI->new;
23my $db = MODS::DBConnect->new;
24my $config = MODS::RePricer::Config->new;
25my $cart = MODS::RePricer::Cart->new;
26my $DB = $config->settings('database_name');
27
28print "Content-Type: application/json\nCache-Control: no-cache\n\n";
29
30our $DONE = 0;
31END {
32 if (!$DONE) {
33 print qq~{"success":0,"error":"server aborted -- check MODS/DB_ERRORS.log"}~;
34 }
35}
36
37sub fail {
38 my ($msg) = @_;
39 $msg =~ s/"/\\"/g;
40 print qq~{"success":0,"error":"$msg"}~;
41 $DONE = 1;
42 exit;
43}
44
45my $token = $cart->read_token($q);
46fail('no cart') unless $token;
47
48my $cart_item_id = $q->param('cart_item_id') || 0;
49$cart_item_id =~ s/[^0-9]//g;
50fail('missing cart_item_id') unless $cart_item_id;
51
52my $dbh = $db->db_connect();
53
54# Verify the row exists AND belongs to this cart token. The
55# combination of WHERE id AND WHERE cart_token gates ownership --
56# without the right cookie, you can't delete someone else's row.
57my $row = $db->db_readwrite($dbh, qq~
58 SELECT storefront_id FROM `${DB}`.cart_items
59 WHERE id='$cart_item_id' AND cart_token='$token' LIMIT 1
60~, $ENV{SCRIPT_NAME}, __LINE__);
61unless ($row && $row->{storefront_id}) {
62 $db->db_disconnect($dbh);
63 fail('cart item not found');
64}
65my $sid = $row->{storefront_id};
66
67$db->db_readwrite($dbh,
68 qq~DELETE FROM `${DB}`.cart_items WHERE id='$cart_item_id' AND cart_token='$token' LIMIT 1~,
69 $ENV{SCRIPT_NAME}, __LINE__);
70
71my $count = $cart->count($db, $dbh, $DB, $token, $sid);
72$db->db_disconnect($dbh);
73
74print qq~{"success":1,"count":$count}~;
75$DONE = 1;
76exit;
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help