private:koding:hostcms:modules:shop:cart:locations

Подгрузка адреса

<?php
 
defined('HOSTCMS') || exit('HostCMS: access denied.');
 
/**
* Подгрузка адреса 1.0
* 
* @author KAD Systems (©) 2014	
* @date 30-12-2014	
*
* Копирование и использование файлов модуля 
* в коммерческих целях ЗАПРЕЩЕНО
*/
 
class Kad_Shop_Cart_Locations
{			
	static function execute()
	{
		if(Core_Array::getGet('dataType'))
		{
			$sQuery = strval(Core_Array::getGet('query'));
 
			$aJSON = array();
			$aJSON['query'] = $sQuery;
			$aJSON['suggestions'] = array();
 
			if(Core_Array::getGet('dataType') == 'shop_country_location')
			{
				$oShopCountryLocations = Core_Entity::factory('shop_country_location');
				$oShopCountryLocations->queryBuilder()
					->where('name', 'like', '%' . $sQuery . '%')
					->where('shop_country_id', '=', Core_Array::getGet('shop_country_id'));
				$aoShopCountryLocations = $oShopCountryLocations->findAll();
 
				foreach ($aoShopCountryLocations as $oShopCountryLocation)
				{
					$aJSON['suggestions'][] = array(
						'value' => $oShopCountryLocation->name,
						'id' => $oShopCountryLocation->id
					);
				}
			}
			elseif(Core_Array::getGet('dataType') == 'shop_country_location_city')
			{
				$oShopCountryLocationCities = Core_Entity::factory('shop_country_location_city');
				$oShopCountryLocationCities->queryBuilder()
					->where('name', 'like', '%' . $sQuery . '%')
					->where('shop_country_location_id', '=', Core_Array::getGet('shop_country_location_id'));
				$aoShopCountryLocationCities = $oShopCountryLocationCities->findAll();
 
				foreach($aoShopCountryLocationCities as $oShopCountryLocationCity)
				{
					$aoShopCountryLocationCityAreas = Core_Entity::factory('shop_country_location_city_area')->getAllByShop_Country_Location_City_Id($oShopCountryLocationCity->id);
 
					$aJSON['suggestions'][] = array(
						'value' => $oShopCountryLocationCity->name,
						'id' => $oShopCountryLocationCity->id,
						'areas' => count($aoShopCountryLocationCityAreas)
					);
				}
			}
			elseif(Core_Array::getGet('dataType') == 'shop_country_location_city_area')
			{
				$oShopCountryLocationCityAreas = Core_Entity::factory('shop_country_location_city_area');
				$oShopCountryLocationCityAreas->queryBuilder()
					->where('name', 'like', '%' . $sQuery . '%')
					->where('shop_country_location_city_id', '=', Core_Array::getGet('shop_country_location_city_id'));
				$aoShopCountryLocationCityAreas = $oShopCountryLocationCityAreas->findAll();
 
				foreach($aoShopCountryLocationCityAreas as $oShopCountryLocationCityArea)
				{
					$aJSON['suggestions'][] = array(
						'value' => $oShopCountryLocationCityArea->name,
						'id' => $oShopCountryLocationCityArea->id
					);
				}
			}
 
			Core_Page::instance()->response
				->status(200)
				->header('Pragma', 'no-cache')
				->header('Cache-Control', 'private, no-cache')
				->header('Vary', 'Accept')
				->header('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT')
				->header('X-Powered-By', 'HostCMS')
				->header('Content-Disposition', 'inline; filename="files.json"');
 
			Core_Page::instance()->response
				->body(json_encode($aJSON))
				->header('Content-type', 'application/json; charset=utf-8');
 
			Core_Page::instance()->response
				->sendHeaders()
				->showBody();
 
			exit();
		}
	}		
}
private/koding/hostcms/modules/shop/cart/locations.txt · Last modified: 12.07.17 в 17:58 by maximzasorin_gmail.com