magneto创建运费模板

Magento系统自带了大概7种运费方式:平价、运费表、免运费、ups、usps、fedex、dhl等。不过这些依然无法满足我们的需求,这时候就需要创建一个shipping module 来实现了。创建一个shipping module 很简单,需要继承Mage_Shipping_Model_Carrier_Abstract抽象类, 实现Mage_Shipping_Model_Carrier_Interface接口类,这样就能利用函数collectRates来自定义计算运费的方式。这样就可以创建一个插件来自定义shipping method。

添加模块配置信息

首先,添加模块信息,创建文件app/etc/modules/Xbc_Ship.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Xbc_Ship>
      <active>true</active>
      <codePool>local</codePool>
	        <depends>
                <Mage_Shipping />
            </depends>
      <version>1.1.0</version>
    </Xbc_Ship>
  </modules>
</config>

添加模块配置信息,创建文件app/code/local/Xbc/Ship/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Xbc_Ship>
      <version>1.1.0</version>
    </Xbc_Ship>
  </modules>
  <global>
    <helpers>
      <ship>
        <class>Xbc_Ship_Helper</class>
      </ship>
    </helpers>
	<resources>
	  <ship_setup>
		<setup>
		  <module>Xbc_Ship</module>
		</setup>
		<connection>
		  <use>core_setup</use>
		</connection>
	  </ship_setup>
	  <ship_write>
		<connection>
		  <use>core_write</use>
		</connection>
	  </ship_write>
	  <ship_read>
		<connection>
		  <use>core_read</use>
		</connection>
	  </ship_read>
	</resources>
	<models>
	  <ship>
		<class>Xbc_Ship_Model</class>
		<resourceModel>ship_mysql4</resourceModel>
	  </ship>
	</models>
  </global>
	<default>
        <carriers>
            <cm_dhl>
                <active>1</active>
                <debug>0</debug>
                <model>ship/carrier_cm_dhl</model>
                <name>DHL</name>
                <title>DHL</title>
                <description>DHL</description>
                <sort_order>0</sort_order>
            </cm_dhl>
        </carriers>
    </default>
</config>

实现自定义运费

创建文件app/code/local/Hofan/Ship/Model/Carrier/Cm/Dhl.php。

<?php
    class Xbc_Ship_Model_Carrier_Cm_Dhl
		extends Mage_Shipping_Model_Carrier_Abstract
		implements Mage_Shipping_Model_Carrier_Interface
	{
        protected $_code = ‘cm_dhl‘;
 
        /**
        * 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){
        	//if this shipping method disabled
        	if (!$this->getConfigFlag(‘active‘)) {
            	return false;
        	}
 
            $result = Mage::getModel(‘shipping/rate_result‘);
            $method = Mage::getModel(‘shipping/rate_result_method‘);
            $method->setCarrier($this->_code);
            $method->setCarrierTitle($this->getConfigData(‘title‘));
            $method->setMethod($this->_code);
            $method->setMethodTitle($this->getConfigData(‘name‘));
 
            $debug = $this->getConfigData(‘debug‘);
            $rate = $this->getConfigData(‘rate‘);
 
        	//get find the country id
            $country_id = $request->getDestCountryId();
 
            //Get all items
            $items = $request->getAllItems();
            $weight = $request->getPackageWeight();
			foreach ($items as $item){
				$_product = $item->getProduct();
				if ($_product instanceof Mage_Catalog_Model_Product) {
					$product = Mage::getModel(‘catalog/product‘)->load($_product->getId());
					if($_weight = $product->getWeight()){
 
					}
				}
			}
 
			//get price
			$shippingPrice = 100;
 
		    $method->setPrice($shippingPrice);
			$method->setCost($shippingPrice);
            $result->append($method);
            return $result;
        }
 
		/**
		 * Get allowed shipping methods
		 *
		 * @return array
		 */
		public function getAllowedMethods()
		{
			return array($this->_code=>$this->getConfigData(‘name‘));
		}
    }

添加后台配置

如果完成了上面的步骤,你可以添加后台配置文件。创建文件app/code/local/Xbc/Ship/etc/system.xml

<?xml version="1.0"?>
<config>
	<sections>
		<carriers  translate="label" module="ship">
				<groups>
				      <cm_dhl translate="label">
					  <label>Hofan DHL</label>
					  <frontend_type>text</frontend_type>
					  <sort_order>0</sort_order>
					  <show_in_default>1</show_in_default>
					  <show_in_website>1</show_in_website>
					  <show_in_store>1</show_in_store>
					  <model>ship/carrier_cm_dhl</model>
				       <fields>
				         <active translate="label">
                            			<label>Enabled</label>
                            			<frontend_type>select</frontend_type>
                            			<source_model>adminhtml/system_config_source_yesno</source_model>
                            			<sort_order>10</sort_order>
                            			<show_in_default>1</show_in_default>
                            			<show_in_website>1</show_in_website>
                            			<show_in_store>1</show_in_store>
                        		</active>
                        		<debug translate="label">
                            			<label>Debug Mode</label>
                            			<frontend_type>select</frontend_type>
                            			<source_model>adminhtml/system_config_source_yesno</source_model>
                            			<sort_order>20</sort_order>
                            			<show_in_default>1</show_in_default>
                            			<show_in_website>1</show_in_website>
                            			<show_in_store>1</show_in_store>
                        		</debug>
                        		<title translate="label">
                            			<label>Title</label>
                            			<frontend_type>text</frontend_type>
                            			<sort_order>30</sort_order>
                            			<show_in_default>1</show_in_default>
                            			<show_in_website>1</show_in_website>
                            			<show_in_store>1</show_in_store>
                        		</title>
                        		<name translate="label">
                            			<label>Method Name</label>
                            			<frontend_type>text</frontend_type>
                            			<sort_order>40</sort_order>
                            			<show_in_default>1</show_in_default>
                            			<show_in_website>1</show_in_website>
                            			<show_in_store>1</show_in_store>
                        		</name>
                        		<description translate="label">
                            			<label>Description</label>
                            			<frontend_type>textarea</frontend_type>
                            			<sort_order>50</sort_order>
                            			<show_in_default>1</show_in_default>
                            			<show_in_website>1</show_in_website>
                            			<show_in_store>1</show_in_store>
                        		</description>
                        		<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>1</show_in_store>
                        		</sort_order>
					</fields>
				</cm_dhl>
			</groups>
		</carriers>
	  </sections>
