Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / scripts.js
Last active April 2, 2016 13:44
For bitrix ajax add to cart action
//Добавить товар в корзину
$(document).on('click', '.pi__order-bucket, .tovar__bucket, .item-found__bucket', function(e){
e.preventDefault();
var id = $(this).data('id'),
price = $(this).data('price'),
name = $(this).data('name'),
count = $('.product2cart_count_'+id).text(),
src = $('.product2cart_img_'+id).attr('src'),
bg = ($('.product2cart_img_'+id).hasClass('empty') ? "#fff url("+src+")" : "url("+src+") no-repeat center");
@d1i1m1o1n
d1i1m1o1n / template.php
Last active April 2, 2016 13:41
Bitrix add product to last viewed
//добавление товара в просмотренные
CModule::IncludeModule("sale");
use \Bitrix\Catalog\CatalogViewedProductTable as CatalogViewedProductTable;
$user_id = CSaleBasket::GetBasketUserID();
if($user_id > 0) {
$product_id = $arResult['ID'];
CatalogViewedProductTable::refresh($product_id, $user_id);
}
@d1i1m1o1n
d1i1m1o1n / index.php
Created November 14, 2015 21:34
Bitrix smart search filter
<?
$GLOBALS['arrFilter'] = Array();
foreach (explode(' ', $_REQUEST["q"]) as $key => $value) {
$GLOBALS['arrFilter'][] = array(
"LOGIC" => "OR",
array("NAME" => "%$value%"),
array("DETAIL_TEXT"=>"%$value%"),
array("PREVIEW_TEXT"=>"%$value%")
);
}
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 14, 2015 22:28
PHP highlight words in text
foreach (explode(' ', $_REQUEST["q"]) as $key => $value) {
$arItem["NAME"] = preg_replace('/'.$value.'/iu', '<span class="search-term">\\0</span>', $arItem["NAME"]);
$arItem["PREVIEW_TEXT"] = preg_replace('/'.$value.'/iu', '<span class="search-term">\\0</span>', $arItem["PREVIEW_TEXT"]);
}
@d1i1m1o1n
d1i1m1o1n / init.php
Created November 15, 2015 09:07
Bitrix detect mobile devices and enable mobile template and redirect to mobile folder
<?
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
//define('siteType', 'dev');
//Определяем мобильные устройства библиотекой http://mobiledetect.net/
require_once 'include/Mobile_Detect.php';
$detect = new Mobile_Detect;
//Все мобилные устройства кроме планшетов
if( $detect->isMobile() && !$detect->isTablet() ){
@d1i1m1o1n
d1i1m1o1n / scripts.js
Created November 15, 2015 12:10
Bootstrap 3 multiple modal dialogs fix scroll
$(document).on('hidden.bs.modal', '.modal', function () {
$('.modal:visible').length && $(document.body).addClass('modal-open');
});
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 15, 2015 16:03
Bitrix template of component news.list. Print prev next page navigation.
<nav class="catalog__nav">
<?if(($arResult["NAV_RESULT"]->PAGEN - 1) > 0):?>
<a href="?PAGEN_1=<?=($arResult["NAV_RESULT"]->PAGEN - 1);?>" class="catalog__nav-active">← Предыдущая</a>
<?else:?>
<a href="#">← Предыдущая</a>
<?endif;?>
<?if(($arResult["NAV_RESULT"]->PAGEN + 1) <= $arResult["NAV_RESULT"]->NavPageCount):?>
<a href="?PAGEN_1=<?=($arResult["NAV_RESULT"]->PAGEN + 1);?>" class="catalog__nav-active">Следующая →</a>
<?else:?>
<a href="#">Следующая →</a>
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 15, 2015 20:08
Bitrix add product to viewed list
//добавление товара в просмотренные
use \Bitrix\Catalog\CatalogViewedProductTable as CatalogViewedProductTable;
$user_id = CSaleBasket::GetBasketUserID();
if($user_id > 0) {
$product_id = $arResult['ID'];
CatalogViewedProductTable::refresh($product_id, $user_id);
}
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 15, 2015 21:12
Bitrix print price with discount
<?if($arResult["PRICE"]["DISCOUNT_PRICE"] < $arResult["PRICE"]["RESULT_PRICE"]["BASE_PRICE"]):?>
<p class="tovar__price">Цена без скидки: <del><?=str_replace('.', ',', $arResult["PRICE"]["RESULT_PRICE"]["BASE_PRICE"])?></del> руб.</p>
<p class="tovar__price">Цена со скидкой: <span><?=str_replace('.', ',', $arResult["PRICE"]["DISCOUNT_PRICE"])?></span> руб.</p>
<p class="tovar__price--discount">Скидка: <span><?=str_replace('.', ',', $arResult["PRICE"]["RESULT_PRICE"]["DISCOUNT"])?> руб. (<?=$arResult["PRICE"]["RESULT_PRICE"]["PERCENT"]?>%)</span></p>
<?else:?>
<p class="tovar__price">Цена: <span><?=str_replace('.', ',', $arResult["PRICE"]["DISCOUNT_PRICE"])?></span> руб.</p>
<?endif;?>
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 15, 2015 21:51
Bitrix rating (voite) in template
<?$APPLICATION->IncludeComponent(
"bitrix:iblock.vote",
"ajax",
Array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ELEMENT_ID" =>$arResult["ID"],
"MAX_VOTE" => $arParams["MAX_VOTE"],
"VOTE_NAMES" => $arParams["VOTE_NAMES"],
"CACHE_TYPE" => $arParams["CACHE_TYPE"],