Полезные решения, шпаргалки и примеры по html, css, js, jQuery, MySQL, PHP, HostCMS, ssh.
Созадем файл например observer.php в папке modules/shop/item/ со следующим содержанием:
<?php
defined('HOSTCMS') || exit('HostCMS: access denied.');
class Shop_Item_Observer
{
static public function onBeforeRedeclaredGetXml($object)
{
$oPricesOtherCurrencies = Core::factory('Core_Xml_Entity')->name('prices_other');
$oShop = $object->Shop;
$aShopCurrencies = Core_Entity::factory('Shop_Currency')->findAll();
foreach ($aShopCurrencies as $oShopCurrency)
{
$fCurrencyCoefficient = $object->shop_currency_id > 0 && $oShopCurrency->id > 0
? Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency($object->Shop_Currency, $oShopCurrency)
: 0
;
$oShop_Item_Controller = new Shop_Item_Controller();
$price = $oShop_Item_Controller->getPrice($object);
$oPricesOtherCurrencies->addEntity(
Core::factory('Core_Xml_Entity')
->name('price')
->addEntity(
Core::factory('Core_Xml_Entity')
->name('value')
->value(Shop_Controller::instance()->round($price * $fCurrencyCoefficient))
)
->addEntity($oShopCurrency)
);
}
$object->addEntity($oPricesOtherCurrencies);
}
}
?>
ВНИМАНИЕ: так не учитываются скидки добавленные у товара!
Добавляем наблюдателя или в bootstrap.php или в ТДС Интернет-магазина:
Core_Event::attach('shop_item.onBeforeRedeclaredGetXml', array('Shop_Item_Observer', 'onBeforeRedeclaredGetXml'));
В итоге в XML в узде shop_item у нас появится следующее:
...
<prices_other>
<price>
<value>43244.82</value>
<shop_currency id="1">
<name>руб.</name>
<code>RUR</code>
<exchange_rate>1.000000</exchange_rate>
<date>2015-12-09</date>
<default>1</default>
<sorting>10</sorting>
<user_id>19</user_id>
</shop_currency>
</price>
<price>
<value>574.22</value>
<shop_currency id="2">
<name>€</name>
<code>EUR</code>
<exchange_rate>75.311100</exchange_rate>
<date>2015-12-09</date>
<default>0</default>
<sorting>20</sorting>
<user_id>19</user_id>
</shop_currency>
</price>
<price>
<value>624.00</value>
<shop_currency id="3">
<name>$</name>
<code>USD</code>
<exchange_rate>69.302600</exchange_rate>
<date>2015-12-09</date>
<default>0</default>
<sorting>30</sorting>
<user_id>19</user_id>
</shop_currency>
</price>
</prices_other>
...