Skip to content

Instantly share code, notes, and snippets.

@maximzasorin
Last active November 10, 2015 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximzasorin/7fb5a97f0bc154ff1f60 to your computer and use it in GitHub Desktop.
Save maximzasorin/7fb5a97f0bc154ff1f60 to your computer and use it in GitHub Desktop.
Регион и город по умолчанию при оформлении заказа (HostCMS)
<?php
$defaultLocation = Core_Entity::factory('shop_country_location', 2); // Санкт-Петербург и область
$defaultCity = Core_Entity::factory('shop_country_location_city', 173); // Санкт-Петербург
$oShopCountry = Core_Entity::factory('shop_country', $oShop->shop_country_id);
if ($oShopCountry)
{
$aoShopCountryLocations = $oShopCountry
->Shop_Country_Locations
->findAll();
if (count($aoShopCountryLocations) > 0)
{
$oShopCountryLocation = $defaultLocation !== NULL
? $defaultLocation
: $aoShopCountryLocations[0];
if ($oShopCountryLocation)
{
$aoShopCountryLocationCities = $oShopCountryLocation
->Shop_Country_Location_Cities
->findAll();
$Shop_Address_Controller_Show
->addEntities($aoShopCountryLocations)
->addEntity(
Core::factory('Core_Xml_Entity')
->name('current_shop_country_location_id')
->value($oShopCountryLocation->id)
);
if (count($aoShopCountryLocationCities) > 0)
{
$oShopCountryLocationCity = $defaultCity !== NULL
? $defaultCity
: $aoShopCountryLocationCities[0];
$Shop_Address_Controller_Show
->addEntities($aoShopCountryLocationCities)
->addEntity(
Core::factory('Core_Xml_Entity')
->name('current_shop_country_location_city_id')
->value($oShopCountryLocationCity->id)
);
}
}
}
}
<!-- ... -->
<div class="row">
<div class="caption">Область:</div>
<div class="field">
<select name="shop_country_location_id" id="shop_country_location_id" onchange="$.loadCities('{/shop/url}cart/', $(this).val())">
<option value="0">…</option>
<xsl:apply-templates select="shop_country_location" />
</select>
<span class="redSup"> *</span>
</div>
</div>
<div class="row">
<div class="caption">Город:</div>
<div class="field">
<select name="shop_country_location_city_id" id="shop_country_location_city_id" onchange="$.loadCityAreas('{/shop/url}cart/', $(this).val())">
<option value="0">…</option>
<xsl:apply-templates select="shop_country_location_city" />
</select>
</div>
</div>
<!-- ... -->
<xsl:template match="shop_country_location">
<option value="{@id}">
<xsl:if test="/shop/current_shop_country_location_id = @id">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name" />
</option>
</xsl:template>
<xsl:template match="shop_country_location_city">
<option value="{@id}">
<xsl:if test="/shop/current_shop_country_location_city_id = @id">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name" />
</option>
</xsl:template>
<!-- ... -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment