Addon Stoped Working After Upgrade To 4.5.2.sp2 - Undefined Index: Cart

Hi, I just did test upgrade from 4.3.9 to 4.5.2.SP2 and one of the addons stopped working - it shows "Undefined index: cart, Error at app/addons/qty_minimums/func.php, line: 23".

The addon page: http://forum.cs-cart.com/topic/21933-qty-minimums-addon-satisfy-minimum-quantities-with-product-options/

Below is the func.php file, and separately line 23:

foreach ($_SESSION['cart']['products'] as $k => $v) {
<?php

if ( !defined(‘AREA’) ) { die(‘Access denied’); }

/** [HOOKS] **/

function fn_qty_minimums_check_amount_in_stock (&$product_id, &$amount, &$product_options, &$cart_id, &$is_edp, &$original_amount, &$min_qty)
{
$_SESSION[‘temp_amount’] = $amount;

if ($_REQUEST['dispatch'] == 'checkout.update') {

	$new_amount = $amount;
	foreach ($_REQUEST['cart_products'] as $k => $v) {
		if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
			$new_amount += $v['amount'];
		}
	}

} else {

	$new_amount = $amount;
	foreach ($_SESSION['cart']['products'] as $k => $v) {
		if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
			$new_amount += $v['amount'];
		}
	}
}

if ($new_amount >= $min_qty) {
	$min_qty = $amount;
}

}

function fn_qty_minimums_check_amount_in_stock_minimum (&$product_id, &$amount, &$product_options, &$cart_id, &$is_edp, &$original_amount, &$min_qty)
{
$_SESSION[‘notifications’] = fn_array_unique($_SESSION[‘notifications’]);
if ($_REQUEST[‘dispatch’] == ‘checkout.place_order’) {
$min_qty = 0;
} else {
$min_qty = $_SESSION[‘temp_amount’];
}
}

/** [/HOOKS] **/

?>

Can you help me?

Please try:

#replace

$_SESSION['cart'] 

#with

Tygh::$app['session']['cart']

Please try:

#replace

$_SESSION['cart'] 

#with

Tygh::$app['session']['cart']

I tried and now it shows "Invalid argument supplied for foreach()"

Below the line 23 after replace:

foreach (Tygh::$app['session']['cart']['products'] as $k => $v) {

Please try

$cart_products = Tygh::$app['session']['cart']['products'];
foreach ($cart_products as $k => $v) {

Please try

$cart_products = Tygh::$app['session']['cart']['products'];
foreach ($cart_products as $k => $v) {

Unfortunately still "Invalid argument supplied for foreach()"

Unfortunately still "Invalid argument supplied for foreach()"


Please try

if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['products'])) {
  foreach ($_SESSION['cart']['products'] as $k => $v) {
    if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
      $new_amount += $v['amount'];
    }
  } 
}
$cart = Tygh::$app['session']['cart'];
if(!empty($cart['products'])){
	foreach ($cart['products'] as $k => $v) {
		if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
			$new_amount += $v['amount'];
		}
	}
}


Please try

if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['products'])) {
  foreach ($_SESSION['cart']['products'] as $k => $v) {
    if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
      $new_amount += $v['amount'];
    }
  } 
}

Now it doesn't show any error, but the addon doesn't work.


$cart = Tygh::$app['session']['cart'];
if(!empty($cart['products'])){
	foreach ($cart['products'] as $k => $v) {
		if (($v['product_id'] == $product_id) && ($k != $cart_id)) {
			$new_amount += $v['amount'];
		}
	}
}

Now it doesn't show any error, but the addon doesn't work.

Now it doesn't show any error, but the addon doesn't work.


Please check if the core modificationsa re still there, as i can see on the post there are some core modifications required and on upgrade thoose might be deleted

Please check if the core modificationsa re still there, as i can see on the post there are some core modifications required and on upgrade thoose might be deleted

Thank you a lot! That was it, actually didn't need to change the func.php after core modification.

$cart = Tygh::$app['session']['cart'];

Actually the old style still also works