-->

Magento - remove shipping & handling when using Fr

2020-07-31 09:44发布

问题:

I have the following issue: I have to main shipping methods. The first one charges a $10 shipping fee for orders below $200. The second method is the default freeshipping, which applies for orders over $200.

When freeshipping is applied, the Shipping & Handling subtotal displays 0.00, and I don't want this line to show up neither in the checkout nor in the invoice.

Is there any way to remove the shipping & handling line completely when freeshipping is used?

Thanks in advance for any thoughts.

回答1:

I dislike filtering things like this by code. So I came up with a solution overriding Mage_Sales_Model_Quote_Address_Total_Shipping::fetch(Mage_Sales_Model_Quote_Address $address)

app/code/local/Me/MyModule/Model/Sales/Quote/Address/Total/Shipping.php:

<?php
class Me_MyModule_Model_Sales_Quote_Address_Total_Shipping
  extends Mage_Sales_Model_Quote_Address_Total_Shipping
{
    /**
     * Add shipping totals information to address object
     *
     * @param   Mage_Sales_Model_Quote_Address $address
     * @return  Mage_Sales_Model_Quote_Address_Total_Shipping
     */
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        if ($address->getShippingAmount() == 0) {
            return $this;
        }

        return parent::fetch($address);
    }
}

app/code/local/Me/MyModule/etc/config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <Me_MyModule>
      <version>0.0.1</version>
    </Me_MyModule>
  </modules>
  <global>
    <models>
      <me_mymodule>
        <class>Me_MyModule_Model</class>
      </me_mymodule>
      <sales>
        <rewrite>
          <quote_address_total_shipping>Me_MyModule_Model_Sales_Quote_Address_Total_Shipping</quote_address_total_shipping>
        </rewrite>
      </sales>
    </models>
  </global>
</config>

app/etc/modules/Me_MyModule.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Me_MyModule>
            <active>true</active>
            <codePool>local</codePool>
        </Me_MyModule>
    </modules>
</config>


回答2:

remove the shipping line from the cart and checkout you can override this method Mage_Checkout_Block_Cart_Totals::renderTotal()

public function renderTotal($total, $area = null, $colspan = 1)
{
    $code = $total->getCode();
    if ($total->getAs()) {
        $code = $total->getAs();
    }
   if ($code == 'shipping' && $total->getValue() == 0) {
       return '';
   }
    return $this->_getTotalRenderer($code)
        ->setTotal($total)
        ->setColspan($colspan)
        ->setRenderingArea(is_null($area) ? -1 : $area)
        ->toHtml();
}

For more reference review this link http://www.magentocommerce.com/boards/viewthread/295412/#t410854