在我们网站开发过程中常常会遇到各种运费的问题,怎样快速添加一个简单的运费规则呢,下面是快速建立运费规则的一些步骤。
模板文件路径:
app
- code
- local
- Tang
- MyCarrier
- Model
- Carrier.php
- etc
- config.xml
- system.xml
- Model
- MyCarrier
- Tang
- local
- etc
- modules
- Tang.xml
Carrier.php文件中的内容:
- Tang.xml
- modules
<?php
class Tang_MyCarrier_Model_Carrier
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'tang_mycarrier';
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$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('tang_mycarrier');
$rate->setMethodTitle('tang_mycarrier');
$rate->setPrice(58.00);
$rate->setCost(0);
return $rate;
}
public function getAllowedMethods()
{
return array('tang_mycarrier' => $this->getConfigData('name'));
}
}
etc.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Tang_MyCarrier>
<module>0.0.1</module>
</Tang_MyCarrier>
</modules>
<global>
<models>
<tang_mycarrier>
<class>tang_MyCarrier_Model</class>
</tang_mycarrier>
</models>
</global>
<default>
<carriers>
<tang_mycarrier>
<active>1</active>
<model>tang_mycarrier/carrier</model>
<title>Smashing Magazine Carrier</title>
<sort_order>10</sort_order>
<sallowspecific>0</sallowspecific>
</tang_mycarrier>
</carriers>
</default>
</config>
system.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<sections>
<carriers translate="label" module="shipping">
<groups>
<tang_mycarrier translate="label">
<label>国际物流</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>
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>
</fields>
</tang_mycarrier>
</groups>
</carriers>
</sections>
</config>
Tang_MyCarrier.xml文件
<?xml version="1.0"?>
<config>
<modules>
<Tang_MyCarrier>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Shipping />
</depends>
</Tang_MyCarrier>
</modules>
</config>
网友评论