Skip to content

Instantly share code, notes, and snippets.

@VSeryoga
VSeryoga / bitrix_basket_props.php
Last active March 14, 2018 11:09
Добавление, изменение св-в товаров в корзине Битриска D7
<?
CModule::IncludeModule("sale");
$order = \Bitrix\Sale\Order::load(25336);
$basket = $order->getBasket();
$basketItem = $basket->getItemById(1890381);
$basketPropertyCollection = $basketItem->getPropertyCollection();
$basketPropertyCollection->setProperty(array(
array(
'NAME' => 'Добавлен в заказ',
@VSeryoga
VSeryoga / bitrix_sections_parents.php
Last active July 19, 2018 10:28
Родительские разделы элемента
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
use Bitrix\Iblock\SectionTable;
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\Loader;
use Bitrix\Main\SystemException;
Loader::includeModule('iblock');
// $elementId = 495982;
// $element = ElementTable::getRow([
@VSeryoga
VSeryoga / yandex_map.js
Created February 15, 2018 08:42
Много меток на Яндекс карте
ymaps.ready(function() {
var mapCenter = [<?=$arResult['ITEMS'][0]['PROPERTIES']['MAP']['VALUE']?>],
map = new ymaps.Map('map_general', {
center: mapCenter,
zoom: 10,
controls: []
});
map.controls.add('routeEditor');
map.controls.add('typeSelector');
map.controls.add('zoomControl');
@VSeryoga
VSeryoga / soap_result_to_array.php
Created February 8, 2018 12:06
Результат SOAP запроса в массив
<?
function soapToArray($soap){
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $soap);
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//SBody')[0];
$array = json_decode(json_encode((array)$body), TRUE);
return $array;
}
@VSeryoga
VSeryoga / url_redirect.php
Created February 7, 2018 14:29
URL редиректа
<?
function redirect($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$a = curl_exec($ch);
if(preg_match('#Location: (.*)#', $a, $r))
$l = trim($r[1]);
@VSeryoga
VSeryoga / func_php.php
Created January 13, 2018 15:40
Где определена функция
<?
$reflFunc = new ReflectionFunction('custom_mail');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
@VSeryoga
VSeryoga / menu.php
Created January 12, 2018 13:17
Битрикс меню
<ul class="menu menu_sub menu_mega">
<?$previousLevel = 0;
foreach ($arResult['CATALOG_SECTIONS'] as $k => $c) {
if ($previousLevel && $c[3]["DEPTH_LEVEL"] < $previousLevel){
echo str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));
}
if($c[3]['IS_PARENT']){
if($c[3]['DEPTH_LEVEL'] == 1){?>
<li class="menu__item"><span class="title"><a href="<?=$c[1]?>"><?=$c[0]?></a></span>
<ul class="menu">
@VSeryoga
VSeryoga / remove_fields_search_bitrix.php
Created November 3, 2017 14:01
Исключить поля из поиска Битрикс
<?
AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
function BeforeIndexHandler($arFields) {
$arrIblock = array(2, 3); //ID инфоблоков, для которых производить модификацию
$arDelFields = array("DETAIL_TEXT" /*, "PREVIEW_TEXT"*/); //стандартные поля, которые нужно исключить
if (CModule::IncludeModule('iblock') && $arFields["MODULE_ID"] == 'iblock' && in_array($arFields["PARAM2"], $arrIblock) && intval($arFields["ITEM_ID"]) > 0){
$dbElement = CIblockElement::GetByID($arFields["ITEM_ID"]);
if ($arElement = $dbElement->Fetch()){
foreach ($arDelFields as $value) {
if (isset ($arElement[$value]) && strlen($arElement[$value])> 0){
@VSeryoga
VSeryoga / redirect.php
Created October 6, 2017 09:15
Редирект redirect Битрикс
<?
AddEventHandler("main", "OnBeforeProlog", Array("MyClass", "MyOnBeforePrologHandler"), 50);
class MyClass
{
function MyOnBeforePrologHandler()
{
// if(strpos($_SERVER['REQUEST_URI'],'/catalog/')!==false){
$old_url = $_SERVER['REQUEST_URI'];
Bitrix\Main\Loader::includeModule("highloadblock");
@VSeryoga
VSeryoga / file_get_contents_post.php
Created October 1, 2017 18:18
Отправка file_get_contents метод post
<?
$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);
$opts = array('http' =>
array(