<?php
declare(strict_types = 1);
namespace Medienreaktor\Products\Domain\Finishers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

class SidebarDataProviderFinisher extends \TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
{
    /**
     * Executes this finisher
     * @throws FinisherException
     * @see AbstractFinisher::execute()
     *
     */


    /**
     * cartDataService
     *
     * @var \Medienreaktor\Products\Service\CartDataService
     */
    protected $cartDataService = null;

    public function __construct(\Medienreaktor\Products\Service\CartDataService $cartDataService)
    {
        $this->cartDataService = $cartDataService;
    }

    protected function executeInternal(): void
    {

        $this->finisherContext->getFinisherVariableProvider()->add(
            $this->shortFinisherIdentifier,
            'active',
            true
        );

        $products = $this->cartDataService->getProductsFromCookie();
        $this->finisherContext->getFinisherVariableProvider()->add(
            $this->shortFinisherIdentifier,
            'products',
            $products
        );

    }

}
