用优惠券的方式实现
web\app\design\frontend\base\default\template\lotusbreath\onestepcheckout\onepage\review\totals.phtml
<?php
$isNewsletter = Mage::getStoreConfig('lotusbreath_onestepcheckout/general/allowsubscribe');
if ($isNewsletter) {
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail(
Mage::getSingleton('customer/session')->getCustomer()->getEmail());
if ($subscriber && $subscriber->getId()) {
$isNewsletter = false;
}
}
}
?>
<?php
/*得到各种数值*/
//$totalKeys = array('subtotal', 'shipping', 'tax', 'discount', 'grand_total');
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
//echo $subtotal;
//echo "---1";
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
//echo $grandtotal;
//echo "---2";
$shipping = $totals["shipping"]->getValue(); //shipping value
//echo $shipping;
//echo "---3";
//if($totals["discount"] && $totals["discount"]->getValue()){
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = $totals["discount"]->getValue(); //discount value
}else{
$discount = 0;
}
$t = $subtotal + $shipping;
$appliedRuleIds = Mage::getSingleton('checkout/session')->getQuote()->getAppliedRuleIds();
//$file = fopen("dh.txt","a+");
//fwrite($file,json_encode($appliedRuleIds));
//fclose($file);
//echo ($appliedRuleIds);
$paymentfee = 0;
$discountfee = 0;
$paymentfeeformat = '';
$discountformat = '';
$appliedRuleIds = explode(',',$appliedRuleIds);
foreach($appliedRuleIds as $appliedRuleId){
$oRule = Mage::getModel('salesrule/rule')->load($appliedRuleId);
$name = $oRule->getData('name');
$discount_amount = $oRule->getData('discount_amount');
if($appliedRuleId == 9){
$paymentfee = -($t * $discount_amount /100);
$paymentfeeformat = Mage::helper('core')->currency($paymentfee);
}
// var_dump($oRule->getData());
// echo $name;
// echo "-->";
// echo $discount_amount;
// echo "-->";
}
if($paymentfee){
if(count($appliedRuleIds) == 1){
$discountfee = 0;
$discountformat = Mage::helper('core')->currency($discountfee);
}else{
$discountfee = ($discount - $paymentfee);
$discountformat = Mage::helper('core')->currency($discountfee);
}
}else{
$discountfee = $discount;
$discountformat = Mage::helper('core')->currency($discountfee);
}
?>
<?php if ($this->getTotals()): ?>
<tfoot>
<?php $_colspan = $this->helper('tax')->displayCartBothPrices() ? 5 : 3; ?>
<!-- /// -->
<?php $getShippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount(); ?>
<?php if ($getShippingAddress): ?>
<tr>
<td class="a-right" colspan="<?php echo $_colspan; ?>">
<small>Shipping & Handling </small>
</td>
<td class="a-right">
<span class="price">
<?php echo Mage::helper('checkout')->formatPrice($getShippingAddress,true,true); ?>
</span>
</td>
</tr>
<?php endif ?>
<!-- /// -->
<?php
$payment = '<tr>
<td colspan="3" style="" class="a-right">
Payment Fee </td>
<td style="" class="a-right">
<span class="price">'.$paymentfeeformat.'</span> </td>
</tr>';
$discount = '<tr>
<td colspan="3" style="" class="a-right">
DISCOUNT </td>
<td style="" class="a-right">
<span class="price">'.$discountformat.'</span> </td>
</tr>';
?>
<?php if($paymentfee)echo $payment; ?>
<?php if($discountfee)echo $discount; ?>
<?php echo $this->renderTotals(null, $_colspan); ?>
<!--<tr>
<td class="a-right" colspan="4" style="height: 10px;"></td>
</tr>
!-->
<?php echo $this->renderTotals('footer', $_colspan); ?>
<?php if ($this->needDisplayBaseGrandtotal()): ?>
<tr>
<td class="a-right" colspan="<?php echo $_colspan; ?>">
<small><?php echo $this->helper('sales')->__('Your credit card will be charged for') ?></small>
</td>
<td class="a-right">
<small><?php echo $this->displayBaseGrandtotal() ?></small>
</td>
</tr>
<?php endif ?>
</tfoot>
<?php endif; ?>
<script type="application/javascript">
/* var paymentfee = '<tr>
<td colspan="3" style="" class="a-right">
Payment Fee </td>
<td style="" class="a-right">
<span class="price">100</span> </td>
</tr>';
var discount = '<tr>
<td colspan="3" style="" class="a-right">
Discount (yy) </td>
<td style="" class="a-right">
<span class="price">200</span> </td>
</tr>';*/
jQuery(document).ready(function(){
jQuery("#checkout-review-table-wrapper tr:contains('Discount')").last().remove();
});
</script>
直接去掉discount
app\code\core\Mage\Checkout\Block\Cart\Totals.php
public function renderTotal($total, $area = null, $colspan = 1)
{
$code = $total->getCode();
if ($total->getAs()) {
$code = $total->getAs();
}
// $file = fopen("mama.txt","a+");
// fwrite($file,($code));
// fclose($file);
/*后面会重置优惠券,所以此处无需设置*/
if($code == 'discount'){
return '';
}else{
return $this->_getTotalRenderer($code)
->setTotal($total)
->setColspan($colspan)
->setRenderingArea(is_null($area) ? -1 : $area)
->toHtml();
}
}