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

Shipping Model Logic - Need Help
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

Can someone help me figure out logic for this shipping method. I can’t wrap my head around it and I’m not sure if I’m even heading in the right direction.

What I’m trying to do is pull the shipping price from the “fixed_shipping” attribute of the item(s) in the cart and multiply it by the quantity of the item(s) to get the total cost of the shipping.

Any help would be awesome.

Thanks in advance.

PS here’s my code as of now

<?php

class Mage_FixedShipping_Model_Carrier_FixedCost extends Mage_Shipping_Model_Carrier_Abstract
{
    
protected $_code 'fixedship';
    
    public function 
collectRates(Mage_Shipping_Model_Rate_Request $request)
    
{
        
// skip if not enabled
        
if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active'))
        
{
            
return false;
        
}
        
        $result 
Mage::getModel('shipping/rate_result');
        
        foreach (
$request->getAllItems() as $item)
        
{
            $shippingPrice 
+= $item->getQty() * $item->getfixed_shipping();
        
};
        
        
        
$method Mage::getModel('shipping/rate_result_method');
            
        
// record carrier information
        
$method->setCarrier('fixedship');
        
$method->setCarrierTitle($this->getConfigData('title'));
        
        
// record method information
        
$method->setMethod('store');
        
$method->setMethodTitle($this->getConfigData('title'));
        
        
$method->setPrice($shippingPrice);
        
        
$result->append($method);        
        return 
$result;
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Baseballtips
Sr. Member
 
Total Posts:  83
Joined:  2008-08-01
 

I updated this so I’m bumping it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
misterMan
Member
 
Total Posts:  57
Joined:  2008-07-15
 

Hi Baseballtips,

I am very interested in this as it looks like what I need. How exactly does this work? Do you put a fixed shipping cost in the product when creating via a text box type attribute, or did you make a list of shipping costs in the attribute and choose from a drop down on the create product page? Can you please explain the setup? This would help many people I think…

And finally, how doe this look on the front end? Does it override the other shipping modules that are active? Or is it another module to choose from when checking out?

Very desperate here. Thanks for any info or insight.

Sorry for all the questions. I’m just trying to clarify.

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

I have added a “Fixed Shipping” attribute to all of my products. When adding a new product you can input a cost for this attribute. Then, in theory, my shipping model will pull the fixed shipping from an item and multiply it by the quantity of the item. This will be done with each item to show the total cost of shipping, which is then added to the total of the items to give the customers the total cost.

Still only theory though because I haven’t been able to wrap my head around the code required to make this work. I’m hoping someone can help me out with this.

For my needs the fixed shipping would override any other active shipping modules that are activated. But only if a fixed shipping cost was specified for the item, otherwise the shipping will probably be based on weight.

 
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 find any result or resources to help find one.

Any ideas out there?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

So, what is the problem with your code exactly?  Does it error out?  Does it calculate the price wrong, What?

Also, as a side note, you have $item->getfixed_shipping() which could/should be written as $item->getFixedShipping()

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

Thanks for responding Lee. I should’ve mentioned all that before.

When I go to checkout it says “Your order cannot be completed at this time there is no shipping method available for it.

I’m pretty sure that it’s seeing my method though, ‘cause I’ve had coding errors in it before that have caused a gray screen to come up and list a bunch of errors whenever I tried to checkout.

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