Skip to content

Instantly share code, notes, and snippets.

@ig0r74
ig0r74 / groupby_sum.php
Created March 6, 2022 15:28
MODX Revolution newQuery groupby & SUM
<?php
// ********************************* //
/** @var mindbox $mindbox */
$modx->loadClass('modMindbox', MODX_CORE_PATH . 'components/mindbox/model/', true, true);
$mindbox = new modMindbox($modx, []);
if (!$mindbox) {
return 'Could not load modMindbox class!';
}
$q = $modx->newQuery('msOrder', [
@ig0r74
ig0r74 / gist:f7e6dddb1d5fa1b72929d158eba9797c
Last active February 25, 2022 16:23
MODX вычисляем сумму остатков по TV и выводим с нулевым остатком в конце. При этом сохраняется сортировка по menuindex у остальных товаров.
{set $goods = 'msProducts' | snippet : [
'sortby' => '{"null_total_remains":"DESC", "menuindex":"DESC"}',
'tpl' => 'good.category3',
'leftJoin' => [
"remains" => [
"class" => "modTemplateVarResource",
"on" => "msProduct.id = remains.contentid AND remains.tmplvarid IN (29,30,31,32,33,34,52)" // id TV с остатками
],
],
'select' => [
@ig0r74
ig0r74 / migration.php
Created October 28, 2021 07:06
Laravel migration additional changes
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddRoleIdToUsersTable extends Migration
{
public function up()
{
@ig0r74
ig0r74 / sentry.plugin.php
Last active February 1, 2021 23:56
MODX Sentry integration
<?php
// Перед этим в консоли "cd core/components && mkdir sentry && composer require sentry/sdk"
switch ($modx->event->name) {
case 'OnMODXInit':
$file = MODX_CORE_PATH.'components/sentry/vendor/autoload.php';
if (file_exists($file)) {
require_once $file;
}
break;
case 'OnWebPageInit':
@ig0r74
ig0r74 / plugin.php
Created December 25, 2020 14:53
MODX MiniShop2 стоимость товаров total_cost без скидки msOnGetStatusCart
<?php
switch ($modx->event->name) {
case 'msOnGetStatusCart':
$values = & $modx->event->returnedValues;
$values['status'] = $status;
$values['status']['real_total_cost'] = $status['total_cost'] + $status['total_discount'];
break;
}
@ig0r74
ig0r74 / dobHook.php
Created November 14, 2020 09:56
MODX Login UpdateProfile dob hook
<?php
$dob = $hook->getValue('dob');
if (!empty($dob)) {
$hook->setValue('dob', strtotime($dob));
}
return true;
@ig0r74
ig0r74 / filterPathSegment.php
Created June 25, 2020 15:15
Транслитерация текста MODX
<?php
$modx->filterPathSegment($caption, ['friendly_alias_word_delimiter' => '_', 'friendly_alias_restrict_chars' => 'alpha']);
@ig0r74
ig0r74 / mfilter2_more_button.js
Last active May 25, 2023 09:24
MODX mFilter2 одновременное использование стандартной пагинации и подгрузки кнопкой
$('.btn_more_custom').click(function() {
var href = $('.mse2_pagination .page-item.active').next('.page-item').find('.page-link').attr('href');
if (typeof href !== "undefined") {
mSearch2.addPage();
}
});
$(document).on('mse2_load', function(e, data) {
if (typeof $('.mse2_pagination .page-item.active').next('.page-item').next('.page-item').find('.page-link').attr('href') === "undefined") {
$('.btn_more_custom').hide();
@ig0r74
ig0r74 / where-color.tpl
Created February 11, 2020 12:12
Выборка товаров по цвету MODX minishop2 where data.color
{'!Localizator' | snippet : [
'snippet' => 'msProducts',
'tpl' => 'good.like',
'leftJoin' => [
"big_2" => [
"class" => "msProductFile",
"alias" => "big_2",
"on" => "big_2.product_id = msProduct.id AND big_2.rank = 1 AND big_2.path LIKE '%/big/%'"
]
],
<?php
require MODX_CORE_PATH . 'components/modinstagram/vendor/autoload.php';
use Phpfastcache\Helper\Psr16Adapter;
// If account is public you can query Instagram without auth
$instagram = \InstagramScraper\Instagram::withCredentials('user', 'password', new Psr16Adapter('Files'));
$instagram->login();
$account = $instagram->getAccount('ig0r74');