Skip to content

Instantly share code, notes, and snippets.

@golubev-alex
Last active May 24, 2024 11:44
Show Gist options
  • Save golubev-alex/bef497830151fe3c83aa597bc9605c1e to your computer and use it in GitHub Desktop.
Save golubev-alex/bef497830151fe3c83aa597bc9605c1e to your computer and use it in GitHub Desktop.
// генерация пароля
\Bitrix\Main\Security\Random::getString(12, true)
// отложенные функции
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=3489
// из той же оперы
https://dev.1c-bitrix.ru/api_help/main/reference/cmain/showviewcontent.php
// проверка не пустая ли выборка
if( $res->SelectedRowsCount() ):
// формат дат
FormatDate("j F Y", MakeTimeStamp($arItem["ACTIVE_FROM"]));
// редирект на нижний регистр
function redirect_to_lowercase($url) {
$admin_url = strpos($url, '/bitrix/');
$rsSites = CSite::GetByID("cr");
$arSite = $rsSites->Fetch();
//$crm_url = strpos($_SERVER["SERVER_NAME"], $arSite["SERVER_NAME"]);
if ($admin_url === false ) { //& $crm_url != 0
$url_data = explode("?", $url);
$url_data_clear = $url_data[0]; // url without params
$url_data_params = $url_data[1]; // params
if ( $url_data_clear != strtolower( $url_data_clear) ) {
if(empty($url_data_params)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER['HTTP_HOST'] . strtolower($url_data_clear));
exit();
}else{
header("HTTP/1.1 301 Moved Permanently");
header('Location: https://' . $_SERVER['HTTP_HOST'] . strtolower($url_data_clear).'?'.$url_data_params);
exit();
}
}
}
}
redirect_to_lowercase($_SERVER['REQUEST_URI']);
// в карточке товара - сумма вместо цены (bitrix.calalog.element)
// script.js
if (this.obPrice.total)
{
if (price && this.obQuantity) // && this.obQuantity.value != this.stepQuantity
{
if(price.BASE_PRICE == price.PRICE){
BX.adjust(this.obPrice.total, {
html: '<div class = "productRightActionsTopPrice-current">'+ BX.Currency.currencyFormat(price.PRICE * this.obQuantity.value, price.CURRENCY, true) +'</div>',
style: {display: ''}
});
} else {
BX.adjust(this.obPrice.total, {
html: '<div class = "productRightActionsTopPrice-current">'+ BX.Currency.currencyFormat(price.PRICE * this.obQuantity.value, price.CURRENCY, true) +'</div><div class = "productRightActionsTopPrice-old">'+ BX.Currency.currencyFormat(price.BASE_PRICE * this.obQuantity.value, price.CURRENCY, true) +'</div>',
style: {display: ''}
});
}
}
// template.pxp (с сохранение ID, иначе цена не обновляется)
<div id="<?=$itemIds['PRICE_TOTAL']?>" class="productRightActionsTop-price">
<? if($actualItem['CAN_BUY']): ?>
<div class="productRightActionsTopPrice-current">
<?= $price['PRINT_RATIO_PRICE'] ?>
</div>
<? if($showDiscount): ?>
<div class="productRightActionsTopPrice-old">
<?=$price['PRINT_RATIO_BASE_PRICE'] ?>
</div>
<? endif; ?>
<!-- без этого не обновляются цены-->
<div style="display: none">
<div id="<?= $itemIds['PRICE_ID'] ?>"></div>
<div id="<?= $itemIds['OLD_PRICE_ID'] ?>"></div>
</div>
// BX AJAX
BX.ajax({
url: '/ajax.php?'+str,
data: {
'Method': 'SubscribeForm',
},
method: 'POST',
dataType: 'json',
onsuccess: function(data){
if(data['status'] == true){
var oPopup = new BX.PopupWindow('call_feedback', window.body, {
autoHide : true,
offsetTop : 1,
offsetLeft : 0,
lightShadow : true,
closeIcon : true,
closeByEsc : true,
});
oPopup.setContent('<font class="notetext">Спасибо! Теперь вы подписаны на наши новости.</font>');
oPopup.show();
}else{
var oPopupEr = new BX.PopupWindow('call_feedback', window.body, {
autoHide : true,
offsetTop : 1,
offsetLeft : 0,
lightShadow : true,
closeIcon : true,
closeByEsc : true,
});
oPopupEr.setContent('<font class="notetext">Произошла ошибка!<br/>' + data['error']+'</font>');
oPopupEr.show();
}
}
});
// закрываем дырки
https://docs.google.com/document/d/1sxw75pUpE3XYDUtQK31j1AjIsecUPSM1oQyTrcuBoIA/edit
// вывод 404 в компонентах (если свой не сработал)
if (defined("ERROR_404")):
define("ERROR_404", "Y");
\CHTTP::setStatus("404 Not Found");
if ($APPLICATION->RestartWorkarea()):
require(\Bitrix\Main\Application::getDocumentRoot() . "/404.php");
die();
endif;
endif;
// ссылки без слэша
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} .+/$ [NC]
RewriteRule ^(.+)(/)$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^.*[^/]$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}/index.php -f
RewriteRule ^(.*)$ /$1/index.php [L]
</IfModule>
<IfModule mod_dir.c>
DirectorySlash Off
</IfModule>
В инфоблоке - убрать конечные слэши
В компоненте - отключить SHOW_404, SET_STATUS_404, конечный слэш в SECTION и DETAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment