Skip to content

Instantly share code, notes, and snippets.

@crystaldaking
Created December 3, 2019 07:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crystaldaking/6725eb05290554c0fbd57b0acca7f36f to your computer and use it in GitHub Desktop.
Save crystaldaking/6725eb05290554c0fbd57b0acca7f36f to your computer and use it in GitHub Desktop.
//плагин на событие 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;
$modx->event->output('Вы пытаетесь положитель больше товаров чем есть в наличии');
}
}
}
$cart->set($cartArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment