Magento 内置了UPS FEDEX DHL USPS 的扩展,因为这些扩展都需要条用官方的结果,而我们的价格和官方又不一样,所以独立出来新建扩展就可以自定义自己的计算规则和价格.同样我也考虑了用SOAP,因为站点比较多.价格也统一了
参考官方文档的步骤很快能实现这一功能:
Magento Official WIKI :Create Shiping Module
创建模块的步骤:
1.在app/etc/modules中新建xml配置文件用来申明该插件的代码位置和状态
2.在app/code/local(community)目录中存放插件,目录需要在app/etc/modules/Company_Module.xml中指定
3.在插件目錄中撰寫config.xml和system.xml配置相關的文件進行配置.
4.撰寫php代碼,model和block部份.
5.後臺配置,前臺調試
一.先到app/etc/modules目录中新建一个文件,名为:Plima_Ship.xml.根据Magento的命名规则,_前为org名称(公司或者组织,当然了.根据自己喜好设定),_后为模块名称.文件全称意味着在 app/etc/code/local(community)中目录和配置文件相符.如:Plima_Ship.xml对应的目录应该为:app/etc/code/local(community)/Plima/Ship
Create config file in app/etc/modules and declare module
01.
< ?xml version="1.0"?>
02.
< config>
03.
< modules>
04.
< Plima_Ship>
05.
< active>true< /active>
06.
< codePool>local< /codePool>
07.
< /Plima_Ship>
08.
< /modules>
09.
< /config>
为模块名称,必须和文件对应,否则Magento找不到模块
中true为启用,反之false为停用
代码位置,之前我提到了有两个地方:local和community,在此申明就可以了,当然了.如果你非要写在core也是可以的,只是预留在这两个位置方便我们对插件进行管理.接下来进行第二步.
二.在app/etc/code/local/中創建插件的目錄結構:
etc 中存放config.xml和system.xml的配置文件
Model 為php的計算模型
Helper 為助手,根據框架的思想來設計的
三.在etc中新建兩個文件,config.xml和system.xml
由于文件代码较多,在文章中我就不一一阐述了,只挑一部分进行说明,两个文件可以在下边的url中下载:
config.xml:http://
system.xml http://
文件说明:
1.config.xml:
之前強調的模塊名稱再一次在這裡出現,需要特別注意名稱的大小寫和目錄的目錄須保持一致;
1.
< modules>
2.
< Plima_Ship>
3.
< version>0.1.0 Beta< /version>
4.
< depends>
5.
< Mage_Shipping />
6.
< /depends>
7.
< /Plima_Ship>
8.
< /modules>
中告訴Magento ship provider 的類名
注:我用pems作為文件名稱是考慮到如果我用ups和fedex時可能會和magento內置的模塊衝突,故在文件名前+了p,如果不需要可先在app/etc/modules/Mage_All.xml中找到 Usa 停用即可
像title name allowspecific這些配置為默認後臺看到的選項,接下來我會在system.xml中說明
01.
< default>
02.
< carriers>
03.
< pems>
04.
< active>0< /active>
05.
< model>plima_ship_model_shipping_carrier_pems< /model>
06.
< allowed_methods>< /allowed_methods>
07.
< weight_unit>kg< /weight_unit>
08.
< rounding_rule>none< /rounding_rule>
09.
< google_checkout_compatible>0< /google_checkout_compatible>
10.
< name>Pems< /name>
11.
< title>Plima Ems< /title>
12.
< sallowspecific>0< /sallowspecific>
13.
< specificcountry>GB< /specificcountry>
14.
< sort_order>0< /sort_order>
15.
< /pems>
16.
< carriers>
17.
< /default>
2.system.xml
< label>Plima_EMS< /label> 這塊為後臺配置時顯示的塊名稱,可以在這裡修改;
fields為詳細的選項,比如常用
active,title,salowspecific,specificcountry等等,這些字段的申明是爲了在model中接受參數,而參數的鍵值正為這裡什麽的名稱,如果我定義一個則我在model中接受的時候需這樣寫:
$val = $this->getConfigData(‘discount’);
而值是根據配置來定的,如果是文本,則值為文本域所保存的值.
< frontend_type>text< /frontend_type>這一段就是什麽字段類型為文本;
具體可以查看數據庫 core_config_data中的表.
01.
< pems translate="label" module="ship">
02.
< label>Plima_EMS< /label>
03.
< frontend_type>text< /frontend_type>
04.
< sort_order>77< /sort_order>
05.
< show_in_default>1< /show_in_default>
06.
< show_in_website>1< /show_in_website>
07.
< show_in_store>1< /show_in_store>
08.
< fields>
09.
< active translate="label">
10.
< label>Enabled< /label>
11.
< frontend_type>select< /frontend_type>
12.
< source_model>adminhtml/system_config_source_yesno< /source_model>
13.
< sort_order>1< /sort_order>
14.
< show_in_default>1< /show_in_default>
15.
< show_in_website>1< /show_in_website>
16.
< show_in_store>1< /show_in_store>
17.
< /active>
18.
< gateway_url translate="label">
19.
< label>SOAP Url< /label>
20.
< frontend_type>text< /frontend_type>
21.
< sort_order>12< /sort_order>
22.
< show_in_default>1< /show_in_default>
23.
< show_in_website>1< /show_in_website>
24.
< show_in_store>1< /show_in_store>
25.
< /gateway_url>
26.
< tax_fee translate="label">
27.
< label>Tax< /label>
28.
< frontend_type>text< /frontend_type>
29.
< sort_order>12< /sort_order>
30.
< show_in_default>1< /show_in_default>
31.
< show_in_website>1< /show_in_website>
32.
< show_in_store>0< /show_in_store>
33.
< /tax_fee>
34.
< sort_order translate="label">
35.
< label>Sort order< /label>
36.
< frontend_type>text< /frontend_type>
37.
< sort_order>100< /sort_order>
38.
< show_in_default>1< /show_in_default>
39.
< show_in_website>1< /show_in_website>
40.
< show_in_store>1< /show_in_store>
41.
< /sort_order>
42.
< title translate="label">
43.
< label>Title< /label>
44.
< frontend_type>text< /frontend_type>
45.
< sort_order>2< /sort_order>
46.
< show_in_default>1< /show_in_default>
47.
< show_in_website>1< /show_in_website>
48.
< show_in_store>1< /show_in_store>
49.
< /title>
50.
< sallowspecific translate="label">
51.
< label>Ship to applicable countries< /label>
52.
< frontend_type>select< /frontend_type>
53.
< sort_order>90< /sort_order>
54.
< frontend_class>shipping-applicable-country< /frontend_class>
55.
<source_model>adminhtml/system_config_source_shipping_allspecificcountries< /source_model>
56.
< show_in_default>1< /show_in_default>
57.
< show_in_website>1< /show_in_website>
58.
< show_in_store>1< /show_in_store>
59.
< /sallowspecific>
60.
< specificcountry translate="label">
61.
< label>Ship to Specific countries< /label>
62.
< frontend_type>multiselect< /frontend_type>
63.
< sort_order>91< /sort_order>
64.
< source_model>adminhtml/system_config_source_country< /source_model>
65.
< show_in_default>1< /show_in_default>
66.
< show_in_website>1< /show_in_website>
67.
< show_in_store>1< /show_in_store>
68.
< /specificcountry>
69.
< showmethod translate="label">
70.
< label>Show method if not applicable< /label>
71.
< frontend_type>select< /frontend_type>
72.
< sort_order>92< /sort_order>
73.
< source_model>adminhtml/system_config_source_yesno< /source_model>
74.
< show_in_default>1< /show_in_default>
75.
< show_in_website>1< /show_in_website>
76.
< show_in_store>1< /show_in_store>
77.
< /showmethod>
78.
< /fields>
79.
< /pems>
本文介绍如何在Magento中创建自定义物流扩展模块,包括模块的配置文件设置、系统配置文件编写及后台配置等内容。

2103

被折叠的 条评论
为什么被折叠?



