ViewRenderer example


    public function preDispatch()
    {
        $this->Response()->setHeader('x-robots-tag', 'noindex');
    }

    public function serviceAction()
    {
        $this->Response()->setStatusCode(503);

        // do not render a template when in service mode         $this->Front()->Plugins()->ViewRenderer()->setNoRender(true);
    }
}

    public function ajaxAmountAction()
    {
        $this->Response()->headers->set('content-type', 'application/json');

        $amount = $this->basket->sGetAmount();
        $quantity = $this->basket->sCountBasket();

        $this->View()->assign('sBasketQuantity', $quantity);
        $this->View()->assign('sBasketAmount', empty($amount) ? 0 : array_shift($amount));

        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $this->Response()->setContent(
            json_encode([
                'amount' => Shopware()->Template()->fetch('frontend/checkout/ajax_amount.tpl'),
                'quantity' => $quantity,
            ])
        );
    }

    /** * Sets a temporary session variable which holds an address for the current order * * @return void */
$this->Front()->Plugins()->Json()->setRenderer();
            $this->View()->assign(['message' => 'File not found', 'success' => false]);

            return;
        }

        $meta = $filesystem->getMetadata($path);
        $mimeType = $filesystem->getMimetype($path) ?: 'application/octet-stream';

        @set_time_limit(0);

        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $response = $this->Response();
        $response->headers->set('content-type', $mimeType);
        $response->headers->set('content-disposition', sprintf('attachment; filename="%s"', basename($path)));
        $response->headers->set('content-length', $meta['size']);
        $response->headers->set('content-transfer-encoding', 'binary');
        $response->sendHeaders();
        $response->sendResponse();

        $upstream = $filesystem->readStream($path);
        if (!\is_resource($upstream)) {
            
use Shopware\Components\CSRFTokenValidator;
use Shopware\Components\Random;

class Shopware_Controllers_Frontend_Csrftoken extends Enlight_Controller_Action
{
    /** * Loads auth and script renderer resource */
    public function preDispatch()
    {
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();
    }

    /** * Generates a token and fills the cookie and session * * @return void */
    public function indexAction()
    {
        $token = Random::getAlphanumericString(30);

        
$this->View()->assign('isShipping', $this->isShippingRequest());
    }

    /** * Saves a new address and returns an envelope containing success and error indicators * * In addition, extraData[] can be send to do various actions after saving. See handleExtraData() for more * information. */
    public function ajaxSaveAction()
    {
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        $response = ['success' => true, 'errors' => [], 'data' => []];

        $userId = $this->get('session')->get('sUserId');
        $addressId = $this->Request()->getPost('id');
        $extraData = $this->Request()->getParam('extraData', []);

        if ($this->Request()->getParam('saveAction') === 'update') {
            $address = $this->addressRepository->getOneByUser($addressId$userId);
        } else {
            $address = new Address();
        }

        
class Shopware_Controllers_Frontend_Error extends Enlight_Controller_Action implements CSRFWhitelistAware
{
    /** * Disable front plugins * * @return void */
    public function init()
    {
        $this->Front()->Plugins()->ScriptRenderer()->setRender(false);
        $this->Front()->Plugins()->ViewRenderer()->setNoRender(false);
        $this->Front()->Plugins()->Json()->setRenderer(false);
    }

    /** * Load correct template */
    public function preDispatch()
    {
        if ($this->Request()->getActionName() === 'service') {
            return;
        }
        
return [
            'downloadLogFile',
        ];
    }

    /** * Disable template engine for some actions */
    public function preDispatch()
    {
        if ($this->Request()->getActionName() === 'downloadLogFile') {
            $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        } elseif (!\in_array($this->Request()->getActionName()['index', 'load'])) {
            $this->Front()->Plugins()->Json()->setRenderer();
        }
    }

    /** * This function is called, when the user opens the log-module. * It reads the logs from s_core_log * Additionally it sets a filterValue * * @return void */

    public static $testRepository;

    /** * Disable template engine for all actions and enable JSON Render - spare index and load action * * @codeCoverageIgnore */
    public function preDispatch()
    {
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
    }

    /** * Tracks how many clicks on a single banner are clicked. * If we have a valid link this action will redirect the browser accordingly * * @return bool */
    public function countBannerClickAction()
    {
        $bannerId = $this->Request()->getParam('bannerId');
        


    /** * Provides a way to download the original resource in the media manager. The * method sets the correct HTTP-Header to trigger the save dialog of the browser * and disables all available renderers. * * @return void */
    public function downloadAction()
    {
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
        $this->Front()->Plugins()->Json()->setRenderer(false);

        $mediaId = $this->Request()->getParam('mediaId');
        $media = $this->getMedia($mediaId)->getQuery()->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

        if (!$media) {
            echo self::FILE_NOT_FOUND_MESSAGE;

            return;
        }

        
use Shopware\Components\CSRFWhitelistAware;
use Shopware\Components\Random;

class Shopware_Controllers_Backend_CSRFToken extends Shopware_Controllers_Backend_ExtJs implements CSRFWhitelistAware
{
    /** * Loads auth and script renderer resource */
    public function init()
    {
        Shopware()->Plugins()->Backend()->Auth()->setNoAuth();
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        parent::init();
    }

    /** * {@inheritdoc} */
    public function getWhitelistedCSRFActions()
    {
        return [
            'generate',
        ];
    }


use Shopware\Components\CSRFWhitelistAware;
use Symfony\Component\HttpFoundation\Response;

class Shopware_Controllers_Backend_Cron extends Enlight_Controller_Action implements CSRFWhitelistAware
{
    public function init()
    {
        Shopware()->Plugins()->Backend()->Auth()->setNoAuth();
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
    }

    public function indexAction()
    {
        if (!Shopware()->Plugins()->Core()->Cron()->authorizeCronAction($this->Request())) {
            $this->Response()
                ->clearHeaders()
                ->setStatusCode(Response::HTTP_FORBIDDEN)
                ->appendBody('Forbidden');

            return;
        }

    /** * Pre dispatch method */
    public function preDispatch()
    {
        $this->Response()->setHeader('x-robots-tag', 'noindex');
    }

    public function refreshCaptchaAction()
    {
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $legacyCaptcha = $this->container->get('shopware.captcha.legacy_captcha');
        $templateData = $legacyCaptcha->getTemplateData();

        $img = $templateData['img'];
        $rand = $templateData['sRand'];

        $body = '<img src="data:image/png;base64,' . $img . '" alt="Captcha" />';
        $body .= '<input type="hidden" name="sRand" value="' . $rand . '" />';

        $this->Response()->setContent($body);
    }

    /** * Disable template engine for selected actions * * @codeCoverageIgnore */
    public function preDispatch()
    {
        parent::preDispatch();
        if (\in_array($this->Request()->getActionName()['validateTrackingCode', 'mapCustomerAccount'])) {
            $this->Front()->Plugins()->Json()->setRenderer(false);
            $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        }
    }

    /** * {@inheritdoc} */
    public function getWhitelistedCSRFActions()
    {
        return [
            'redirectToPartnerLink',
            'downloadStatistic',
        ];
class Shopware_Controllers_Backend_Newsletter extends Enlight_Controller_Action implements CSRFWhitelistAware
{
    /** * Init controller method * * Disables the authorization-checking and template renderer. */
    public function init()
    {
        Shopware()->Plugins()->Backend()->Auth()->setNoAuth();
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
    }

    /** * {@inheritdoc} */
    public function getWhitelistedCSRFActions()
    {
        return [
            'view',
            'index',
            'cron',
            


        $this->redirect(['action' => 'index']);
    }

    /** * @return void */
    public function ajaxAddAction()
    {
        $this->Request()->setHeader('Content-Type', 'application/json');
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $this->Response()->setContent(json_encode(
            [
                'success' => $this->addNote((string) $this->Request()->getParam('ordernumber')),
                'notesCount' => (int) Shopware()->Modules()->Basket()->sCountNotes(),
            ]
        ));
    }

    private function addNote(string $orderNumber): bool
    {
        
Home | Imprint | This part of the site doesn't use cookies.