fix - Commerce checkout confirmation very confusing

fix - EMS Discount Pass Not Applied
This commit is contained in:
Roy Johnson 2006-06-09 21:26:45 +00:00
parent b36b58cbb2
commit edaa6c463a
5 changed files with 93 additions and 18 deletions

View file

@ -18,7 +18,8 @@
- fix: No Help link icon in Matrix edit page
- fix: Problems with In/Out Board (labeling only)
- fix: Adding HTTP Proxy
- fix: EMS Discount Pass Not Applied
- fix: Commerce checkout confirmation very confusing
6.99.3
- Someone removed the status from the submission templates. That has been

View file

@ -0,0 +1,66 @@
#PBtmpl0000000000000016
<a href="<tmpl_var viewShoppingCart.url>"><tmpl_var viewShoppingCart.label></a> &middot;
<a href="<tmpl_var changePayment.url>"><tmpl_var changePayment.label></a> &middot;
<a href="<tmpl_var changeShipping.url>"><tmpl_var changeShipping.label></a><br>
<br>
<tmpl_var title><br>
<ul>
<tmpl_loop errorLoop>
<li><tmpl_var message></li>
</tmpl_loop>
</ul>
<table> <tr align="left">
<th style="border-bottom: 2px solid black">Product</th>
<th style="border-bottom: 2px solid black">Quantity</th>
<th style="border-bottom: 2px solid black" align='center'>Price</th>
<th style="border-bottom: 2px solid black">Amount</th>
<th style="border-bottom: 2px solid black">Each</th>
</tr>
<tmpl_if normalItems>
</tmpl_if>
<tmpl_loop normalItemsLoop>
<tr>
<td align="left"><tmpl_var name></td>
<td align="center"><tmpl_var quantity></td>
<td align="right"><tmpl_var price></td>
<td align="right"><tmpl_var totalPrice></td>
<td>&nbsp;</td>
</tr>
</tmpl_loop>
<tmpl_loop recurringItemsLoop>
<tr>
<td align="left"><tmpl_var name></td>
<td align="center"><tmpl_var quantity></td>
<td align="left"><tmpl_var price></td>
<td align="right"><tmpl_var totalPrice></td>
<td align="left"><tmpl_var period></td>
</tr>
</tmpl_loop>
<tr style="border-top: 1px solid black">
<td colspan='2' style="border-top: 1px solid black">&nbsp;</td>
<td align="right" style="border-top: 1px solid black"><b>Subtotal</b></td>
<td align="right" style="border-top: 1px solid black"><b><tmpl_var subtotal></b></td>
</tr>
<tr>
<td colspan="3" align="right">Shipping</td>
<td align="right"><tmpl_var shippingCost></td>
</tr>
<tr>
<td colspan="3" align="right"><tmpl_var discountsApplied.label></td>
<td align="right"><tmpl_var discountsApplied></td>
</tr>
<tr>
<td colspan="3" align="right" style="border-top: 1px solid black"><b>Total</b></td>
<td align="right" style="border-top: 1px solid black"><b><tmpl_var total></b></td>
</table>
<br><br>
<tmpl_var form>

View file

@ -140,7 +140,7 @@ sub priceLineItem {
);
}
if ($numberOfPasses) {
# $self->session->errorHandler->warn('adding a discount pass.');
#$self->session->errorHandler->warn('adding a discount pass.');
$passesInCart{$passId} = $numberOfPasses;
$totalPassesInCart += $numberOfPasses;
}
@ -151,7 +151,7 @@ sub priceLineItem {
my $numberOfThisPass = $passesInCart{$passId};
# calculate discount.
if ($pass->{type} eq 'newPrice') {
$self->session->errorHandler->warn('discounted price: '.$pass->{amount});
#$self->session->errorHandler->warn('discounted price: '.$pass->{amount});
$discountedPrice = (0 + $pass->{amount}) if ($price > (0 + $pass->{amount}));
} elsif ($pass->{type} eq 'amountOff') {
# not yet implemented!
@ -160,14 +160,15 @@ sub priceLineItem {
}
# while we still have passes and items left to discount.
while ($numberOfThisPass && $quantity) {
# $self->session->errorHandler->warn('applying a discount pass.');
#$self->session->errorHandler->warn('applying a discount pass.');
$totalPrice += $discountedPrice;
$self->session->errorHandler->warn('new discounted price: '.$discountedPrice);
#$self->session->errorHandler->warn('new discounted price: '.$discountedPrice);
$quantity--;
$numberOfThisPass--;
}
}
# return the total of the discounted items plus the total of the non discounted items.
#$self->session->errorHandler->warn($totalPrice + ($quantity * $price));
return ($totalPrice + ($quantity * $price));
}

View file

