alexpimnev писал(а):
shop_item.onBeforeSelectModifications
Спасибо за подсказку. Вроде заработало.
static public function onBeforeSelectModifications($object, $args)
{
// Получаем список валют магазина
$aShop_Currencies = Core_Entity::factory('Shop_Currency')->findAll();
$query_tax = 'IF(`shop_taxes`.`tax_is_included`, 0, `shop_items`.`price` * `shop_taxes`.`rate` / 100)';
$query_currency_switch = "`shop_items`.`price` + {$query_tax}";
foreach ($aShop_Currencies as $oShop_Currency)
{
// Получаем коэффициент пересчета для каждой валюты
$currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$oShop_Currency, $object->Shop->Shop_Currency
);
$query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (COUNT(`shop_discounts`.`id`), ((`shop_items`.`price` + {$query_tax}) * (1 - SUM(IF(`shop_discounts`.`type` = 0, `shop_discounts`.`value`, 0)) / 100)) * {$currency_coefficient} - SUM(IF(`shop_discounts`.`type`, `shop_discounts`.`value`, 0)), (`shop_items`.`price`) * {$currency_coefficient}), {$query_currency_switch})";
}
$current_date = date('Y-m-d H:i:s');
$args[0]->queryBuilder()
->select('shop_items.*')
->select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price'))
->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id')
->leftJoin('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
array('AND ' => array('shop_discounts.active', '=', 1)),
array('AND ' => array('shop_discounts.deleted', '=', 0)),
array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00')),
array(')' => NULL)
))
->leftJoin('shop_taxes', 'shop_taxes.id', '=', 'shop_items.shop_tax_id')
->groupBy('shop_items.id')
->clearOrderBy()
->orderBy('absolute_price', 'ASC');
}
if ($Shop_Controller_Show->item)
{
Core_Event::attach('shop_item.onBeforeSelectModifications', array('Shop_Item_Observer', 'onBeforeSelectModifications'));
}