holyandrew (holyandrew) wrote in changelog,
holyandrew
holyandrew
changelog

[ljcom] r11415: LJSUP-11099: LJ Shop. Change LJ Tokens m...

Committer: akanashin
LJSUP-11099: LJ Shop. Change LJ Tokens mechanics
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm
U   trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm
U   trunk/templates/Shop/Wallet.tmpl
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm	2012-02-06 14:19:16 UTC (rev 11414)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/WalletTokens.pm	2012-02-06 14:22:56 UTC (rev 11415)
@@ -5,6 +5,16 @@
 
 use base qw(LJ::Pay::Payment::PayItem);
 
+use constant {
+    PACKAGES => {
+        500 => 5,
+        1000 => 9,
+        3000 => 25,
+    },
+
+    PACKAGES_ORDER => [ 3000, 1000, 500 ],
+};
+
 sub item { 'tokens' }
 
 sub get_product_name {
@@ -23,7 +33,8 @@
 
 sub calculate_price {
     my ($self) = @_;
-    $self->{'amt'} = ($self->get_qty / LJ::Pay::Wallet::EXCHANGE_RATE());
+
+    $self->{'amt'} = $LJ::DISABLED{ljtokens_slider} ? ($self->get_qty / LJ::Pay::Wallet::EXCHANGE_RATE()) : (PACKAGES->{$self->get_qty} || ($self->get_qty / LJ::Pay::Wallet::EXCHANGE_RATE()));
     return $self->{'amt'};
 }
 

Modified: trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm	2012-02-06 14:19:16 UTC (rev 11414)
+++ trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm	2012-02-06 14:22:56 UTC (rev 11415)
@@ -25,6 +25,8 @@
 
             my @items = $cart->get_items;
             my ($item) = @items;
+            my $tokens_code = LJ::Pay::Payment::PayItem::WalletTokens->item;
+            die unless $item && $item->get_item eq $tokens_code;
 
             my $rcptid = $items[0]->get_rcptid;
             my $rcpt_ljuser = LJ::load_userid($rcptid)->ljuser_display;
@@ -45,6 +47,21 @@
 
     my $balance = int eval { LJ::Pay::Wallet->get_user_balance($remote) };
 
+    my %packages = %{LJ::Pay::Payment::PayItem::WalletTokens::PACKAGES()};
+    my @order = @{LJ::Pay::Payment::PayItem::WalletTokens::PACKAGES_ORDER()};
+
+    my $buy_select_options = [
+        map { {
+            'value' => $_, 
+            'text'  => LJ::Lang::ml(
+                'wallet.bml.landing.package_description', {
+                    'qty' => $_,
+                    'amt' => sprintf ("%.2f", $packages{$_}),
+                }
+            )
+        } } @order,
+    ];
+
     my $amt_input = LJ::html_text({
         'name' => 'send_amt',
         'id' => 'send_amt',
@@ -117,7 +134,10 @@
         'tab_buy_active' => $show_tab eq 'buy',
         'tab_send_active' => $show_tab eq 'send',
         'tab_tokens_free' => $show_tab eq 'free',
+        'buy_select_options' => $buy_select_options,
+        'ljtokens_slider' => !$LJ::DISABLED{ljtokens_slider},
 
+
         'proceed_buy_btn' => $proceed_buy_btn,
         'proceed_offerpal_btn' => $proceed_offerpal_btn,
         'amt_input' => $amt_input,
@@ -169,6 +189,10 @@
     if ($act eq 'buy') {
         my $qty = LJ::Request->post_param('buy_select');
 
+    unless ($LJ::DISABLED{ljtokens_slider} && $qty =~ /^(?:500|1000|3000)$/) {
+        $self->ml_error('error.invalidform');
+    }
+
         my $it;
 
         eval {

Modified: trunk/templates/Shop/Wallet.tmpl
===================================================================
--- trunk/templates/Shop/Wallet.tmpl	2012-02-06 14:19:16 UTC (rev 11414)
+++ trunk/templates/Shop/Wallet.tmpl	2012-02-06 14:22:56 UTC (rev 11415)
@@ -45,7 +45,16 @@
 		<form action="<TMPL_VAR self_uri>" method="post">
 		<TMPL_VAR form_auth>
 		<input type="hidden" name="act" value="buy">
-		<input type="text" name="buy_select">
+
+		<tmpl_if ljtokens_slider>
+			<ul class="b-wallet-tokens-select">
+				<TMPL_LOOP name="buy_select_options">
+					<li class="b-wallet-tokens-select-item b-wallet-tokens-select-<TMPL_VAR value><TMPL_IF __first__> current</TMPL_IF>"><label for="buy_select_<TMPL_VAR value>"><i></i><strong><TMPL_VAR text></strong><input type="radio" name="buy_select" id="buy_select_<TMPL_VAR value>" value="<TMPL_VAR value>"<TMPL_IF __first__> checked="checked"</TMPL_IF> /></label></li>
+				</TMPL_LOOP>
+			</ul>
+		<tmpl_else>
+			<input type="text" name="buy_select"> 
+		</tmpl_if>
 		<TMPL_VAR buy_select>
 		<p><TMPL_VAR proceed_buy_btn></p>
 		</form>

Tags: akanashin, holyandrew, ljcom, pm, tmpl
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