Shopping Cart Error 500

Hey guys,

I added some Articles in an array. This works fine, but if I check the page with the MiniCart Module I get the right output at the first call. Then I refresh the page an get an Error 500. Only since PHP 7.1

<?php
namespace NeosCommerce\Cart\Controller;

/*
 * This file is part of the NeosCommerce.Cart package.
 */

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;

/**
 * @Flow\Scope("session")
 */
class CartController extends ActionController
{

/**
 * @var array
 */
protected $items = array();

/**
 * @Flow\Inject
 * @var \NeosCommerce\Cart\Domain\Repository\CartRepository
 */
protected $cartRepository;

/**
 * @param integer $title
 * @return void
 * @Flow\Session(autoStart = TRUE)
 */
public function addtoAction($title) {

    $cart = $this->items;

    $article = array();
    $article[] = array("title"=>$articleTitle);

    $this->redirectToUri('/');

}

/**
 * @return void
 */
public function miniCartAction() {

    $cart = $this->items;

    if ($cart==false) {
        $sum = "";
        $sum = intval($sum);
        foreach ($cart as $dat) {
            $quantity = intval($dat["quantity"]);
            $sum += $quantity;
        }
        $this->view->assign('itemscount', $sum);
        $this->view->assign('items', $cart);
    } else {
        $this->view->assign('itemscount', '0');
        $this->view->assign('items', '0');
    }

}

}

Okay, I have found this in the error.log but I do not understand it. Can you help me?

[Fri Jul 14 07:16:54.157005 2017] [:error] [pid 12681] [client 80.123.79.100:57957] FastCGI: server “/usr/lib/cgi-bin/php71-fcgi-www” stderr: PHP message: PHP Fatal error: TYPO3Fluid\Fluid\View\AbstractTemplateView::getCurrentParsedTemplate(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Cart_action_miniCart_3debb049a1d40f09835559fe0b2308f9599a9c2b” of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /var/www/Neos3dev/Packages/Libraries/typo3fluid/fluid/src/View/AbstractTemplateView.php on line 364, referer: http://mydomain.com/de/mini-warenkorb.html

What you definitely do there is mix variable types. your items variable is either an array or a string with 0 in it. You should adjust that, asme for itemscount. Also how can $cart ever be false?

Thx Christian, I’ve fixed this. But it does not work. I think, it is an issue with PHP 7.1. It works with PHP 7.0

The line in the apache error log:

FastCGI: server “/usr/lib/cgi-bin/php71-fcgi-www” stderr: PHP message: PHP Fatal error: TYPO3Fluid\Fluid\View\AbstractTemplateView::getCurrentParsedTemplate(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Cart_action_miniCart_7a047694d155e6a53865076308e9879f5492a491” of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /var/www/Neos3dev/Packages/Libraries/typo3fluid/fluid/src/View/AbstractTemplateView.php on line 364, referer: http://my.subdomain.com/de/mini-warenkorb.html

Christian, sorry.
The problem was the configuration of the webserver.

Thx for your help!

Would you explain what it was and how you fixed it? Might help others with similar problems. :slight_smile:

With pleasure!
First a little modification in php.ini: session.auto_start = 1
Second: Restart the box :slight_smile:

It was not the solution. After the restart it worked. But after a short time it does not work anymore. I just added a <strong> tag in the template and get a 500 error again :frowning:

So restarting was probably what fixed it. Could it be that your OPCache settings are broken maybe?

OPCache is disabled :frowning:
I don’t understand this, but this Code is in use in an old “TYPO3” Neos and it works.
First I think PHP 7.1 makes problems, but I have the same php.ini settings as in PHP 5. I have no idea anymore.

I add this in the Controller Action (at end):
return $this->view->render("../Cart/MiniCart");

It works now. Then I add this

`<f:link.action action="removeAll" controller="Cart">Warenkorb löschen</f:link.action>`

in the MiniCart Template. Nothing works.

I get:
An exception was thrown while Neos tried to render your page
Argument “class” has already been defined, thus it should not be defined again.

I think it is a serialize() unserialize() problem as the error message describes.