Your IP : 3.129.23.166
<?php
/**
* Created by PhpStorm.
* User: Yumster
* Date: 26.12.2014
* Time: 19:59
*/
require_once($_SERVER['DOCUMENT_ROOT'].'/local/vendor/autoload.php');
require_once('constants.php');
//-- Добавление обработчика события
AddEventHandler("main", "OnBeforeProlog", array('\Epages\Event\Main\OnBeforeProlog', 'processRedirectRules'));
AddEventHandler("sale", "OnOrderNewSendEmail", "bxModifySaleMails");
if (isset($_SERVER['HTTP_HOST']) && strlen($_SERVER['HTTP_HOST']) > 0) {
$httpHost = $_SERVER['HTTP_HOST'];
} else {
$httpHost = COption::GetOptionString('main', 'server_name', '');
}
if (!defined(MAIN_SITE_URL)) {
define('MAIN_SITE_URL', 'http://klimatlend.ua');
}
if (!defined(MAIN_SITE_EMAIL)) {
define('MAIN_SITE_EMAIL', 'shop@klimatlend.ua');
}
$eventManager = Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('catalog', 'OnGetOptimalPrice', function(
$productId,
$quantity = 1,
$arUserGroups = [],
$renewal = "N",
$arPrices = [],
$siteID = false,
$arDiscountCoupons = false){
AddMessage2Log('P1:'.CPrice::GetBasePrice($productId)["PRICE"].' P2: ');
// $arPrice = CCatalogProduct::GetOptimalPrice($productId, $quantity, $arUserGroups, $renewal);
// AddMessage2Log('AAR:'.print_r($arPrice));
if($_SESSION["PRIVATBANK_PAYTYPE"]=="pp") {
$month = $_SESSION["PRIVATBANK_PAY_PERIOD"];
$price = round(getKreditPrice($productId,$month,$_SESSION["PRIVATBANK_KREDIT3"]));
$_SESSION["PRIVATBANK_PAY_PRICE"] = $price;
Bitrix\Main\Diag\Debug::dumpToFile("P:".$price, $varName = "$productId", $fileName = "/log.txt");
return [
'PRICE' => [
"ID" => $productId,
'PRICE' => $price,
'CURRENCY' => \Bitrix\Currency\CurrencyManager::getBaseCurrency(),
'ELEMENT_IBLOCK_ID' => $productId,
'VAT_INCLUDED' => "Y",
],
];
}else{
$dbPrice = CPrice::GetList(
array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"),
array("PRODUCT_ID" => $productId),
false,
false,
array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")
);
while ($arPrice = $dbPrice->Fetch()) {
$arDiscounts = CCatalogDiscount::GetDiscountByPrice(
$arPrice["ID"],
$arUserGroups,
"N",
$siteID
);
$discountPrice = CCatalogProduct::CountPriceWithDiscount(
$arPrice["PRICE"],
$arPrice["CURRENCY"],
$arDiscounts
);
$arPrice["DISCOUNT_PRICE"] = $discountPrice;
// AddMessage2Log('AAR: <pre>'.print_r($arPrice)."</pre>");
}
return true;
}
});
//-- Не знаю зачем эта штука, думаю она здесь лишняя
//-- define('IBLOCK_ID', 'http://'.str_replace(':80', '', $httpHost));
//-- Собственно обработчик события
function bxModifySaleMails(
$orderID, &$eventName, &$arFields)
{
$arOrder = CSaleOrder::GetByID($orderID);
//-- получаем телефоны и адрес
$order_props = CSaleOrderPropsValue::GetOrderProps($orderID);
$phone="";
$index = "";
$country_name = "";
$city_name = "";
$address = "";
while ($arProps = $order_props->Fetch())
{
if ($arProps["CODE"] == "PHONE")
{
$phone = htmlspecialchars($arProps["VALUE"]);
}
if ($arProps["CODE"] == "LOCATION")
{
$arLocs = CSaleLocation::GetByID($arProps["VALUE"]);
$country_name = $arLocs["COUNTRY_NAME_ORIG"];
$city_name = $arLocs["CITY_NAME_ORIG"];
}
if ($arProps["CODE"] == "INDEX")
{
$index = $arProps["VALUE"];
}
if ($arProps["CODE"] == "ADDRESS")
{
$address = $arProps["VALUE"];
}
}
$full_address = $index.", ".$country_name."-".$city_name.", ".$address;
//-- получаем название службы доставки
$arDeliv = CSaleDelivery::GetByID($arOrder["DELIVERY_ID"]);
$delivery_name = "";
if ($arDeliv)
{
$delivery_name = $arDeliv["NAME"];
}
//-- получаем название платежной системы
$arPaySystem = CSalePaySystem::GetByID($arOrder["PAY_SYSTEM_ID"]);
$pay_system_name = "";
if ($arPaySystem)
{
$pay_system_name = $arPaySystem["NAME"];
}
//-- добавляем новые поля в массив результатов
$arFields["ORDER_DESCRIPTION"] = $arOrder["USER_DESCRIPTION"];
$arFields["PHONE"] = $phone;
$arFields["DELIVERY_NAME"] = $delivery_name;
$arFields["PAY_SYSTEM_NAME"] = $pay_system_name;
$arFields["FULL_ADDRESS"] = $full_address;
}
AddEventHandler("main", "OnBeforeProlog", "OnBeforePrologHandler", 50);
function OnBeforePrologHandler()
{
global $APPLICATION;
if ($_REQUEST["city"]) {
$canonical = $APPLICATION->GetCurPageParam("", array("city"));
$APPLICATION->SetPageProperty('canonical', $canonical);
}
}
if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/functions.php")) {
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/functions.php");
}
AddEventHandler("main", "OnAfterUserAdd", 'SetUserDiscountGroup');
function SetUserDiscountGroup(&$arFields)
{
if ($arFields["ID"] > 0) {
$cUser = new CUser;
$sort_by = "ID";
$sort_ord = "ASC";
$arFilter = array(
"ID" => $arFields['ID'],
);
$dbUsers = $cUser->GetList($sort_by, $sort_ord, $arFilter, array('SELECT' => array('ID', 'NAME', 'UF_DISCOUNT_COUPON', 'GROUP_ID')));
if ($arUser = $dbUsers->Fetch()) {
if (strlen($arUser['UF_DISCOUNT_COUPON']) > 0) {
try {
$couponUsed = Epages\DiscountCoupons::getCouponStatus($arUser['UF_DISCOUNT_COUPON']);
if ($couponUsed == 'N') {
$group = new CGroup();
$user = new CUser;
$arGroups = array(3, 4, 7);
//add new group for use
$rsGroups = $group->GetList($by = "c_sort", $order = "asc", array("STRING_ID" => 'discount-coupons'));
$groupData = $rsGroups->Fetch();
if (count($groupData) > 0) {
$arGroups[] = $groupData['ID'];
}
//update user groups
$fields = array(
"GROUP_ID" => $arGroups,
);
$user->Update($arFields['ID'], $fields);
//set coupon as used
Epages\DiscountCoupons::setCouponAsUsed($arUser['UF_DISCOUNT_COUPON']);
}
} catch (Exception $e) {
AddMessage2Log($e->getMessage());
}
}
}
}
}
/**
* Returns Iblock ID by it's code
*
* @param $iblockCode
* @return bool
*/
function getIblockIdByCode($iblockCode)
{
$cache = new CPHPCache;
$cache_time = 3600;
$cache_id = 'get_id_'.$iblockCode;
if ($cache->InitCache($cache_time, $cache_id, '/'.SITE_ID.'/iblock/helper/')) {
$arVars = $cache->GetVars();
return $arVars['DATA']['ID'];
} else {
$cache->StartDataCache($cache_time, $cache_id);
$arIblock = \Bitrix\Iblock\IblockTable::getList([
'filter' => ['CODE' => $iblockCode],
'select' => ['ID']
])->fetch();
if ($arIblock) {
$cache->EndDataCache(['DATA' => $arIblock]);
return $arIblock['ID'];
} else {
return false;
}
}
}
function isCategoryChildForProm($id){
$nav = CIBlockSection::GetNavChain(false,$id);
while($arSectionPath = $nav->GetNext()){
if ( $arSectionPath["ID"] == 228 ){
return true;
}
}
return false;
}
function pre1($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
AddEventHandler(
'iblock',
'OnAfterIBlockElementAdd',
array('\Epages\Event\IBlock\UpdatePrice', 'updateDiscountPriceType')
);
AddEventHandler(
'iblock',
'OnAfterIBlockElementUpdate',
array('\Epages\Event\IBlock\UpdatePrice', 'updateDiscountPriceType')
);
AddEventHandler(
'iblock',
'OnBeforeIBlockElementUpdate',
array('\Epages\Event\IBlock\Handlers', 'OnBeforeIBlockElementUpdateHandler')
);
AddEventHandler(
'iblock',
'OnStartIBlockElementAdd',
array('\Epages\Event\IBlock\Handlers', 'OnBeforeIBlockElementAddHandler')
);
AddEventHandler(
'iblock',
'OnBeforeIBlockElementDelete',
array('\Epages\Event\IBlock\Handlers', 'OnBeforeIBlockElementDeleteHandler')
);
AddEventHandler(
'main',
'OnBuildGlobalMenu',
array('\Epages\Event\Menu\OnBuildGlobalMenu', 'OnBuildGlobalMenuHandler')
);
AddEventHandler(
'iblock',
'OnBeforeIBlockElementUpdate',
array('\Epages\Event\IBlock\Handlers', 'doNotDeactivatedSection')
);
AddEventHandler(
'iblock',
'OnAfterIBlockElementAdd',
array('\Epages\Event\IBlock\Handlers', 'doNotDeactivatedSection')
);
AddEventHandler(
'catalog',
'OnProductAdd',
array('Epages\OnProductAddUpdate', 'setMinPrice')
);
AddEventHandler(
'catalog',
'OnProductUpdate',
array('Epages\OnProductAddUpdate', 'setMinPrice')
);
function getKreditPrice($productID, $month,$kredit3)
{
$partsK = array(
1 => 1,
2 => 1.016,
3 => 1.026,
4 => 1.049,
5 => 1.078,
6 => 1.102,
7 => 1.134,
8 => 1.161,
9 => 1.190,
10 => 1.205,
11 => 1.212,
12 => 1.220,
13 => 1.243,
14 => 1.268,
15 => 1.293,
16 => 1.319,
17 => 1.337,
18 => 1.366,
19 => 1.385,
20 => 1.415,
21 => 1.436,
22 => 1.469,
23 => 1.492,
24 => 1.515,
25 => 1.551
);
CModule::IncludeModule('sale');
$productPrice = CPrice::GetBasePrice($productID)["PRICE"];
if($kredit3=="Y" && ( $month==3 || $month==2 )){
$specialPrice = $productPrice ;
}else{
$specialPrice = $productPrice * $partsK[$month];
}
return $specialPrice;
}