@ -45,17 +45,17 @@ sub addItem {
$self->session->db->write("insert into transactionItem ".
"(transactionId, itemName, amount, quantity, itemId, itemType) values ".
"(".$self->session->db->quote($self->{_transactionId}).",".$self->session->db->quote($item->name).",".$self->session->db->quote(
($lineItemAmount)
($lineItemAmount ne "")
?($lineItemAmount)
:($item->price)
).",".$self->session->db->quote(
($lineItemAmount)
($lineItemAmount ne "")
?('1')
:($quantity)
).",".
$self->session->db->quote($item->id).",".$self->session->db->quote($item->type).")");
# Adjust total amount in the transaction table.
$self->session->db->write("update transaction set amount=amount+".($item->price * $quantity)." where transactionId=".$self->session->db->quote($self->{_transactionId}));
$self->session->db->write("update transaction set amount=amount+".$self->session->db->quote(($lineItemAmount ne "") ? ($lineItemAmount) : ($item->price * $quantity))." where transactionId=".$self->session->db->quote($self->{_transactionId}));
$self->{_properties}{amount} += ($item->price * $quantity);
push @{$self->{_items}}, {
transactionId => $self->{_transactionId},

View file

@ -236,7 +236,7 @@ If the user continues, the next sub called is www_checkoutSubmit.
sub www_checkoutConfirm {
my $session = shift;
my ($plugin, $f, %var, $errors, $i18n, $shoppingCart, $normal, $recurring, $shipping, $total);
my ($plugin, $f, %var, $errors, $i18n, $shoppingCart, $normal, $recurring, $shipping, $total, $subTotal);
$errors = shift;
$i18n = WebGUI::International->new($session, 'Commerce');
@ -255,15 +255,22 @@ sub www_checkoutConfirm {
# Put contents of cart in template vars
$shoppingCart = WebGUI::Commerce::ShoppingCart->new($session);
($normal, $recurring) = $shoppingCart->getItems;
my @copyOfNormal = @$normal;
foreach (@$normal) {
my $amount;
$_->{deleteIcon} = $session->icon->delete('op=deleteCartItem;itemId='.$_->{item}->id.';itemType='.$_->{item}->type);
$_->{'quantity.form'} = WebGUI::Form::integer($session,{
name => 'quantity~'.$_->{item}->type.'~'.$_->{item}->id,
value => $_->{quantity},
size => 3,
});
$total += $_->{totalPrice};
my $priceLineItem = ($_->{item}->{priceLineItem}) ? ($_->{item}->priceLineItem($_->{quantity},\@copyOfNormal)) : undef; # pass in the quantity and the normal items in the cart.
# use the item plugin's lineItem method for price override
# situations.
$amount = ($priceLineItem ne "") ? ($priceLineItem) : ($_->{totalPrice});
$_->{item}->{price} = $amount;
$total += $amount; # tracks discount
$subTotal += $_->{totalPrice}; # ignores discount (we need this to show them an accurate subtotal and to calculate the discount given.)
}
foreach (@$recurring) {
$_->{deleteIcon} = $session->icon->delete('op=deleteCartItem;itemId='.$_->{item}->id.';itemType='.$_->{item}->type);
@ -274,13 +281,13 @@ sub www_checkoutConfirm {
});
$total += $_->{totalPrice};
}
$var{normalItemsLoop} = $normal;
$var{normalItems} = scalar(@$normal);
$var{recurringItemsLoop} = $recurring;
$var{recurringItems} = scalar(@$recurring);
$var{subTotal} = sprintf('%.2f', $total);
$var{subTotal} = sprintf('%.2f', $subTotal);
$shipping = WebGUI::Commerce::Shipping->load($session, $session->scratch->get('shippingMethod'));
$shipping->setOptions(Storable::thaw($session->scratch->get('shippingOptions'))) if ($session->scratch->get('shippingOptions'));
@ -289,6 +296,8 @@ sub www_checkoutConfirm {
$var{total} = sprintf('%.2f', $total + $shipping->calc);
$var{discountsApplied} = sprintf('%.2f', $total - $subTotal - $shipping->calc);
$var{'discountsApplied.label'} = $i18n->echo("Discount Applied");
$plugin = WebGUI::Commerce::Payment->load($session, $session->scratch->get('paymentGateway'));
$f = WebGUI::HTMLForm->new($session);
@ -388,14 +397,12 @@ sub www_checkoutSubmit {
$transaction = WebGUI::Commerce::Transaction->new($session, 'new');
foreach (@{$currentPurchase->{items}}) {
my $priceLineItem = ($_->{item}->{priceLineItem})
# pass in the quantity and the normal items in the cart.
?($_->{item}->priceLineItem($_->{quantity},\@copyOfNormal))
:undef;
my $priceLineItem = ($_->{item}->{priceLineItem}) ? ($_->{item}->priceLineItem($_->{quantity},\@copyOfNormal)) : undef; # pass in the quantity and the normal items in the cart.
$session->errorHandler->warn("Price Line Item: $priceLineItem");
$transaction->addItem($_->{item}, $_->{quantity},$priceLineItem);
# use the item plugin's lineItem method for price override
# situations.
$amount += ($priceLineItem)
$amount += ($priceLineItem ne "")
?($priceLineItem)
:($_->{item}->price * $_->{quantity});
$var->{purchaseDescription} .= $_->{quantity}.' x '.$_->{item}->name.'<br />';