Skip to content

Instantly share code, notes, and snippets.

//плагин на событие 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;
<?php
/**
Класс оплаты в кредит или рассрочку для Тинькофф
*/
require_once MODX_CORE_PATH . 'components/minishop2/model/minishop2/mspaymenthandler.class.php';
class Tinkoff extends msPaymentHandler implements msPaymentInterface{
public $demo;
@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};
@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 / 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 / main.tpl
Last active May 15, 2021 16:15
tagger выводим товары привязанные к alias тегам
{set $par = $_modx->resource.parent | url}
{set $getTag = $_modx->resource.id | url | replace : $par : ''}
{set $parents = $_modx->resource.parent}
{*Находим шаблон родителя*}
{set $parentTemplate = $parents | resource: 'template'}
{*Если это тег, значит поднимаемся выше для получения родителя*}
{if $parentTemplate == 27}
{set $parents = $parents | resource: 'parent'}
@Sentinel-7
Sentinel-7 / catalog.tpl
Created May 15, 2021 16:26
Выборка для mFilter2 если нужно сделать фильтрацию для ресурсов по url
Список ресурсов сделан списком и выведен через процессор в msFieldsManager для свойств товара
'optionFilters' => '{ "collection:!=":"" }',
'where' => ['collection.value' => $_modx->resource.pagetitle],
@Sentinel-7
Sentinel-7 / file.php
Created May 18, 2021 06:48
Пересохранить все товары в console
<?php
$resources = $modx->getCollection('modResource', [
'class_key' => 'msProduct'
]);
foreach ($resources as $res) {
$res->save();
}
@Sentinel-7
Sentinel-7 / main.tpl
Created May 27, 2021 13:02
youtube-background
{set $main = $_modx->resource.main | fromJSON}
<div data-youtube="{$main[0]['url']}"></div>
<script src="/assets/js/youtube-background.js"></script>
<script>
jQuery(document).ready(function() {
jQuery('[data-youtube]').youtube_background();
});
</script>
@Sentinel-7
Sentinel-7 / main.tpl
Created June 1, 2021 17:09
Получаем вчерашнюю дату fenom
{set $time = '' | date_format : "%s" - (24*60*60)}
{$time | date_format : "%b %d, %Y"}
или сниппет
<?php
$yesterday = date('F j, Y', time()-86400);
return $yesterday;