Plugins example

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(['success' => true]);
    }

    /** * Validate name action * * Validates whether or not the provided value exists in the database */
    public function validateNameAction()
    {
        $this->Front()->Plugins()->Json()->setRenderer(false);

        if (!($name = $this->Request()->getParam('value'))) {
            return;
        }

        $id = $this->Request()->getParam('param', false);

        $mail = $this->getRepository()
                     ->getValidateNameQuery($name$id)
                     ->getResult(AbstractQuery::HYDRATE_OBJECT);

        

    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');
        

    public function preDispatch()
    {
        parent::preDispatch();

        $calledAction = $this->Request()->getActionName();

        if (Shopware()->Plugins()->Backend()->Auth()->shouldAuth()
            && $this->isPasswordConfirmProtectedAction($calledAction)
            && !$this->container->get('backendsession')->offsetGet('passwordVerified')
        ) {
            $this->forward('passwordConfirmationRequired');
        }
    }

    /** * Displays a JSON string indicating failure for password confirmation */
    public function passwordConfirmationRequiredAction()
    {


        $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
    {
        
$this->addAclPermission('createPremiumArticle', 'create', "You're not allowed to create an article.");
        $this->addAclPermission('editPremiumArticle', 'update', "You're not allowed to update the article.");
        $this->addAclPermission('deletePremiumArticle', 'delete', "You're not allowed to delete the article.");
    }

    /** * Disable template engine for all actions */
    public function preDispatch()
    {
        if (!\in_array($this->Request()->getActionName()['index', 'load', 'validateArticle'])) {
            $this->Front()->Plugins()->Json()->setRenderer(true);
        }
    }

    public function getSubShopsAction()
    {
        // load shop repository         $repository = $this->get('models')->getRepository(Shop::class);

        $builder = $repository->createQueryBuilder('shops');
        $builder->select([
            'shops.id as id',
            

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

    /** * Product navigation as json string */
    public function productNavigationAction(): void
    {
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        try {
            $orderNumber = $this->Request()->get('ordernumber');

            if (!$orderNumber) {
                throw new InvalidArgumentException('Argument ordernumber missing');
            }

            $categoryId = (int) $this->Request()->get('categoryId');
            if (!$categoryId) {
                throw new InvalidArgumentException('Argument categoryId missing');
            }

    if (isset($params['params'])) {
        $userParams = (array) $params['params'];
        unset($params['params']);
    } else {
        $userParams = [];
    }

    $params = array_merge($userParams$params);

    /** @var \Shopware_Plugins_Core_HttpCache_Bootstrap $httpCache */
    $httpCache = Shopware()->Plugins()->Core()->HttpCache();
    if ($esiTag = $httpCache->renderEsiTag($request$params)) {
        return $esiTag;
    }

    $request = clone $request;
    $response = clone $response;

    $request->clearParams();
    $response->clearHeaders()
             ->clearBody();

    
throw new RuntimeException('Could not redirect as the "Location" header is not set');
            }
            $this->resetResponse();
            $cookies = $this->Response()->getCookies();
            $this->resetRequest();
            $this->Request()->setCookies($cookies);

            return $this->dispatch($link);
        }

        /** @var Enlight_Controller_Plugins_ViewRenderer_Bootstrap $viewRenderer */
        $viewRenderer = $front->Plugins()->get('ViewRenderer');
        $this->_view = $viewRenderer->Action()->View();

        return $response;
    }

    /** * Reset all instances, resources and init the internal view, template and front properties * * @return void */
    public function reset()
    {
$this->addAclPermission('getEnconder', 'read', "You're not allowed to open the module.");
        $this->addAclPermission('getOptimizers', 'read', "You're not allowed to open the module.");
        $this->addAclPermission('info', 'read', "You're not allowed to open the module.");
    }

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

    /** * Function to get all system-configs and its requirements * The array also contains a status, whether the minimum requirements are met * The encoder-configs are excluded, because they are needed in another store * getEncoderAction loads those two encoder-configs * * @return void */
    
array_merge(['optinconfirmed' => true]$redirection)
        );
    }

    /** * @throws Exception * * @deprecated since 5.7.4. Will be removed in Shopware 5.8 without replacement */
    public function ajaxValidateEmailAction()
    {
        $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        $this->Response()->setHttpResponseCode(Response::HTTP_GONE);
    }

    public function ajaxValidatePasswordAction()
    {
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();

        $data = $this->getPostData();
        $customerForm = $this->createCustomerForm($data['register']['personal']);

        $errors = $this->getFormErrors($customerForm);
        

        if (PHP_SAPI === 'cli') {
            return;
        }

        $container = Shopware()->Container();
        if (!$container->initialized('session')) {
            return;
        }

        /** @var Shopware_Plugins_Frontend_Statistics_Bootstrap $plugin */
        $plugin = Shopware()->Plugins()->Frontend()->Statistics();
        if ($plugin->checkIsBot($args->getRequest()->getHeader('USER_AGENT') ?: '')) {
            $this->get('session')->invalidate();
        }
    }

    /** * Event listener method * * @return \sSystem */
    public function onInitResourceSystem(Enlight_Event_EventArgs $args)
    {
use Shopware\Components\CSRFTokenValidator;
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',
        ];
/** * Disable template engine for all actions * * @codeCoverageIgnore */
    public function preDispatch()
    {
        parent::preDispatch();
        if (\in_array($this->Request()->getActionName()[
            'validateOrderCode', 'validateVoucherCode', 'validateDescription', ])) {
            $this->Front()->Plugins()->Json()->setRenderer(false);
            $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        }
    }

    /** * Deletes a Supplier from the database * * @return void */
    public function deleteVoucherAction()
    {
        

    private $export;

    /** * Init controller method * * Disables the authorization-checking and template renderer. */
    public function init()
    {
        Shopware()->Plugins()->Backend()->Auth()->setNoAuth();
        Shopware()->Front()->Plugins()->ViewRenderer()->setNoRender();
        $this->Front()->setParam('disableOutputBuffering', true);
        $this->export = Shopware()->Modules()->Export();
    }

    /** * Index action method * * Creates the export product. */
    public function indexAction()
    {
Home | Imprint | This part of the site doesn't use cookies.