0

In my Magento website all items are with weight - grams (gr), litre (L), milliliter (ml), centilitre (cl).

I have created an attribute dropdown contain all weight unit for all products and select the specify weight unit for each product.

But in Shipping Calculations, i want a unified unit weight.

How to do that? any suggestion ?

1

Weight will always be in grams or pounds. It can't be calculated based on liters. You need to make conversion at product creation level when you enter the weight value.
Most of the packaged liter qty items have weight mentioned there.
You can get the better picture of the unit conversion on google.

1

You must calculate the weight for a quote and save it to the shipping address in an observer or rewrite. Something like this (not tested):

$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllItems();
$calculatedWeight = 0;

foreach($items as $item) {

    // Example to create kg unit
    // 1 kg = 1000gr
    // 1 kg = 1 L
    // ...

    $itemWeight = 0;
    $itemVolume = $item->getWeight(); // product weight
    $itemUnit = $item->getYourUnitAtributeCode(); // weight unit

    switch($itemUnit) {
        case 'grams':
            $itemWeight = $itemVolume / 1000; // 785gr = 0.785kg
            break;
        case 'centilitre':
            $itemWeight = $itemVolume * 10 // 85cl = 0.85kg
            break;
        ...
    }

    $calculatedWeight += $item->getQty() * $itemWeight;

}

$quote->getShippingAddress()->setWeight($calculatedWeight)->save();

Hope this helps!

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.