Magento does not provide the ability to calculate shipping charges per item outside of flat rates. For businesses shipping large items via Freight or in individual boxes, shipping charges need to be on a per item basis.
The code below will allow you to specify shipping costs per item based on weight. In our implementation we have 3 individual shipping rates per state. Standard Freight (100lb), Large Freight (500lb), and Extra Large freight (1000lb). Actual weight is irrelevant – we just need to ensure we can accurately quote shipping on 3 sizes to 48 destinations.
Table Rate shipping per item
Using the code below shipping will be calculated per product. Shipping is not calculated per product but per item – if item A costs $10 to ship, and a cart contain (10) item A’s, shipping will be $100.
- Open /app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php
- Find:
$result = Mage::getModel('shipping/rate_result'); $rate = $this->getRate($request);
- Add After:
$combined_request = $request; $individual_rate = 0; foreach($combined_request->getAllItems() as $item) { $combined_request->setPackageWeight($item->getRowWeight()); $temp_rate = $this->getRate($combined_request); $individual_rate += ($temp_rate['price'] * $item->getQty()); } $rate['price'] = $individual_rate;
I can’t remember where this code originated, unfortunately, but it was originally shared by another Magento developer. This code could easily be adapted to Matrix Rates if your already using it.
4 Responses to Magento: Calculate Table Rates per item/product