ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[ljcom] r7531: LJSUP-4203: Userpic Add-on - LJSUP-4457:...

Committer: ssafronova
LJSUP-4203: Userpic Add-on - LJSUP-4457: move bulk code to class structure - cleaning code

U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm
U   branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm
U   branches/shop/cgi-bin/paylib.pl
U   branches/shop/htdocs/admin/accounts/enternew.bml
U   branches/shop/htdocs/manage/account/modify.bml
U   branches/shop/htdocs/pay/modify.bml
Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Boolean.pm	2009-08-03 11:08:11 UTC (rev 7531)
@@ -2,13 +2,38 @@
 
 use base LJ::Pay::Payment::PayItem::Addon;
 
-sub can_apply_bool_bonus {
-    my ($u, $cartobj, $item) = @_;
-    my $userid = LJ::want_userid($u);
+sub is_valid_bool_bonus {
+    my ($item, $qty, $is_rec) = @_;
 
-    # easy/obvious checks
-    return undef unless $userid && item_is_bonus($item, 'bool');
+    # allow passing of an $it hash
+    if (ref $item) {
+        $qty  = $item->{qty};
+        $item = $item->{item};
+    }
 
+    my $itrec = $LJ::Pay::Payment::PayItem::Addon::bonus{$item};
+    return 0 unless ref $itrec;
+    return 0 unless $itrec->{type} eq 'bool';
+    return 0 unless ref $itrec->{items}->{$qty};
+    return 0 unless defined $itrec->{items}->{$qty}->{$is_rec ? 'amount_rec' : 'amount'};
+    return 1;
+}
+
+sub get_product_name {
+    my ($class, $subitem, $qty, $short) = @_;
+    my $item = $class->item;
+
+    my $bitem = $LJ::Pay::Payment::PayItem::Addon::bonus{$item};
+    return LJ::Lang::ml($bitem->{'name'}) . ($short ? "" : (" - " . ($bitem->{'items'}->{$qty}->{'name'} || $qty)));
+}
+
+sub is_valid_cart_item {
+    my $self = shift;
+    my $cartobj = shift;
+
+    my $userid = $self->{'rcptid'};
+    my $item = $self->{'item'};
+
     # when does paid time in the cart begin?
     my $cart_paid_start = undef;
     my $cart_bonus_start = undef;
@@ -73,56 +98,9 @@
 
     # everything checked out
     return 1;
-}
 
-sub get_bool_bonus_price {
-    my ($item, $qty, $is_rec) = @_;
-
-    # allow passing of an $it hash
-    if (ref $item) {
-        $qty = $item->{'qty'};
-        $item = $item->{'item'};
-    }
-
-    return undef unless
-        is_valid_bool_bonus($item, $qty, $is_rec);
-
-    return $LJ::Pay::Payment::PayItem::Addon::bonus{$item}->{items}->{$qty}->{$is_rec ? 'amount_rec' : 'amount'};
 }
 
-sub is_valid_bool_bonus {
-    my ($item, $qty, $is_rec) = @_;
-
-    # allow passing of an $it hash
-    if (ref $item) {
-        $qty  = $item->{qty};
-        $item = $item->{item};
-    }
-
-    my $itrec = $LJ::Pay::Payment::PayItem::Addon::bonus{$item};
-    return 0 unless ref $itrec;
-    return 0 unless $itrec->{type} eq 'bool';
-    return 0 unless ref $itrec->{items}->{$qty};
-    return 0 unless defined $itrec->{items}->{$qty}->{$is_rec ? 'amount_rec' : 'amount'};
-    return 1;
-}
-
-sub get_product_name {
-    my ($class, $subitem, $qty, $short) = @_;
-    my $item = $class->item;
-
-    my $bitem = $LJ::Pay::Payment::PayItem::Addon::bonus{$item};
-    return LJ::Lang::ml($bitem->{'name'}) . ($short ? "" : (" - " . ($bitem->{'items'}->{$qty}->{'name'} || $qty)));
-}
-
-sub is_valid_cart_item {
-    my $self = shift;
-    my $cartobj = shift;
-
-    return undef unless can_apply_bool_bonus($self->{'rcptid'}, $cartobj, $self->{'item'});
-    return 1;
-}
-
 sub get_item_base_price {
     my $self = shift;
     my ($qty, $size, %opts) = @_;
@@ -156,7 +134,11 @@
 sub calculate_price {
     my ($self, $is_gift, $cartobj) = @_;
 
-    $self->{'amt'} = get_bool_bonus_price($self->{item}, $self->{qty});
+    if (is_valid_bool_bonus($self->{item}, $self->{qty})) {
+        $self->{'amt'} = $LJ::Pay::Payment::PayItem::Addon::bonus{$self->{item}}->{items}->{$self->{qty}}->{'amount'};
+    } else {
+        $self->{'amt'} = undef;
+    }
 }
 
 1;

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Sized.pm	2009-08-03 11:08:11 UTC (rev 7531)
@@ -213,8 +213,7 @@
     my $self = shift;
     my $cartobj = shift;
 
-    return undef unless can_apply_sized_bonus($self->{'rcptid'}, $cartobj, $self->{'item'});
-    return 1;
+    return can_apply_sized_bonus($self->{'rcptid'}, $cartobj, $self->{'item'});
 }
 
 sub get_item_base_price {

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm	2009-08-03 11:08:11 UTC (rev 7531)
@@ -609,8 +609,6 @@
 }
 
 sub get_item_base_price {
-    my ($item, $qty, $size, $is_rec, %opts) = @_;
-
     # this shouldn't happen, we'll error loudly
     return undef;
 }

Modified: branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm
===================================================================
--- branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm	2009-08-03 11:08:11 UTC (rev 7531)
@@ -5,8 +5,6 @@
 use base LJ::Pay::Payment::PayItem::Interval;
 
 sub get_item_base_price {
-    my ($item, $qty, $size, $is_rec, %opts) = @_;
-
     # this shouldn't happen, we'll error loudly
     return undef;
 }

Modified: branches/shop/cgi-bin/paylib.pl
===================================================================
--- branches/shop/cgi-bin/paylib.pl	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/cgi-bin/paylib.pl	2009-08-03 11:08:11 UTC (rev 7531)
@@ -80,7 +80,6 @@
 sub product_name       { return LJ::Pay::Payment::PayItem::product_name(@_); }
 sub clothing_availability { return LJ::Pay::Payment::PayItem::Clothes::clothing_availability(@_); }
 sub can_apply_sized_bonus { return LJ::Pay::Payment::PayItem::Addon::Sized::can_apply_sized_bonus(@_); }
-sub can_apply_bool_bonus  { return LJ::Pay::Payment::PayItem::Addon::Boolean::can_apply_bool_bonus(@_); }
 sub get_bonus_dim      { return LJ::Pay::Payment::PayItem::Addon::Sized::get_bonus_dim(@_); }
 sub apply_bonus_item   { return LJ::Pay::Payment::PayItem::Addon::apply_bonus_item(@_); }
 sub expire_bonus       { return LJ::Pay::Payment::PayItem::Addon::expire_bonus(@_); }

Modified: branches/shop/htdocs/admin/accounts/enternew.bml
===================================================================
--- branches/shop/htdocs/admin/accounts/enternew.bml	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/htdocs/admin/accounts/enternew.bml	2009-08-03 11:08:11 UTC (rev 7531)
@@ -115,8 +115,10 @@
             return LJ::bad_input("Must specify a number of months for userpics")
                 unless $POST{'userpic_mo'};
 
+            my $item = LJ::Pay::Payment::PayItem->new_memonly(item => 'userpic', subitem => undef, qty => $POST{'userpic_mo'}+0, 
+                                                              rcptid => $rcptuserid);
             return LJ::bad_input("Cannot apply userpics to the account.")
-                unless LJ::Pay::can_apply_bool_bonus($rcptuserid, undef, 'userpic');
+                unless $item->is_valid_cart_item(undef);
 
             $payit{'qty'} = $POST{'userpic_mo'};
             $payit{'subitem'} = undef;

Modified: branches/shop/htdocs/manage/account/modify.bml
===================================================================
--- branches/shop/htdocs/manage/account/modify.bml	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/htdocs/manage/account/modify.bml	2009-08-03 11:08:11 UTC (rev 7531)
@@ -424,8 +424,10 @@
         # w00t, userpics!
         if ( $POST{userpic} && !$userpic_on) {
 
+            my $item = LJ::Pay::Payment::PayItem->new_memonly(item => 'userpic', rcptid => $u->{'userid'});
+
             my $gb = $good_bonus->('userpic', undef, $curr_bill_interval);
-            my $ca = LJ::Pay::can_apply_bool_bonus($u, $pmt, 'userpic');
+            my $ca = $item->is_valid_cart_item($pmt);
 
             if ($gb && $ca) {
                 my $amt = $rec->calc_item_activation_price('userpic', undef, $bill_interval)

Modified: branches/shop/htdocs/pay/modify.bml
===================================================================
--- branches/shop/htdocs/pay/modify.bml	2009-08-03 09:09:24 UTC (rev 7530)
+++ branches/shop/htdocs/pay/modify.bml	2009-08-03 11:08:11 UTC (rev 7531)
@@ -978,39 +978,6 @@
     }
     # end add item block
 
-    # add a physical item
-    if ($POST{'action:addinventory'}) {
-        my $prod = $POST{'product'};
-        return $err->($ML{'.error.invalidproduct'}) unless $prod =~ /^(\w+?)-(.+)$/;
-        return $err->($msg_already_out) unless $can_mod;
-        my ($item_type, $subitem) = ($1, $2);
-
-        # they need to be logged in (no gift products for now at least)
-        return $err->(BML::ml('.error.notloggedinforaddingitems', {'aopts' => "href='$LJ::SITEROOT/login.bml'"}))
-            unless $remote;
-
-        # see if it's available, and its price
-        my $inv = $dbh->selectrow_hashref("SELECT qty, avail, price FROM inventory WHERE ".
-                                          "item=? AND subitem=?", undef, $item_type, $subitem);
-        return $err->($ML{'.error.invalidproduct'}) unless $inv;
-        return $err->($ML{'.error.outofstock'}) unless $inv->{'avail'};
-
-        my $item = {
-            'item' => $item_type,
-            'subitem' => $subitem,
-            'qty' => 1,
-            'amt' => $inv->{'price'},
-            'rcptid' => $remote->{'userid'},
-        };
-
-        $ensurecart->() or return $err->(BML::ml('.error.cantcreatecart', {'errormsg' => $@}));
-
-        my $rt = LJ::Pay::add_cart_item($cartobj, $item);
-        return $err->(BML::ml('.error.cantadditem', {'errormsg' => $dbh->errstr})) unless $rt;
-
-        return BML::redirect("/pay/?c=$cart");
-    }
-
 }
 _code?><?page
 title=><?_code return $title; _code?>

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments