журнал (shhh) wrote in changelog,
журнал
shhh
changelog

[ljcom] r12615: LJSUP-13538: Refactoring of shop promo p...

Committer: nnikulochkina
LJSUP-13538: Refactoring of shop promo pages
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
U   trunk/htdocs/shop/selfpromo.bml.text.local
Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-09-06 09:49:00 UTC (rev 12614)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-09-06 09:51:45 UTC (rev 12615)
@@ -42,6 +42,20 @@
     'community' => 'community',
     'journal' => 'journal',
 );
+
+my $errors_map = {
+    ERROR_OBJECT_INELIGIBLE()         => {
+        'entry'     => 'entry_ineligible',
+        'journal'   => 'journal_ineligible',
+        'community' => 'community_ineligible',
+    },
+    ERROR_PRICE_INSUFFICIENT()        => 'price_insufficient',
+    ERROR_INVALID_PRICE()             => 'price_invalid',
+    ERROR_WALLET_INSUFFICIENT_FUNDS() => 'wallet_insufficient_funds',
+    ERROR_BIDS_HAVE_CHANGED()         => 'bids_have_changed',
+    ERROR_PROMO_HAS_CHANGED()         => 'promo_has_changed',
+};
+
   
 sub class { PROMO_SELF() }
   
@@ -108,8 +122,11 @@
     do {
         my $reason;
         unless ( $class->is_object_eligible( $slot, $promoted_object, $promoter, \$reason ) ) {
-            $class->raise_error( ERROR_OBJECT_INELIGIBLE, details => $reason );             
-            # TODO: fix error messages, make it class specific
+            $class->raise_error( ERROR_OBJECT_INELIGIBLE,
+                                 typified => 1,
+                                 type     => $promoted_object->type,
+                                 details  => $reason, 
+                                 $promoted_object->get_ml_params );
         }
     };
   
@@ -117,7 +134,8 @@
     do {
         my $price_additional = $price - $slot->config->{'min_cost'};
         if ( $price_additional % $slot->config->{'step'} ) {
-            $class->raise_error(ERROR_INVALID_PRICE);
+            $class->raise_error(ERROR_INVALID_PRICE, 
+                                price => $price);
         }
 
         my $min_price = $class->buyout_cost($slot, 'require_db' => 1 );
@@ -125,7 +143,9 @@
             $class->debug_msg($slot,
                 "not enough money offered, need at least $min_price");
 
-            $class->raise_error( ERROR_PRICE_INSUFFICIENT, details => $min_price );
+            $class->raise_error( ERROR_PRICE_INSUFFICIENT, 
+                                 need => $min_price,
+                                 price => $price);
         }
 
         my $wallet_balance = int LJ::Pay::Wallet->get_user_balance($promoter);
@@ -136,7 +156,8 @@
             );
 
             $class->raise_error( ERROR_WALLET_INSUFFICIENT_FUNDS,
-                details => $wallet_balance );
+                have => $wallet_balance,
+                need => $price );
         }
     };
 
@@ -1117,6 +1138,17 @@
 }
 
 
+sub raise_error {
+    my ( $class, $code, %args ) = @_;
+    
+    $code = $args{typified} ?
+        $errors_map->{$code}{$args{type}} :
+        $errors_map->{$code};
+        
+    $class->SUPER::raise_error($code, %args);
+}
+
+
 # TODO: Candidate to move it to PromotionSlot
 #sub was_promoted {
 #    my ($class, $slot, $object) = @_;

Modified: trunk/htdocs/shop/selfpromo.bml.text.local
===================================================================
--- trunk/htdocs/shop/selfpromo.bml.text.local	2012-09-06 09:49:00 UTC (rev 12614)
+++ trunk/htdocs/shop/selfpromo.bml.text.local	2012-09-06 09:51:45 UTC (rev 12615)
@@ -65,6 +65,8 @@
 
 .entry_was_promoted=<b>This entry was promoted in Promo</b>
 
+.error.bids_have_changed=Bids have changed
+
 .error.community.not_specified|staleness=1
 .error.community.not_specified=No community specified to promote.
 
@@ -172,6 +174,8 @@
 
 .error.remote_non_sup=This service is not available to the users who have not opted into <a href="http://www.livejournal.com/manage/settings/?cat=display#LJ__Setting__CyrillicServices_cyrillicservices">Cyrillic services</a>.
 
+.error.promo_has_changed=Promo has changed
+
 .error.wallet_insufficient_funds=You only have [[have]] [[?have|LJ Token|LJ Tokens]] in your Wallet, which is not enough to pay [[need]] [[?need|LJ Token||LJ Tokens]] for promotion.
 
 .get.this.place=Promote your entry for just 100 tokens

Tags: ljcom, local, nikulochkina, nnikulochkina, pm
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