Помогите устранить ошибку в коде

Добрый день

Ошибка вот такая.

(ERROR @ httpdocs/core/cache/includes/elements/modplugin/32.include.cache.php: 122) PHP warning: max(): When only one parameter is given, it must be an array

Как её устранить или обойти, чтоб больше её не было.

И какой файл нужно для этого отредактировать?
Как я понимаю «32.include.cache.php» — это временный файл кэша и редактирование его, результата не даст.

Код из этого файла «32.include.cache.php»

<?php
switch ($modx->event->name) {
	case 'OnWebPageInit':
			$discounts = array(0);
			$now = new DateTime();
			$yearago = 0;
			$yearago = $now->modify('-1 year');
			$modx->setPlaceholder('disyearago', $yearago->format('d.m.Y'));
			$yearago = $yearago->format("Y-m-d H:i:s");
			$modx->setPlaceholder('yearago', $yearago);
			$user_id = $modx->user->get('id');
			if($user_id != 0){
				$profile = $modx->user->getOne('Profile');
			  //Скидка за ДР
			  //$dob = $profile->get('dob');
			  //if($dob && $dob != 0){
			  //	$discounts[] = 0;
			  //}
			  
			  //Скидки группам пользователей
			  //if($admin = $modx->user->isMember('Administrator')){
			  //$discounts[] = 0;
			  //}
			  
			  //Скидки от суммы покупок за год
			  $q = $modx->prepare("SELECT * FROM modx_ms2_orders WHERE user_id='$user_id' AND createdon > '$yearago'  ORDER BY createdon");
			  $q->execute();
			  $orders = $q->fetchAll(PDO::FETCH_ASSOC);
			  $yearcost = 0;
			  $i = 0;
			  $firstorder = 0;
			  if(count($orders)!=0){
				  foreach($orders as $order){
					  switch ($order[status]){
						  case 2:
						  case 3:
							  $yearcost = $yearcost + $order[cost];
							  if($i == 0){
								  $firstorder = new DateTime($order[createdon]);
								  $firstorder->modify('+1 year');
								  $firstorder = $firstorder->format('d.m.Y');
							  }
							  $i++;
							  break;
					  }
				  }
				  $extended = $profile->get('extended');
				  if($extended['yearcost'] != $yearcost){
					$extended['yearcost'] = $yearcost;
					$extended['firstorder'] = $firstorder;
					if($yearcost < 2500){
						$extended['userdiscount'] = 0;
					}
					if($yearcost >= 2500){
						$extended['userdiscount'] = 5;
					}
					if($yearcost >= 5000){
						$extended['userdiscount'] = 10;
					}
					if($yearcost >= 10000){
						$extended['userdiscount'] = 15;
					}
					$profile->set('extended', $extended);
					$profile->save();
				  }
				  $discountindicator = 0;
				  if($yearcost > 0){
						$discountindicator = $yearcost * 100 / 10000;
						if($discountindicator > 100){ $discountindicator = 100; }
				  }
				  $modx->setPlaceholder('discountindicator', $discountindicator);
			  }
			}
		break;
	case 'msOnGetProductPrice':
		if ($modx->context->key == 'mgr') {return;}
		//if($data['id'] == 154) {return;}
		/**
		 * Counts discount of current product for current user, based on rules in msDiscount component
		 * New price must be set in $modx->event->returnedValues['price']
		 *
		 * @var msProductData $product Object with product properties
		 * @var array $data Array with product properties. Can be empty!
		 * @var float $price Current price of product
		 */
		if (!isset($modx->event->returnedValues['price'])) {
			$modx->event->returnedValues['price'] = $price;
		}

		// Get link to product price
		$price = & $modx->event->returnedValues['price'];


		$values = & $modx->event->returnedValues;
		$product = $modx->getObject('msProduct', $data['id']);
		$id = $data['id'];
		$ccat  = $product->get('category');


		//Скидка пользователя
		$user_id = $modx->user->get('id');
		if($user_id != 0){
		  $profile = $modx->user->getOne('Profile');
		  $extended = $profile->get('extended');
		  if($ccat != 'special'){
		  $discounts[] = $extended['userdiscount'];
		  }

		}
		
		//Скидки на продукт
		$skidka = $product->get('skidka');
		$skidkauntill = $product->get('skidkauntill');
		if($$skidkauntill){
		$skidkauntill = new DateTime($skidkauntill);
		if($now < $skidkauntill){
			$discounts[] = $skidka;
			$modx->setPlaceholder('productskidka', $skidka);
		}
		}
		//Вычисляем скидку
		$discount = max($discounts);
		$multiplier = (100 - $discount)/100;
		$new_price = round($price * $multiplier);
		 $modx->setPlaceholder('new_price', $new_price);

		if ($new_price !== false) {
			$price = $new_price;
		}
		break;

}
return;
Asus0
15 декабря 2023, 10:12
modx.pro
295
0

Комментарии: 2

Володя
15 декабря 2023, 10:20
0
открыть плагин с id 32 и после
case 'msOnGetProductPrice':
		if ($modx->context->key == 'mgr') {return;}
добавить
$discounts = [0];
    Asus0
    15 декабря 2023, 10:39
    0
    Спасибо!

    Вот так вставил:

    case 'msOnGetProductPrice':
                    $discounts = [0];
    		if ($modx->context->key == 'mgr') {return;}
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    2