1

I have added an attribute for use on the product page:

enter image description here

Now I would like it show on cart page like this:

enter image description here

If the quantity of a product in the cart is increased, I would like the additional shipping fee to add and increase the GrandTotal

1

I solve my question by own.In the upper picture you see a attribute is created with the name of addition_shipping_fee.Now you need to do follow step to solve the question.

enter image description here

Put this code in file:

<tr>
    <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
        <?php echo 'Additional Shipping Fee'; ?>
    </td>
    <td style="<?php echo $this->getStyle() ?>" class="a-right">
        <?php echo $this->helper('checkout')->formatPrice($this->getAdditionalShippingFee()) ?>
    </td>
</tr>

Now Goto:/app/code/local/Mage/Tax/Block/Checkout/Shipping.php Put this code:

public function getAdditionalShippingFee()
{
    $quote = Mage::getSingleton('checkout/cart')->getQuote();
    $additional_fee = 0;
    foreach($quote->getAllItems() as $item) {
        $product = Mage::getModel('catalog/product')->load($item->getProductId());
        $fee = $product->getData('additional_shipping_fee');
        if($fee) {
            $additional_fee += ($item->getQty() * $fee);
        }
    }
    return $additional_fee;
}

this code help to get value of additional_shipping_fee according to all product Id and product Quantity that already present in quote.

Now we need to add additional fee to order table:

Goto:/app/code/local/Mage/Sales/Model/Quote/Address/Total/Grand.php

public function collect(Mage_Sales_Model_Quote_Address $address)
{
    foreach($address->getAllItems() as $item) {
        $product = Mage::getModel('catalog/product')->load($item->getProductId());
        $fee = $product->getData('additional_shipping_fee');
        if($fee) {
            $additional_fee += ($item->getQty() * $fee);
        }
    }

    $grandTotal     = $address->getGrandTotal();
    $baseGrandTotal = $address->getBaseGrandTotal();

    $store      = $address->getQuote()->getStore();
    $totals     = array_sum($address->getAllTotalAmounts());
    $totals     = $store->roundPrice($totals);
    $baseTotals = array_sum($address->getAllBaseTotalAmounts());
    $baseTotals = $store->roundPrice($baseTotals);

    $address->setGrandTotal($grandTotal+$totals+$additional_fee);
    $address->setBaseGrandTotal($baseGrandTotal+$baseTotals+$additional_fee);
    return $this;
}

here additional_fee is added in both GrandTotal & BaseGrandTotal.

**Result:**This Will Update value on both increase and decrease condition.

enter image description here

after this if any query please tell me:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.