Last active
March 20, 2017 08:18
-
-
Save maximzasorin/226cf05d4650a809ae7b to your computer and use it in GitHub Desktop.
Обработчик типа доставки для реализации пунктов вывоза (HostCMS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Обработчик доставки для пунктов выдачи интернет-магазина. | |
*/ | |
class Shop_Delivery_HandlerXXX extends Shop_Delivery_Handler | |
{ | |
/** | |
* Возврвщает список пунктов выдачи для заданных параметров доставки. | |
* | |
* @return array | |
*/ | |
public function execute() | |
{ | |
$shopDeliveryId = str_replace('Shop_Delivery_Handler', '', get_class($this)); | |
$countryId = $this->_shopCountry->id; | |
$locationId = $this->_shopLocation->id; | |
$cityId = $this->_shopCity->id; | |
// Находим условия доставки по заданным параметрам | |
$oShopDeliveryConditions = Core_Entity::factory('Shop_Delivery_Condition'); | |
$oShopDeliveryConditions->queryBuilder() | |
->where('shop_delivery_id', '=', $shopDeliveryId) | |
// Адрес | |
->where('shop_country_id', '=', $countryId) | |
->where('shop_country_location_id', '=', $locationId) | |
->where('shop_country_location_city_id', '=', $cityId) | |
// Вес | |
->where('min_weight', '<=', $this->_weight) | |
->open() | |
->where('max_weight', '>=', $this->_weight) | |
->setOr() | |
->where('max_weight', '=', 0) | |
->close() | |
// Сортировка | |
->orderBy(Core_QueryBuilder::expression('IF ( `min_weight` > 0 AND `max_weight` > 0 AND `min_price` > 0 AND `max_price` > 0, 1, 0)'), 'DESC') | |
->orderBy('min_weight', 'DESC') | |
->orderBy('max_weight', 'DESC') | |
->orderBy('min_price', 'DESC') | |
->orderBy('max_price', 'DESC') | |
->orderBy('price', 'DESC') | |
->where('active', '=', 1) | |
; | |
$aoShopDeliveryConditions = $oShopDeliveryConditions->findAll(); | |
// Возвращаем условия доставки | |
$aRetObjs = array(); | |
foreach ($aoShopDeliveryConditions as $oShopDeliveryCondition) | |
{ | |
$oCurrentDeliveryType = new StdClass(); | |
$oCurrentDeliveryType->description = $oShopDeliveryCondition->name; | |
$oCurrentDeliveryType->price = $oShopDeliveryCondition->price; | |
$aRetObjs[] = $oCurrentDeliveryType; | |
} | |
return $aRetObjs; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:template match="shop_delivery"> | |
<xsl:variable name="shop_delivery_id" select="@id" /> | |
<!-- Доставки с таким идентификатором --> | |
<xsl:variable name="shop_delivery_with_id" select="../shop_delivery[@id = $shop_delivery_id]" /> | |
<xsl:variable name="shop_delivery_count_pickpoints" select="count($shop_delivery_with_id[not(shop_delivery_condition/name/node())])" /> | |
<xsl:variable name="shop_delivery_with_pickpoint" select="$shop_delivery_count_pickpoints > 0" /> | |
<!-- Не выводились доставки с таким идентификатором --> | |
<xsl:if test="count(preceding::shop_delivery[@id = $shop_delivery_id]) = 0"> | |
<tr> | |
<td class="cell-metod"> | |
<input class="forms__check" type="radio" id="{shop_delivery_condition/@id}" value="{shop_delivery_condition/@id}" name="shop_delivery_condition_id"> | |
<xsl:if test="position() = 1"> | |
<xsl:attribute name="checked">checked</xsl:attribute> | |
</xsl:if> | |
</input> | |
<label class="forms__label forms__label-radio" for="{shop_delivery_condition/@id}"><xsl:value-of select="name"/></label> | |
<!-- --> | |
<xsl:if test="$shop_delivery_with_pickpoint"> | |
<div> | |
<xsl:attribute name="class"> | |
<xsl:text>shop-delivery</xsl:text> | |
<xsl:if test="$shop_delivery_count_pickpoints > 1"> shop-delivery_hidden</xsl:if> | |
</xsl:attribute> | |
<xsl:choose> | |
<xsl:when test="$shop_delivery_count_pickpoints > 1"> | |
<select name="shop_delivery_condition_pickpoint_id" class="shop-delivery__select"> | |
<xsl:apply-templates select="../shop_delivery[@id = $shop_delivery_id]" mode="pickpoint" /> | |
</select> | |
</xsl:when> | |
<xsl:when test="$shop_delivery_count_pickpoints = 1"> | |
<div class="shop-delivery_single"> | |
<xsl:value-of select="shop_delivery_condition/description" /> | |
</div> | |
</xsl:when> | |
</xsl:choose> | |
</div> | |
</xsl:if> | |
</td> | |
<td class="text-left"> | |
<xsl:value-of disable-output-escaping="yes" select="description"/> | |
</td> | |
<td> | |
<xsl:value-of select="format-number(shop_delivery_condition/price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="/shop/shop_currency/name"/> | |
</td> | |
<td> | |
<xsl:value-of select="format-number(/shop/total_amount, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="/shop/shop_currency/name"/> | |
</td> | |
<td> | |
<xsl:value-of select="format-number(/shop/total_amount + shop_delivery_condition/price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="/shop/shop_currency/name"/> | |
</td> | |
</tr> | |
</xsl:if> | |
</xsl:template> | |
<xsl:template match="shop_delivery" mode="pickpoint"> | |
<xsl:variable name="price"> | |
<xsl:value-of select="format-number(shop_delivery_condition/price, '### ##0,00', 'my')" /><xsl:text> </xsl:text><xsl:value-of select="/shop/shop_currency/name"/> | |
</xsl:variable> | |
<option value="{shop_delivery_condition/@id}" data-price="{$price}"> | |
<xsl:value-of select="shop_delivery_condition/description" /> | |
</option> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment