I'm using a Free, open source flat rate shipping per product extension on Magento CE 1.8. Basically it just creates a new shipping method and you control the price of that method at the product level.
My problem is I'm using configurable products with child simple products. I'm trying to set the shipping rate on the child simple product ie. $5 for a specific option, if I add that option to the cart it shows the shipping rate correctly as $5, but if I add a qty of 3, it still shows $5 instead of $15.
Any idea how to calculate the shipCost of the child products correctly in the cart?
It calculates the shipping rate with this expression, where shipCost is the custom attribute on the product where you enter the rate:
$shippingPrice += $item->getQty() * $shipCost;
I'm thinking the issue is here:
if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle') {
continue;
}
And here is the full code:
class Magebuzz_Flatrateperproduct_Model_Carrier_Flatrateperproduct
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface {
protected $_code = 'flatrateperproduct';
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$shippingPrice =0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle') {
continue;
}
$shipCost= $product->getShipCost();
if($shipCost==null || $shipCost==0){
$shippingPrice += $item->getQty() * $this->getConfigData('price');
}
else{
$shippingPrice += $item->getQty() * $shipCost;
}
}
}
$result = Mage::getModel('shipping/rate_result');
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrateperproduct');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrateperproduct');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
public function getAllowedMethods()
{
return array('flatrateperproduct'=>$this->getConfigData('name'));
}
}
Please check this you can get configurable product Quantity by this Code :
if($product->getTypeId()=='configurable' || $product->getTypeId()=='bundle')
{
foreach ($item->getChildren() as $child)
{
$quentity = $item->getQty() * $child->getQty();
}
}
else
{
$quentity = $item->getQty();
}