burnbright/silverstripe-shop-geocoding

为SilverShop提供地理编码支持。

安装次数: 1,628

依赖项: 1

建议者: 1

安全: 0

星标: 6

关注者: 5

分支: 9

开放性问题: 1

类型:silverstripe-vendormodule

2.1.0 2022-08-26 01:18 UTC

This package is auto-updated.

Last update: 2024-08-28 03:20:55 UTC


README

为SilverShop添加地理编码支持。根据输入的地址计算出地址坐标。

使用geocoder-php/Geocoder库。

Latest Stable Version Latest Unstable Version CI Total Downloads

安装

composer reqire silvershop/geocoding

配置

提供默认配置,但您也可以定义自己的配置。

在 _config.php 中

$geocoder = new \Geocoder\Geocoder();
$adapter  = new \Geocoder\HttpAdapter\CurlHttpAdapter();
$geocoder->registerProvider(
	new \Geocoder\Provider\ChainProvider(array(
		new \Geocoder\Provider\HostIpProvider($adapter),
		new \Geocoder\Provider\GoogleMapsProvider($adapter)
	))
);
AddressGeocoding::set_geocoder($geocoder);

要本地测试IP,您可以在配置中配置一个'test ip'。

Address:
  test_ip: 202.160.48.114

relocateuser=1 添加到URL中以重新运行地理编码器。

禁用地址坐标地理编码

默认情况下,如果地址尚未计算出坐标,则在保存时自动检索地址的纬度和经度。可以通过以下方式禁用此行为:

Address:
  enable_geocoding: false

禁用自动访问者IP地理编码

默认情况下,此模块为每个访问者地理编码IP。可以通过以下方式禁用此行为:

Page:
  geocode_visitor_ip: false

警告

依赖于第三方地理编码服务可能会降低您的网站速度,尤其是在外部服务负载较重时。您可能需要考虑设置自己的地理编码服务器实例。

地图回退

如果地址无法地理编码,则提供回退结账步骤,通过Google地图字段指定坐标。

请确保将结账步骤添加到yaml配置中。在账单地址后工作可能最好。

CheckoutPage:
  steps:
    'membership' : 'CheckoutStep_Membership'
    'contactdetails' : 'CheckoutStep_ContactDetails'
    'shippingaddress' : 'CheckoutStep_Address'
    'billingaddress' : 'CheckoutStep_Address'
    'addresslocation' : 'CheckoutStep_AddressLocationFallback' #here
    'shippingmethod' : 'CheckoutStep_ShippingMethod'
    'paymentmethod' : 'CheckoutStep_PaymentMethod'
    'summary' : 'CheckoutStep_Summary'