I am fairly new to Magento Development and am having trouble getting a custom shipping module to work. I followed numerous tutorials but ended up with similar errors each time. The current one I am using is here. I tinkered with it a lot but ended up with more errors, so I am currently at the stock of this tutorial copied over to my magento 1.12.0.2
installation.
Under Sysytem->Config->Shipping Methods
the new method, Smashing Magazine Carrier
, appears and I can edit the values shown. However, whenever I try to go to the cart on the frontend I get the error:
Fatal error: Call to a member function setStore() on a non-object in /var/www/includes/src/Mage_Shipping_Model_Shipping.php on line 421
and the error:
Fatal error: Class 'Mage' not found in /var/www/includes/src/Mage_Core_Model_Resource_Setup.php on line 378
I am at a loss and am looking for any inkling of a right direction to move in to fix this. Thank you for reading! Here are the relevant files:
/var/www/app/etc/modules/SmashingMagazine_MyCarrier.xml
<?xml version="1.0"?>
<config>
<modules>
<SmashingMagazine_MyCarrier>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Shipping />
</depends>
</SmashingMagazine_MyCarrier>
</modules>
</config>
/var/www/app/code/local/SmashingMagazine/MyCarrier/Model/Carrier.php
<?php
class SmashingMagazine_MyCarrier_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {
protected $_code = 'smashingmagazine_mycarrier';
public function collectRates(
Mage_Shipping_Model_Rate_Request $request
) {
$result = Mage::getModel('shipping/rate_result');
/* @var $result Mage_Shipping_Model_Rate_Result */
$result->append($this->_getStandardShippingRate());
$expressWeightThreshold =
$this->getConfigData('express_weight_threshold');
$eligibleForExpressDelivery = true;
foreach ($request->getAllItems() as $_item) {
if ($_item->getWeight() > $expressWeightThreshold) {
$eligibleForExpressDelivery = false;
}
}
if ($eligibleForExpressDelivery) {
$result->append($this->_getExpressShippingRate());
}
if ($request->getFreeShipping()) {
/**
* If the request has the free shipping flag,
* append a free shipping rate to the result.
*/
$freeShippingRate = $this->_getFreeShippingRate();
$result->append($freeShippingRate);
}
return $result;
}
protected function _getStandardShippingRate() {
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
/**
* getConfigData(config_key) returns the configuration value for the
* carriers/[carrier_code]/[config_key]
*/
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('standand');
$rate->setMethodTitle('Standard');
$rate->setPrice(4.99);
$rate->setCost(0);
return $rate;
}
protected function _getExpressShippingRate() {
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('express');
$rate->setMethodTitle('Express (Next day)');
$rate->setPrice(12.99);
$rate->setCost(0);
return $rate;
}
protected function _getFreeShippingRate()
{
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod('free_shipping');
$rate->setMethodTitle('Free Shipping (3 - 5 days)');
$rate->setPrice(0);
$rate->setCost(0);
return $rate;
}
public function getAllowedMethods() {
return array(
'standard' => 'Standard',
'express' => 'Express',
'free_shipping' => 'Free Shipping',
);
}
}
/var/www/app/code/local/SmashingMagazine/MyCarrier/etc/system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<sections>
<carriers translate="label" module="shipping">
<groups>
<smashingmagazine_mycarrier translate="label">
<label>Smashing Magazine Carrier</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<!--
The following fields are available
to modify in the admin panel.
The values are saved in the
database.
This shipping carrier abstract checks
this value to determine whether
the carrier should be shown.
-->
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<!--
This value can be used to specify a
custom title for our method.
-->
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</title>
<!--
The sort order is used in Magento
to determine what order the carrier
will appear in relative to the
other carriers available.
-->
<sort_order translate="label">
<label>Sort Order</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</sort_order>
<!--
This value is used to specify whether
the carrier is available only for
specific countries or all countries
available in the current Magento
installation.
-->
<sallowspecific translate="label">
<label>Ship to Applicable Countries</label>
<frontend_type>select</frontend_type>
<sort_order>90</sort_order>
<frontend_class>shipping-applicable-country</frontend_class>
<source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</sallowspecific>
<!--
If 'specific countries' is chosen
in the previous option, then this field
allows the administrator to specify
which specific countries this carrier
should be available for.
-->
<specificcountry translate="label">
<label>Ship to Specific Countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>91</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<can_be_empty>1</can_be_empty>
</specificcountry>
<express_weight_threshold translate="label">
<label>Express Weight Threshold</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</express_weight_threshold>
</fields>
</smashingmagazine_mycarrier>
</groups>
</carriers>
</sections>
</config>
/var/www/app/code/local/SmashingMagazine/MyCarrier/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<SmashingMagazine_MyCarrier>
<module>0.0.1</module>
</SmashingMagazine_MyCarrier>
</modules>
<global>
<models>
<smashingmagazine_mycarrier>
<class>SmashingMagazine_MyCarrier_Model</class>
</smashingmagazine_mycarrier>
</models>
</global>
<!-- Default configuration -->
<default>
<carriers>
<smashingmagazine_mycarrier>
<active>1</active>
<!--
This configuration should not be made visible
to the administrator, because it specifies
the model to be used for this carrier.
-->
<model>smashingmagazine_mycarrier/carrier</model>
<!--
The title as referenced in the carrier class
-->
<title>Smashing Magazine Carrier</title>
<!--
The sort order specifies the position that
this carrier appears relative to the other
carriers available in checkout.
-->
<sort_order>10</sort_order>
<!--
Out of the box, Magento offers shipping
carriers the ability to restrict themselves
to specific countries. For this configuration
option, 0 means allow all countries available,
and 1 means allow all countries specified
in the country list that we will add later
in system.xml
-->
<sallowspecific>0</sallowspecific>
</smashingmagazine_mycarrier>
</carriers>
</default>
</config>