Чтобы при оформлении заказа на странице «Адрес доставки» по умолчанию выбирались требуемые значения необходимо:
Интернет-магазин корзина на шаге 1 после создания объекта Shop_Address_Controller_Show добавить следующий код, который выведет в XML необходимые данные:<?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) ); } } } }
Переменные $defaultLocation и $defaultCity задают область и город по умолчанию.
МагазинАдресДоставки добавить код для вывода областей и городов в выпадающих списках, если такой отстуствует в шаблоне:<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>