本文整理汇总了PHP中CSaleLocation::getTypes方法的典型用法代码示例。如果您正苦于以下问题:PHP CSaleLocation::getTypes方法的具体用法?PHP CSaleLocation::getTypes怎么用?PHP CSaleLocation::getTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSaleLocation
的用法示例。
在下文中一共展示了CSaleLocation::getTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveSelectedTypes
/**
* A very important function. Here we decide what locations we need to take,
* making a descision based on $_REQUEST from sales zone selector.
*
* Then we normalize the selection and store to database.
*
* Also this function is used in data migrator.
*/
public static function saveSelectedTypes($typeList, $siteId)
{
$types = \CSaleLocation::getTypes();
$locations = array(Location\Connector::DB_LOCATION_FLAG => array(), Location\Connector::DB_GROUP_FLAG => array());
if (is_array($typeList['COUNTRY']) && !empty($typeList['COUNTRY'])) {
$typeList['COUNTRY'] = array_flip($typeList['COUNTRY']);
}
if (is_array($typeList['REGION']) && !empty($typeList['REGION'])) {
$typeList['REGION'] = array_flip($typeList['REGION']);
}
if (is_array($typeList['CITY']) && !empty($typeList['CITY'])) {
$typeList['CITY'] = array_flip($typeList['CITY']);
}
$allCountries = isset($typeList['COUNTRY']['']);
$allRegions = isset($typeList['REGION']['']);
$allCities = isset($typeList['CITY']['']);
// no countries
$noCountry = isset($typeList['COUNTRY']['NULL']);
$noRegion = isset($typeList['REGION']['NULL']);
// make up list of ids
$res = Location\LocationTable::getList(array('select' => array('ID', 'COUNTRY_ID', 'REGION_ID', 'CITY_ID', 'TYPE_ID'), 'filter' => array()));
while ($item = $res->fetch()) {
$id = $item['ID'];
$countryId = intval($item['COUNTRY_ID']);
$regionId = intval($item['REGION_ID']);
$cityId = intval($item['CITY_ID']);
$typeId = intval($item['TYPE_ID']);
$take = false;
$countryTaken = false;
$regionTaken = false;
if ($typeId == $types['COUNTRY']) {
if ($allCountries || isset($typeList['COUNTRY'][$countryId])) {
$take = true;
$countryTaken = true;
}
}
if ($typeId == $types['REGION']) {
if ($allRegions && $countryTaken || isset($typeList['REGION'][$regionId]) || $noCountry && !$countryId) {
$take = true;
$regionTaken = true;
}
}
if ($typeId == $types['CITY']) {
if ($allCities && $regionTaken || isset($typeList['REGION'][$regionId]) || $noRegion && !$regionId) {
$take = true;
}
}
if (isset($typeList['CITY'][$cityId]) && $typeId == $types['CITY']) {
// this is a city and it is in list - take it
$take = true;
}
if ($take) {
$locations[Location\Connector::DB_LOCATION_FLAG][$id] = true;
}
}
// normalize
$class = self::CONN_ENTITY_NAME . 'Table';
$locations[Location\Connector::DB_LOCATION_FLAG] = array_keys($locations[Location\Connector::DB_LOCATION_FLAG]);
$locations[Location\Connector::DB_LOCATION_FLAG] = $class::normalizeLocationList($locations[Location\Connector::DB_LOCATION_FLAG]);
// store to database
$class::resetMultipleForOwner(strlen($siteId) ? $siteId : $class::ALL_SITES, $locations);
}