</config>

该插件在Magento CE 1.6.2上测试通过。

时间: 2024-08-06 16:06:25

magneto创建运费模板的相关文章

Ecshop实现仿Taobao地区运费模板

目录: 1.Ecshop后台配送方式创建 2.商品绑定配送方式的运费模板 2.1 数据表“ecs_goods”增加一个字段,执行下面SQL语句: 2.2 后台添加/编辑 商品 调出已经安装配送方式 "admin/ goods.php ",将此shipping_list函数添加到goods.php最末处. 2.3 后台添加/编辑商品 实现绑定配送方式"admin/goods_info.htm" 3.前台商品详情调用设置好的配送方式 4.结算流程中,根据配送地址计算运费

VMM创建虚拟机模板按钮不可用

在部署完SCVMM之后,有些朋友可能就迫不及待的想建个虚拟机模板玩玩,但是却发现创建虚拟机模板的按钮是灰色的,不可用.如下图 创建VM模板不可用,一般是操作系统的信息是"未知" 解决办法: 打开虚拟机属性,选择操作系统 修改之后,创建VM模板的按钮就可以正常使用了

整理 PHPstorm实用个人配置,修改调整个性化快捷键,修改使用phpstorm创建的模板的默认注释:

对你有助请点赞,请顶------送人玫瑰,手留余香! 1:58 2016/3/12 整理PHPstorm实用个人配置,修改调整个性化快捷键,修改使用phpstorm创建的模板的默认注释: PHPstorm配置:修改使用phpstorm创建的模板的默认注释 注意:我的也是phpstorm 10,但是配置的位置与下面参见的文章中描述的有所不同: 位置: 主要在一下两个路径: File | Settings | Appearance & Behavior | Appearance File | Set

OPENSTACK在RHEL7安装;admin创建虚拟机模板供demo使用

首先RHEL7安装,导入镜像,选择第一个安装7.0,接着出现下面的界面,我这安装截图来自虚拟机,真正做实验是在物理机,一般需要内存5个G 选择英文 时间选择上海,software selection选择Server UI(加上图形化界面),设置installation destination最后点击begin installation 重新配置分区 点done,一步步继续,下面截图,来自别人提供,我当时忘记截图了 左边添加root密码,右边创建用户 把勾选的enable取消掉 不注册 OK,等待

创建项目模板并上传至gallery

在此之前: 你可能需要visual studio sdk:http://www.microsoft.com/en-us/download/details.aspx?id=40758 关于如何创建项目模版及创建过程中应该要注意的事项: 参考此文,中文的:如何:创建项目模板 http://msdn.microsoft.com/zh-cn/library/xkh1wxd8.aspx 以及 如何:替换模板中的参数 甚至 模板参数. 如何创建一个可以供他人使用或者上传至gallery的vsix模版文件,参

VS自定义项目模板:[3]创建自定义模板

VS2013(VS2010等版本也适用,均需安装Visual Studio SDK) 如何创建自定义模板 1 创建一个C# Project Template项目. 2 项目模板中主要包含4种文件: ●代码文件(可删除),通过模板创建的项目直接包含这些文件. ●自定义项目模板的图标(可删除). ●自定义模板的项目文件,通过模板创建的项目的项目文件. ●模板文件vstemplate,很重要,通过模板创建项目时,通过这个文件来生成项目的. 模板文件的生成操作(Build Action)为VSTempl

修改使用phpstorm创建的模板的默认注释

修改使用phpstorm创建的模板的默认注释听语音 如下图中的Created by JetBrains PhpStorm.和最后一句都不是我想要的.所以需要稍微修改下,但是照他说的在File | Settings | File Templates.里修改,但是根本找不到这个路径,原来是在偏好设置里面. 1 先点击PhpStorm,选择"perfernces" 2 然后点击"File and Code Templates"就会看到各种模板啦. 3 比如我做了如下修改

Sublime text3 创建html模板

最近接手了公司官网跟新的任务,需要编写HTML页面.页面中存在大量重复内容(导航条.页脚.侧边栏等),每次复制粘贴也不是个事,网上搜了相关的HTML模板创建问题,还找到了.楼主使用的是Sublime text3,相关创建HTML模板的方法如下: 1. 使用相关的包,如SublimeTmpl,安装步骤如下: 1.1 安装Package Control组件 1.2 按下Ctrl + Shift + P调出命令面板,选择Install Package选项并回车 1.3 输入要安装的插件,如Sublim

VS2010-MFC(对话框:创建对话框模板和修改对话框属性)

转自:http://www.jizhuomi.com/software/149.html 对话框,大家应该很熟悉了,在我们常用的软件中大多都有对话框界面,例如,360安全卫士的主界面其实就是个对话框,只是它做了很多美工方面的工作,将其大大美化了. 创建对话框主要分两大步,第一,创建对话框资源,主要包括创建新的对话框模板.设置对话框属性和为对话框添加各种控件:第二,生成对话框类,主要包括新建对话框类.添加控件变量和控件的消息处理函数等. 本节先讲讲怎样创建对话框模板和设置对话框属性. 创建基于对话