skip to content
KAD::Wiki
User Tools
Log In
Site Tools
Search
Tools
Show page
Old revisions
Log In
>
You are here:
Приветствие
»
Для сотрудников
»
Разработка
»
HostCMS
»
Статьи (по модулям)
»
Интернет-магазин
»
Полезные решения
»
Область и город по умолчанию при оформлении заказа
private:koding:hostcms:modules:shop:useful:default-location
Media Files
====== Область и город по умолчанию при оформлении заказа ====== Чтобы при оформлении заказа на странице «Адрес доставки» по умолчанию выбирались требуемые значения необходимо: - В ТДС ''Интернет-магазин корзина'' на шаге 1 после создания объекта ''Shop_Address_Controller_Show'' добавить следующий код, который выведет в XML необходимые данные:<code php> <?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) ); } } } } </code>Переменные ''$defaultLocation'' и ''$defaultCity'' задают область и город по умолчанию. - Затем в XSL шаблоне ''МагазинАдресДоставки'' добавить код для вывода областей и городов в выпадающих списках, если такой отстуствует в шаблоне:<code xsl> <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> </code>... и сами шаблоны (также при отсутствии):<code xsl><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> </code>
Save
Preview
Cancel
Edit summary
private/koding/hostcms/modules/shop/useful/default-location.1447142114.txt.gz
· Last modified: 10.11.15 в 10:55 by
maximzasorin_gmail.com
Page Tools
Show page
Old revisions
Export to PDF
Rename Page
Back to top