sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[ljcom] r12803: LJSUP-13935: Show correct Journal Promo ...

Committer: vtroitsky
LJSUP-13935: Show correct Journal Promo transactions in the user's wallet history
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/Wallet/Log.pm
U   trunk/cgi-bin/LJ/Widget/Shop/History.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2012-10-22 14:04:55 UTC (rev 12802)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2012-10-22 14:26:24 UTC (rev 12803)
@@ -4,23 +4,25 @@
 
 use LJ::Pay::PromotedObject;
 use LJ::Pay::Promotion;
+use LJ::Pay::PromotionSlot qw(:classes);
 
 use base qw( LJ::Pay::Payment::PayItem );
 
 sub item {'selfpromo'}
 
+# get the object buyed in this payitem
 sub get_object {
     my ($self) = @_;
     $self->{promoted_object} ||= LJ::Pay::PromotedObject->new_from_cart_item($self);
     return $self->{promoted_object};
 }
-
+# get the object URL 
 sub get_object_url {
     my ($self) = @_;
     $self->{promoted_object} ||= LJ::Pay::PromotedObject->new_from_cart_item($self);
     return $self->{promoted_object} ? $self->{promoted_object}->url : '';
 }
-
+# get the object owner
 sub get_object_owner {
     my ($self) = @_;
     $self->{promoted_object} ||= LJ::Pay::PromotedObject->new_from_cart_item($self);   #cache object creation
@@ -41,15 +43,12 @@
 =cut
 sub get_product_name {
     my ($self, $subitem) = @_;
-    $subitem = $self->get_subitem();
+
+    my $promo_class = $self->get_promo_class();
     my $sp_type = $self->get_prop('selfpromo');
-    my $prefix = 'selfpromo';   # TODO: Make it dependent on
+    my $promo = $self->get_promotion();
 
-    # TODO: Refactor and move this later into LJ::Pay::Promotion->new_from_cart_item($self)
-    # split subitem into promo class - 
-    if ( $subitem && $subitem =~ /^commercial\-(\d+)$/ ) {
-        # Create promotion object here       
-        my $promo = LJ::Pay::Promotion::Commercial->new($1);
+    if ( $promo_class eq PROMO_COMMERCIAL()) {
         my $url = "$LJ::SITEROOT/shop/commpromo.bml";
         if ($promo) {
             $url = $promo->url();
@@ -57,10 +56,21 @@
 
         my $type = $self->get_prop('selfpromo_type');
         my $suffix = ($type && $type eq 'refund' ? '.refund' : '');
-        return LJ::Lang::ml( "commercial.$sp_type.shop_item.name$suffix", 
+        return LJ::Lang::ml( "$promo_class.$sp_type.shop_item.name$suffix", 
                 { 'promotion_url' => $url } );
+    } elsif ($promo_class eq PROMO_JOURNAL()) {
+        my $url = '';
+        $url = $promo->object_url() if($promo);
+        my $owner = '';
+        $owner = $promo->slot->owner->ljuser_display() if $promo;
+
+        return LJ::Lang::ml("$promo_class.$sp_type.shop_item.name",
+            {   'object_url' => $url,
+                'journal' => $owner,
+            } );
     }
-    return LJ::Lang::ml( "selfpromo.$sp_type.shop_item.name",
+
+    return LJ::Lang::ml( "$promo_class.$sp_type.shop_item.name",
         { 'object_url' => $self->get_object_url } );
 }
 
@@ -70,8 +80,7 @@
     my $amt = $self->get_amt;
     my $qty = $self->get_qty;
 
-    my $subitem = $self->get_subitem();
-    my $prefix = ( $subitem && $subitem =~ /^commercial/ ? 'commercial' : 'selfpromo'); # TODO: Make it better
+    my $prefix = $self->get_promo_class();
 
     return {
         'name' => $self->get_product_name,
@@ -79,23 +88,65 @@
     };
 }
 
+=item get_promo_class
+=cut
+sub get_promo_class {
+    my ($self, $subitem) = @_;
+    $subitem ||= $self->get_subitem();
+
+    my ($class) = split(/[_\-]/, $subitem); # get first splitted element
+    $class ||= 'selfpromo';
+    return $class;
+}
+
 =item get_wallet_history_desc
-    Return 
+    TODO:  !!!!
 =cut
 sub get_wallet_history_desc {
-    my ($self, $buyer) = @_;
-    my $subitem = $self->get_subitem();
+    my ($self, $buyer, $misc) = @_;
 
-    my $prefix = ($subitem && $subitem =~ /^commercial/ ? 'commercial' : ( $subitem =~ /^journal/ ? 'journals' : 'selfpromo'));
-    if ( $self->get_prop($prefix.'_type') eq 'buyout' ) {
+    my $prefix = $self->get_promo_class();
+    if ($prefix eq PROMO_JOURNAL()) {
+        my $promo = $self->get_promotion();
+        if ($misc && $promo) {
+            if ( $misc & LJ::Pay::Wallet::Log::MASK_REFUND() ) {
+                my $prev_promo = $promo->previous_promotion();
+                return LJ::Lang::ml(
+                    'wallet.widget.history.des.journals.refund', 
+                    { 'buyer' => $buyer->ljuser_display, 
+                      'entry_url' => ($prev_promo ? $prev_promo->object_url() : ''),
+                      'journal' => $promo->slot->owner()->ljuser_display(),
+                    }
+                );
+            } elsif ( $misc & LJ::Pay::Wallet::Log::MASK_INCOME() ) {
+                return LJ::Lang::ml(
+                    'wallet.widget.history.des.journals.income', 
+                    { 'buyer' => $buyer->ljuser_display(),
+                      'entry_url' => $promo->object_url(),
+                    }
+                );
+            } elsif ( $misc & LJ::Pay::Wallet::Log::MASK_REMAINDER() ) {
+                return LJ::Lang::ml(
+                    'wallet.widget.history.des.journals.remainder', 
+                    { 'buyer' => $buyer->ljuser_display(),
+                    }
+                );
+            }
+        }
+        return LJ::Lang::ml('wallet.widget.history.des.journals', { });
+    } else {
+        $prefix = 'selfpromo';
+        if ( $self->get_prop($prefix.'_type') eq 'buyout' ) {
+            return LJ::Lang::ml(
+                'wallet.widget.history.des.'.$prefix.'_refund',
+                { 'buyer' => $buyer->ljuser_display }
+            );
+        }
+
         return LJ::Lang::ml(
-            'wallet.widget.history.des.'.$prefix.'_refund',
-            { 'buyer' => $buyer->ljuser_display }
+            'wallet.widget.history.des.'.$prefix.'_refund.generic'
         );
     }
-    return LJ::Lang::ml(
-        'wallet.widget.history.des.'.$prefix.'_refund.generic'
-    );
 }
 
 sub is_tangible {1}

Modified: trunk/cgi-bin/LJ/Pay/Wallet/Log.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Wallet/Log.pm	2012-10-22 14:04:55 UTC (rev 12802)
+++ trunk/cgi-bin/LJ/Pay/Wallet/Log.pm	2012-10-22 14:26:24 UTC (rev 12803)
@@ -124,6 +124,9 @@
     $masks = {
         MASK_SUP        => 1 << $bits->{'BIT_SUP'},
         MASK_PAID       => 1 << $bits->{'BIT_PAID'},
+        MASK_REFUND     => 1 << 7,
+        MASK_REMAINDER  => 1 << 11,
+        MASK_INCOME     => 1 << 13,
     };
 
     our @EXPORT = ();
@@ -308,6 +311,12 @@
     return $self->{'status'};
 }
 
+sub misc {
+    my ($self) = @_;
+    $self->_load_props;
+    return $self->{'misc'};
+}
+
 sub parse_common_params {
     my ($class, $params) = @_;
 

Modified: trunk/cgi-bin/LJ/Widget/Shop/History.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/History.pm	2012-10-22 14:04:55 UTC (rev 12802)
+++ trunk/cgi-bin/LJ/Widget/Shop/History.pm	2012-10-22 14:26:24 UTC (rev 12803)
@@ -163,7 +163,7 @@
             }
 
             if ( my $it = $it{'SelfPromo'} ) {
-                return $it->get_wallet_history_desc($buyer);
+                return $it->get_wallet_history_desc($buyer, $logitem->misc());
             }
 
             if ( $logitem->userid == $buyer_userid ) {

Tags: ljcom, pm, sunnyman, vtroitsky
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