wfgm5k2d/bitrix-location-service

该软件包最新版本(1.0.0)没有提供许可证信息。

这是一个用于获取和处理Bitrix位置的库

1.0.0 2022-07-28 04:39 UTC

This package is not auto-updated.

Last update: 2024-09-20 11:48:40 UTC


README

描述

这是一个用于获取和处理Bitrix位置的库。对于返回数组的每个键,都有一个对应的方法。获取数据的主要方式是通过IP - 网站 https://ipwhois.io/。使用它们的方法来自动确定人的位置。所有的处理都通过Bitrix进行。每个类都可以独立使用,从而消除依赖。除了get<数组字段>方法外,函数也可以独立使用。

安装

composer require wfgm5k2d/bitrix-location-service

对于第一次在Bitrix上使用composer的用户。通常,库安装在local/php_interface (cd local/php_interface) 中。接着在local/php_interface/init.php中添加以下内容:

require_once 'vendor/autoload.php';

使用

    <?php 
    // Получить данные о местоположении по реальномму IP пользователя
    $data = IpWhoIsService::getRealIp()->getDataResult();
    
    // Получить данные города из массива
    $city = $data->getCity();
    
    // Получить информацию о местоположении
    $obData = $data->getBxLocation($city);
    
    // Получить REGION_ID из массива ITEM
    $regionId = $obData->getItemRegionId();
    
    // Получить данные о местоположении региона по REGION_ID
    $obRegion = $obData->getBitrixRegion($regionId);
    
    // Получить название города из региона ['VALUE']['CITY_NAME']
    $sCity = $obData->getValueCityName();
    
    // Выбираем все города
    $arCity = $obData->searchLocationInBitrixLocations(BitrixLocationService::TYPE_CITY, $sCity);
    
    // Если город не нашелся ищем в селах
    $arVillage = $obData->searchLocationInBitrixLocations(BitrixLocationService::TYPE_VILLAGE, $sCity);
    
    // Совместим результаты
    $arCities = array_merge($arCity, $arVillage);
    
    // Получим индекс этого города
    BitrixLocationService::getZipLocation($arCities['ID']);
    
    // Получим полный путь до города
    BitrixLocationService::getFullPathToLocation($arCities);
    ?>

如何将选定的位置绑定到订单表单的设计。生产环境使用

    <?php 
    $siteId = Context::getCurrent()->getSite(); // Получили site ID
    $currencyCode = CurrencyManager::getBaseCurrency(); // Метод возвращает код базовой валюты

    $obOrder = Order::create($siteId, $USER->GetID());
    $obOrder->setPersonTypeId(1); //Установим тип плательщика (Физическое лицо)
    $obOrder->setField('CURRENCY', $currencyCode);
    
    // Устанавливаем корзину пользователя в заказ
    // Получили текущую корзину
    $obBasket = Sale\Basket::loadItemsForFUser(Sale\Fuser::getId(), Bitrix\Main\Context::getCurrent()->getSite())->getBasket(); 
    $obOrder->setBasket($obBasket); // Установили корзину в заказ

    $propertyCollection = $obOrder->getPropertyCollection();
    $propertyCodeToId = array();

    foreach ($propertyCollection as $propertyValue)
        $propertyCodeToId[$propertyValue->getField('CODE')] = $propertyValue->getField('ORDER_PROPS_ID');

    if (!empty($arCity['CODE'])) {
        $propertyValue = $propertyCollection->getItemByOrderPropertyId($propertyCodeToId['LOCATION']);
        $propertyValue->setValue($arCity['CODE']);
    }
    ?>

类描述

  • IpWhoIsService
    • getRealIp
    • getDataResult
    • toArray
    • toObject
    • getBxLocation
    • getIp
    • isSuccess
    • getType
    • getContinent
    • getContinentCode
    • getCountry
    • getCountryCode
    • getRegion
    • getRegionCode
    • getCity
    • getLatitude
    • getLongitude
    • isEu
    • getZip
    • getCallingCode
    • getCapital
    • getBorders
    • getFlagImg
    • getFlagEmoji
    • getFlagEmojiUnicode
    • getConnectionAsn
    • getConnectionOrg
    • getConnectionIsp
    • getConnectionDomain
    • getTimezoneId
    • getTimezoneAbbr
    • getTimezoneIsDst
    • getTimezoneUtc
    • getTimezoneCurrentTime
  • BitrixLocationService
    • getLocation
    • getBitrixRegion
    • searchLocationInBitrixLocations
    • getZipLocation
    • getFullPathToLocation
    • getItemId
    • getItemCode
    • getItemLeftMargin
    • getItemRightMargin
    • getItemDepthLevel
    • getItemSort
    • getItemParentId
    • getItemTypeId
    • getItemLatitude
    • getItemLongitude
    • getItemCountryId
    • getItemRegionId
    • getItemCityId
    • getItemLocDefault
    • getItemNameRu
    • getItemTypeCode
    • getValueId
    • getValueSort
    • getValueCode
    • getValueCountryName
    • getValueCountryShortName
    • getValueCountryId
    • getValueCountryNameOrig
    • getValueCountryNameLang
    • getValueRegionName
    • getValueRegionShortName
    • getValueRegionId
    • getValueRegionNameOrig
    • getValueRegionNameLang
    • getValueCityName
    • getValueCityShortName
    • getValueCityId
    • getValueCityNameOrig
    • getValueCityNameLang
    • getLocationId
    • getFormat
    • getRegionId
  • BitrixLocationRegionService
    • getLocationRegion
    • getId
    • getCode
    • getLeftMargin
    • getRightMargin
    • getDepthLevel
    • getSort
    • getParentId
    • getTypeId
    • getLatitude
    • getLongitude
    • getCountryId
    • getRegionId
    • getCityId
    • getLocDefault
    • getNameRu
    • getTypeCode