Last active
August 16, 2024 09:06
-
-
Save andrei99/a024c8d87ff96f8474ad1598aa05df30 to your computer and use it in GitHub Desktop.
d7 bitrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\Bitrix\Main\Diag\Debug::writeToFile($signatureValue, '$signatureValue', '__#params_1.log'); | |
//php 8.1 | |
https://www.sng-it.ru/snippet/oshibki-pri-perekhode-sayta-na-bitrikse-na-php-8-1.html | |
//платежка | |
https://g-rain-design.ru/blog/posts/payment-handlers-bitrix-d7/ | |
//скорость выполнения скрипта | |
$time_start = microtime(true); | |
sleep(2); | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo "Ничего не делал $time секунд\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//no component | |
<?\Bitrix\Main\Page\Frame::getInstance()->startDynamicWithID("area_favorites_list"); ?> | |
Контент | |
<? \Bitrix\Main\Page\Frame::getInstance()->finishDynamicWithID("area_favorites_list", ""); ?> | |
//component | |
<? $frame = $this->createFrame(); ?> | |
<? $frame->begin(); ?> | |
Контент | |
<? $frame->beginStub(); ?> | |
Заглушка | |
<? $frame->end(); ?> | |
<? $frame = $this->createFrame()->begin() ?> | |
без заглушки | |
<? $frame->end() ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Bitrix\Sale; | |
use Bitrix\Main\Loader; | |
Loader::includeModule("sale"); | |
$basket = \Bitrix\Sale\Basket::loadItemsForFUser( | |
\Bitrix\Sale\Fuser::getId(), | |
\Bitrix\Main\Context::getCurrent()->getSite() | |
); // текущая корзина | |
$fuser = new \Bitrix\Sale\Discount\Context\Fuser($basket->getFUserId(true)); | |
$discounts = \Bitrix\Sale\Discount::buildFromBasket($basket, $fuser); | |
$discounts->calculate(); | |
$result = $discounts->getApplyResult(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use \Bitrix\Main\Application; | |
$context = Application::getInstance()->getContext(); | |
$request = $context->getRequest(); | |
?> | |
<?if ($request->isAjaxRequest()): | |
$APPLICATION->RestartBuffer(); | |
$APPLICATION->FinalActions(); | |
endif;?> | |
//content | |
<? if ($request->isAjaxRequest()): | |
die(); | |
endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arParams = array( | |
'select' => array( | |
'ID', | |
'USER_ID', | |
'ACCOUNT_NUMBER' | |
), | |
'filter' => array( | |
'=PROPERTY_VAL.CODE' => 'IS_MOBILE_APP', | |
'=PROPERTY_VAL.VALUE' => 'Y', | |
'=PROPERTY_VAL_2.CODE' => 'PUSHED', | |
'=PROPERTY_VAL_2.VALUE' => 'N', | |
'PAYED' => 'N', | |
'<=DATE_INSERT' => date($DB->DateFormatToPHP(\CSite::GetDateFormat('FULL')), strtotime('+20 minutes')) | |
), | |
'runtime' => array( | |
new ReferenceField( | |
'PROPERTY_VAL', | |
'\Bitrix\sale\Internals\OrderPropsValueTable', | |
["=this.ID" => "ref.ORDER_ID"], | |
["join_type" => "left"] | |
), | |
new ReferenceField( | |
'PROPERTY_VAL_2', | |
'\Bitrix\sale\Internals\OrderPropsValueTable', | |
["=this.ID" => "ref.ORDER_ID"], | |
["join_type" => "left"] | |
), | |
), | |
'order' => array('ID' => 'desc') | |
); | |
$arOrder = \Bitrix\Sale\Order::getList($arParams)->fetchAll(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arFieldsPrice = Array( | |
"PRODUCT_ID" => $arElement["ID"], | |
"CATALOG_GROUP_ID" => $id, | |
"PRICE" => $price, | |
"CURRENCY" => !$currency ? "RUB" : $currency, | |
); | |
$dbPrice = \Bitrix\Catalog\Model\Price::getList([ | |
"filter" => array( | |
"PRODUCT_ID" => $arElement["ID"], | |
"CATALOG_GROUP_ID" => $id | |
)]); | |
if ($arPrice = $dbPrice->fetch()) { | |
$result = \Bitrix\Catalog\Model\Price::update($arPrice["ID"], $arFieldsPrice); | |
if ($result->isSuccess()) | |
{ | |
echo "Обновили цену у товара у элемента каталога " . $arElement["ID"] . " Цена " . $price . PHP_EOL; | |
} | |
else { | |
echo "Ошибка обновления цены у товара у элемента каталога " . $arElement["ID"] . " Ошибка " . $result->getErrorMessages() . PHP_EOL; | |
} | |
}else{ | |
$result = \Bitrix\Catalog\Model\Price::add($arFieldsPrice); | |
if ($result->isSuccess()) | |
{ | |
echo "Добавили цену у товара у элемента каталога " . $arElement["ID"] . " Цена " . $price . PHP_EOL; | |
} | |
else { | |
echo "Ошибка добавления цены у товара у элемента каталога " . $arElement["ID"] . " Ошибка " . $result->getErrorMessages() . PHP_EOL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://estrin.pw/bitrix-d7-snippets/s/url/ | |
$path = $uri->getPath(); // путь, например "/path/to/page.php" | |
$query = $uri->getQuery(); // строка параметров, например, "param1=value1¶m2=value2" | |
parse_str($uri->getQuery(), $params); // так можно разбить строку параметров на массив вида array("param1" => "value1","param2" => "value2"); | |
$port = $uri->getPort(); // порт, например, 80 | |
$scheme = $uri->getScheme(); // протокол, например, "http" | |
$pathQuery = $uri->getPathQuery(); // строка параметров со знаком вопроса, например, "?param1=value1¶m2=value2"; | |
$host = $uri->getHost(); // домен, например, "site.com" | |
$fragment = $uri->getFragment(); // то, что находится после знака "#" | |
$user = $uri->getUser(); // имя пользователя | |
$pass = $uri->getPass(); // пароль |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//задать не редактируемое свойство в заказе | |
$order = Sale\Order::load(8801); | |
$order->setFieldNoDemand('PAYED', "Y"); | |
$order->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$res = CCatalogProductSet::getList( | |
array(), | |
array( | |
'TYPE' => CCatalogProductSet::TYPE_SET, | |
'ITEM_ID' => 141367 | |
), | |
false, | |
false, | |
array('OWNER_ID') | |
); | |
while ($arFields = $res->GetNext()) { | |
$arData[] = $arFields['OWNER_ID']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
catalog.element | |
"SET_VIEWED_IN_COMPONENT" => "Y" | |
use \Bitrix\Catalog\CatalogViewedProductTable as CatalogViewedProductTable; | |
CatalogViewedProductTable::refresh($arResult["ID"], CSaleBasket::GetBasketUserID()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment