Skip to content

Instantly share code, notes, and snippets.

@crystaldaking
crystaldaking / gist:503adf2afdb264f4a966d44dce4f3d19
Created December 20, 2019 09:53
перегенировать uri modx
<?php
$q = $modx->newQuery('modResource', array(
'parent:IN' => array(0), // Перечисляем id разделов, если надо, но если документов не очень много, то можно с корня
));
// Это условие указывает поиск только документов без uri
$q->andCondition(array(
'uri' => null,
'OR:uri:=' => '',
));
//плагин на событие 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;
@pavel-one
pavel-one / plugin.php
Created April 30, 2018 16:01
MODX Extjs Интересные методы
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnDocFormPrerender':
// Для ресурсов с индетификатором шаблона 2
// а также для всех новых ресурсов ( $resource == null )
if( $resource && $resource->get('template') == 2 || !$resource){
$modx->regClientStartupHTMLBlock('<script>
Ext.onReady(function() {
@andronex
andronex / delete_old_sessions.php
Created October 2, 2017 20:33
Удаление старых сессий в таблице MODX посредством плагина, а не настройками PHP.
<?php
$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};
OPTIMIZE TABLE {$modx->getTableName('modSession')};
");
$modx->log(modX::LOG_LEVEL_ERROR, 'clearOldSessions: old sessions have been removed.');
@OlegShchavelev
OlegShchavelev / index.js
Last active December 22, 2020 00:57
Стоимость доставки отдельной строкой в Minishop2 (после </body>)
<script>
miniShop2.Order.deliveryCost = '#ms2_delivery_cost';
miniShop2.Callbacks.Order.getcost.response.success = function(response) {
var rdc = response.data['delivery_cost'];
if(rdc) $(miniShop2.Order.deliveryCost, miniShop2.Order.order).text(miniShop2.Utils.formatPrice(rdc));
else $(miniShop2.Order.deliveryCost, miniShop2.Order.order).text('0');
}
@davidpede
davidpede / xpdo-where
Last active February 5, 2025 16:24
pdoResources where examples
&where=`{ "template:IN" : [ 1,2,3 ] }
&where=`{ "template:NOT IN" : [ 1,2,3 ] }
&where=`[{"alias:LIKE":"foo%", "OR:alias:LIKE":"%bar"},{"OR:pagetitle:=":"foobar", "AND:description:=":"raboof"}]`
@cod3cow
cod3cow / svg.js
Created June 3, 2015 13:59
Replace all SVG images with inline SVG using jQuery
/*
* Replace all SVG images with inline SVG
*/
jQuery('img.svg').each(function(){
var $img = jQuery(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
jQuery.get(imgURL, function(data) {
@iftee
iftee / bootstrap-480-767-grid.css
Last active June 30, 2017 11:51
Custom Bootstrap 3 Grid for 480-767px Layout
/**
* Custom Bootstrap 3 grid for 480-767px layout
* Author: Iftakhar Hasan
*
* A new set of column classes (with class prefix .col-ms- ) for Bootstrap 3
* to make Medium Small grids for supporting 480-767px
*
* This will push the default Bootstrap 3 Extra Small column (class prefix .col-xs- )
* to support 1-479px instead of 1-767px
*/
@grachov
grachov / msOrder
Created May 3, 2015 21:14
Простой способ для пересчета стоимости заказа после его изменения
<?php
class msOrder extends xPDOSimpleObject
{
public function updateProducts()
{
$originalContext = $this->xpdo->context->get('key');
$this->xpdo->switchContext($this->get('context'));
$originalMiniShop = isset($this->xpdo->services['minishop2']) ? $this->xpdo->services['minishop2'] : null;
$cart = array();
foreach ($this->getMany('Products') as $product) {
@codedokode
codedokode / js-task-1.md
Last active May 18, 2025 16:40
Задания на яваскрипт (простые)