voyage/silverstripe-nzpost-addressfinder

此包已被放弃且不再维护。未建议替代包。
此包最新版本(1.0.0)无可用许可证信息。

使用NZPost API添加地址自动完成字段

安装: 647

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:silverstripe-module

1.0.0 2017-12-18 22:08 UTC

This package is not auto-updated.

Last update: 2024-06-23 03:47:20 UTC


README

NZ Post Address Finder

NZ Post API的地址查找模块。

当前使用API的1.0-client版本。所有请求都需要您的client_id和client_secret,并且不使用1.0中的Oauth实现。

入门指南

在NZ Post注册API访问。获取您的client_id和client_secret并将其添加到您的config.yml文件中

NZPOSTAPI:
  client_id: "1234567890"
  client_secret: "1234567890"

此模块包含两个代码:用于在您的表单中使用的AddressFinderField以及用于用户表单的EditableAddressFinderField

表单字段

在您的表单中添加AddressFinderField,如下所示。请确保添加setFieldMap并包含您想映射返回结果的字段。键始终是您的表单字段ID,值将是NZ Post字段(这些值可以在下面或NZ Post API文档中找到)。

$field = AddressFinderField::create('AddressFinderField', 'Search for an address')
  ->setFieldMap([
    "FormField_AddressLine1" => "AddressLine1",
    "FormField_AddressLine2" => "AddressLine2",
    "FormField_City" => "CityTown",
    "FormField_Postcode" => "Postcode"
  ]);

用户表单字段

此模块包含用于用户表单的字段。EditableAddressFinderField将映射标签页添加到字段的编辑视图中。在这里您可以添加多个映射。

每个映射都需要用户表单字段ID或名称以及要获取的对应NZ Post值。

内容编辑器

使用用户表单字段时,内容编辑器需要通过CMS手动选择他们想要映射的字段。

在字段编辑视图中,有一个映射标签页。从这里,内容编辑器可以添加新的字段映射并将另一个用户表单字段ID/名称与NZ Post字段ID相匹配。

用户表单字段的名称可以在字段主标签页中找到。

字段映射

以下是从NZ Post提供的可映射字段。显示的值仅基于返回的响应的示例。

"DPID": 3111226,
"AddressLine1": "7 Waterloo Quay",
"AddressLine2": "Pipitea",
"AddressLine3": "Wellington 6011",
"AddressLine4": null,
"AddressLine5": null,
"Postcode": "6011",
"SourceDesc": "Postal\\Physical - Not Delivered",
"Deliverable": "N",
"Physical": "Y",
"UnitType": null,
"UnitValue": null,
"Floor": null,
"StreetNumber": 7,
"StreetAlpha": null,
"RoadName": "Waterloo",
"RoadTypeName": "Quay",
"RoadSuffixName": null,
"Suburb": "Pipitea",
"RuralDelivery": null,
"Lobby": null,
"CityTown": "Wellington",
"MailTown": null,
"BoxBagNumber": null,
"BoxBagType": null

贡献

  1. 分支它!
  2. 创建您的功能分支: git checkout -b my-new-feature
  3. 提交您的更改: git commit -am '添加一些功能'
  4. 推送到分支: git push origin my-new-feature
  5. 提交拉取请求 :D

致谢

Silverstripe Google Address Field - 映射字段值的灵感

许可证

待办事项

  • 添加单元测试
  • 添加JS测试
  • 使SS4兼容
  • 完成设置Oauth