Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Using “$request->getAllItems()” Returns The Same Item Twice
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

I’m using $request->getAllItems() two get all of the items in my cart. Then it’s supposed to return the items “name” and “fixed_shipping” attributes. The problem I’m having is that it doing this twice for only one item. Does anyone know why that is and how to fix it?

go to this product page and add it to your cart. Then estimate the shipping and tax. You should see “Fixed Shipping” and, under that, the name of the product twice. The name of the product is only supposed to appear once.

Here’s the code I’m using:

<?php

class BBT_FixedShipping_Model_Carrier_FixedShipping 
    
extends Mage_Shipping_Model_Carrier_Abstract {
    
    
protected $_code 'fixedshipping';
    
    public function 
collectRates(Mage_Shipping_Model_Rate_Request $request)
    
{
        
if (!$this->getConfigFlag('active')) {
            Mage
::log('The Fixed Shipping method is not active.');
            return 
false;
        
}
        
        $freeBoxes 
0;
        if (
$request->getAllItems()) {
            
foreach ($request->getAllItems() as $item{
                
if ($item->getFreeShipping() && !$item->getProduct()->getTypeInstance()->isVirtual()) {
                    $freeBoxes
+=$item->getQty();
                
}
            }
        }
        $this
->setFreeBoxes($freeBoxes);
        
        
$result Mage::getModel('shipping/rate_result');
        
        
$ship_cost 0;
        if (
$request->getAllItems()) {
            
foreach ($request->getAllItems() as $item{
                $quantity 
$item->getQty();
                
$ship_cost+=$item->getfixed_shipping() * $quantity;
            
}
        }
        
        $shippingPrice 
$this->getFinalPriceWithHandlingFee($ship_cost);
        
        if (
$shippingPrice !== false{
            $method 
Mage::getModel('shipping/rate_result_method');
            
            
$method->setCarrier('fixedshipping');
            
$method->setCarrierTitle($this->getConfigData('title'));
            
            
$method->setMethod('fixedshipping');
            if (
$request->getAllItems()) {
                
foreach ($request->getAllItems() as $item{
                    $method
->setMethodTitle($item->getName());
                
}
            } 
else {
                $method
->setMethodTitle($this->getConfigData('name'));
            
}
            
            
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice 
'0.00';
            
}
            
            $method
->setPrice($shippingPrice);
            
$method->setCost($shippingPrice);
            
            
$result->append($method);
        
}
        
        
return $result;
    
}
    
    
public function getAllowedMethods()
    
{
        
return array('fixedshipping'=>$this->getConfigData('name'));
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

I still haven’t been able to figure this out.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

A little bump.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

I figured it out. Sort of. The reason why the cost is always doubling is because I was testing on a configurable product. Both my Configurable product and the simple products that it consisted of had the same fixed shipping cost. When I removed the fixed shipping cost from my simple products, it stopped doubling.

This feels like a bit of a work around though. Does anyone know of a way to test if the product is the child of a configurable product or the parent of simple products? That way I could exclude one or the other from my loop.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top