Skip to content

Instantly share code, notes, and snippets.

@Sentinel-7
Sentinel-7 / main.tpl
Last active May 28, 2021 17:15
Выборка json pdoResources
{set $output = '!pdoResources' | snippet: [
'parents' => '35|bb,39|bb'
'limit' => 0,
'includeTVs' => 'block_image',
'tvPrefix' => '',
'sortby' => '{ "menuindex":"ASC" }',
'where' => '{"parent:IN":[35|bb,39|bb]}',
'return' => 'json',
'select' => 'id,pagetitle,parent'
]}
@Sentinel-7
Sentinel-7 / head.tpl
Last active May 7, 2021 13:38
application/ld+json
BreadcrumbList
Реализуем с помощью стандартного pdoCrumbs
{$_modx->runSnippet('pdoCrumbs',[
'showHome'=> 1,
'showCurrent' => 1,
'from' => '0'
'tplWrapper'=> '@INLINE
<script type="application/ld+json">
@Sentinel-7
Sentinel-7 / delete_old_sessions.php
Created March 31, 2021 07:23 — forked from andronex/delete_old_sessions.php
Удаление старых сессий в таблице MODX посредством плагина, а не настройками PHP.
<?php
/**
на событие OnMODXInit
*/
$rand = rand(1, 1000);
if ($rand === 1) {
$gcMaxlifetime = (integer) $modx->getOption('session_gc_maxlifetime', null, @ini_get('session.gc_maxlifetime'), true);
$access = time() - $gcMaxlifetime;
$modx->exec("
DELETE FROM {$modx->getTableName('modSession')} WHERE `access` < {$access};
<?php
/**
Класс оплаты в кредит или рассрочку для Тинькофф
*/
require_once MODX_CORE_PATH . 'components/minishop2/model/minishop2/mspaymenthandler.class.php';
class Tinkoff extends msPaymentHandler implements msPaymentInterface{
public $demo;
//плагин на событие msOnBeforeAddToCart.
$cartArray = $cart->get(); // Массив корзины
$cartStatus = $cart->status(); // Состояние корзины
$totalCount = $cartStatus['total_count']; // Общее количество товаров в корзине
foreach ($cartArray as &$cartProduct) { // Обрабатываем все товары корзины
if ($product = $modx->getObject('msProduct', $cartProduct['id'])) { // Получаем объект товара по его ID в корзине
$quanity = $product->get('count_prod)';
$cartQuantity = $cartProduct["count"];
if($cartQuantity > $quanity){
$cartProduct['count'] = $quanity;
@Sentinel-7
Sentinel-7 / createUser.php
Created February 12, 2021 15:48 — forked from andronex/createUser.php
Создание юзера и добавление его в группу (hook для FormIt MODX Revolution) - 2 способа + отдельным файлом с запросом Ajax
<?php
$allFormFields = $hook->getValues();
if(is_array($allFormFields)){
foreach($allFormFields as $k => $v){
if (filter_var($v, FILTER_VALIDATE_EMAIL)) {
$mail = trim($v);
}
}
if($mail){
@Sentinel-7
Sentinel-7 / settimeout.js
Last active November 19, 2022 12:51
Отложенная загрузка метрики и скриптов
var loadedMetrica = false;
window.addEventListener('scroll', loadMetrica);
window.addEventListener('click', loadMetrica);
window.addEventListener('mousemove', loadMetrica);
function loadMetrica() {
if (!loadedMetrica) {
setTimeout(function() {
/* ТУТ ВАШ КОД И СКРИПТЫ, метрика например*/
},500);
}
@Sentinel-7
Sentinel-7 / getViewed.php
Last active December 29, 2020 16:51 — forked from shvind/gist:8273223
getViewed - Сниппет вывода просмотренных товаров для minishop2
<?php
$id = $modx->resource->id;
$tpls = explode(',', $modx->getOption('ms2_template_product_default'));
if (!isset($limit)) {$limit = 10;}
if (!isset($tpl)) {$tpl = 'tpl.msProducts.row';}
// Вносим ID просмотренных товаров
if (in_array($modx->resource->template, $tpls)) {
if (!isset($_SESSION['viewed'])) {
@Sentinel-7
Sentinel-7 / taggercustomfilter.class.php
Created December 16, 2020 19:33 — forked from sheronov/taggercustomfilter.class.php
Интеграция компонента Tagger с фильтрами в mFilter2 (компонент mSearch2) - Расширение класса фильтрации через системную настройку mse2_filters_handler_class
<?php
class taggerCustomFilter extends mse2FiltersHandler {
/**
* Retrieves values from Tagger table
*
* @param array $fields
* @param array $ids
*
* @return array
@Sentinel-7
Sentinel-7 / chunk.tpl
Created September 21, 2020 15:27
AjaxForm цели
<button type="submit" onclick="ga('send', 'zakazat_zvonok', '/'); ym(99999,'reachGoal','ostavit_zayavku'); return true;" class="bt_red" style="display: block;">
$(document).on("af_complete", function (event, response) {
var fid = response.form[0].id;
switch (fid) {
case 'question':
case 'online':
case 'modal_form':
case 'regForm':