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

Custom shipping module has fatal error, not showing up in quotes/checkout
 
strategic
Jr. Member
 
Total Posts:  1
Joined:  2010-07-02
 

I have a custom shipping module almost implemented, showing up in backend under shipping methods. When i enable, here is what I get: when I try to get a quote. Please help.

Fatal error: Call to a member function setStore() on a non-object in /home1/norrichc/public_html/app/code/core/Mage/Shipping/Model/Shipping.php on line 191

My method code is as follows:

<?php

/**
 * Our test shipping method module adapter
 */
class Norrich_TritanShipping_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
{
  
/**
   * unique internal shipping method identifier
   * 
   * @var string [a-z0-9_]
   */
  
protected $_code 'TritanShipping';

    
/**
     * Collect rates for this shipping method based on information in $request
     *
     * @param Mage_Shipping_Model_Rate_Request $data
     * @return Mage_Shipping_Model_Rate_Result
     */
  
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
  
{
    
// skip if not enabled
    
if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
        
return false;
    
}

    
/**
     * here we are retrieving shipping rates from external service
     * or using internal logic to calculate the rate from $request
     * you can see an example in Mage_Usa_Model_Shipping_Carrier_Ups::setRequest()
     */

    //Define quote information
    
    
$destCity $request->getDestCity();
    
$destState $request->getDestRegionCode();
    
$destZip $request->getDestPostcode();
    
$destCountry $request->getDestCountryId();
    
$weight $request->getPackageWeight();
    
    
/**
     * Define POST URL and also payload
     */
    
$XML_PAYLOAD '<RateRequest>
                    <Constraints>
                        <Contract />
                        <Carrier />
                        <Mode />
                        <ServiceFlags/>
                        <PaymentTerms/>
                    </Constraints>
                    <Items>
                        <Item sequence="1" freightClass="60">
                            <Weight units="lb"><?php echo $weight; ?></Weight>
                        </Item>
                    </Items>
                    <Events>
                        <Event sequence="1" type="Pickup" date="2/25/2010 08:20">
                            <Location>
                                <City>MIAMI</City>
                                <State>FL</State>
                                <Zip>33122</Zip>
                                <Country>USA</Country>
                            </Location>
                        </Event>
                        <Event sequence="2" type="Drop" date="2/25/2010 16:22">
                            <Location>
                                <City><?php echo $destCity; ?></City>
                                <State><?php echo $destState; ?></State>
                                <Zip><?php echo $destZip; ?></Zip>
                                <Country><?php echo $destCountry; ?></Country>
                            </Location>
                        </Event>
                    </Events>
                </RateRequest>'
;

    
//echo $XML_PAYLOAD;
    
    
$XML_POST_URL "https://mysecureapi.com?userid=****&password;=*****&request;=" urlencode($XML_PAYLOAD);
       
    
/**
     * Initialize handle and set options
     */
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URL$XML_POST_URL);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt($chCURLOPT_TIMEOUT4);
    
//curl_setopt($ch, CURLOPT_POSTFIELDS, $XML_PAYLOAD);
    
curl_setopt($chCURLOPT_HTTPHEADER, array('Connection: close'));

    if ( 
curl_errno($ch) ) {
        $result 
'ERROR -> ' curl_errno($ch) . ': ' curl_error($ch);
    
else {
        $returnCode 
= (int)curl_getinfo($chCURLINFO_HTTP_CODE);
        switch(
$returnCode){
            
case 404:
                
$result 'ERROR -> 404 Not Found';
                break;
            default:
                break;
        
}
    }
    $result 
curl_exec($ch);
    
curl_close($ch);

    
//Create XML Object from XML quote result string
    
$xml simplexml_load_string($result);

     
//As optional array
       
function xml2array($xml{
          $arXML
=array();
          
$arXML['name']=trim($xml->getName());
          
$arXML['value']=trim((string)$xml);
          
$t=array();
          foreach(
$xml->attributes() as $name => $value$t[$name]=trim($value);
          
$arXML['attr']=$t;
          
$t=array();
          foreach(
$xml->children() as $name => $xmlchild$t[$name]=xml2array($xmlchild);
          
$arXML['children']=$t;
          return(
$arXML);
       
}
       
       $response 
xml2array($xml));       

    
// get necessary configuration values
    
$handling Mage::getStoreConfig('carriers/'.$this->_code.'/handling');

    
// this object will be returned as result of this method
    // containing all the shipping rates of this method
    
$result Mage::getModel('shipping/rate_result');

    
// $response is an array that we have 
    
foreach ($response as $rMethod{
      
// create new instance of method rate
      
$method Mage::getModel('shipping/rate_result_method');

      
// record carrier information
      
$method->setCarrier($this->_code);
      
$method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));

      
// record method information
      
$method->setMethod($this->_code);
      
$method->setMethodTitle($rMethod['CarrierName']);

      
// rate cost is optional property to record how much it costs to vendor to ship
      
$method->setCost($rMethod['Total']);

      
// in our example handling is fixed amount that is added to cost 
      // to receive price the customer will pay for shipping method.
      // it could be as well percentage: 
      /// $method->setPrice($rMethod['amount']*$handling/100);
      
$method->setPrice($rMethod['Total']+$handling);

      
// add this rate to the result
      
$result->append($method);
    
}

    
return $result;
  
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
ketu
Jr. Member
 
Total Posts:  5
Joined:  2010-08-20
 

Hi,I had the same issue,did you find the answer?

 
Magento Community Magento Community
Magento Community
Magento Community
 
koopkoop2
Member
 
Total Posts:  38
Joined:  2009-02-04
 

Trying to create my own shipping module too and seeing this same error.

With my module disabled, I echo $storeid right before the line that it crashes on and it returns ‘11’.

With my module enabled, it returns ‘111’.

Tried tracing it back through to where it sets the storeId, but haven’t really dug far enough yet.

Anyone licked this problem yet? It’s the last obstacle to making my store go live!

 
Magento Community Magento Community
Magento Community
Magento Community
 
olivenet
Jr. Member
 
Total Posts:  3
Joined:  2011-01-31
 

Also the same error whether using custom or default shipping modules.  Did anyone get to the bottom of this?  I have commented out the offending line, 192, and it all seems to work, but that’s a nasty hack and I’d rather not do it or at least know why I should.

Thanks

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