Front example

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',
        ];
    }
$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();
        }

        
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->addAclPermission('createRule', 'save', "You're not allowed to save a rule.");
        $this->addAclPermission('editRule', 'save', "You're not allowed to save a rule.");
        $this->addAclPermission('deleteRule', 'delete', "You're not allowed to delete a rule.");
    }

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

    /** * Function to get all active payment-means and the ruleSets */
    public function getPaymentsAction()
    {
        try {
            $builder = $this->get('models')->createQueryBuilder();
            $builder->select(['payment', 'ruleSets'])
                    


    /** * Initializes plugin config * * @throws Exception */
    public function initConfig()
    {
        $shopConfig = Shopware()->Config();
        self::$baseFile = $shopConfig->get('baseFile');
        $this->useSecure = Shopware()->Front()->Request()->isSecure();

        $request = Shopware()->Front()->Request();
        $this->basePath = $request->getHttpHost() . $request->getBasePath() . '/';
        $this->basePathUrl = $request->getScheme() . '://' . $this->basePath;

        $this->backLinkWhiteList = preg_replace('#\s#', '', $shopConfig->get('seoBackLinkWhiteList'));
        $this->backLinkWhiteList = explode(',', $this->backLinkWhiteList);

        $hosts = $this->getShopHosts();

        $this->backLinkWhiteList = array_merge(
            
return;
        }

        $this->View()->assign(['success' => true]);
    }

    /** * Import snippet action */
    public function importSnippetAction()
    {
        $this->Front()->Plugins()->Json()->setRenderer(false);

        if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) {
            echo json_encode([
                'success' => false,
                'message' => 'Could not upload file',
            ]);

            return;
        }

        if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
            


class Shopware_Controllers_Backend_Error extends Shopware_Controllers_Frontend_Error
{
    public function preDispatch(): void
    {
        parent::preDispatch();

        $contentType = $this->Request()->getHeader('Content-Type');
        if ($contentType && str_starts_with($contentType, 'application/json')) {
            $this->Front()->Plugins()->Json()->setRenderer();
            $this->View()->assign('success', false);
        }
    }
}
namespace Shopware\Components\Log\Processor;

use Monolog\Processor\ProcessorInterface;

class ShopwareEnvironmentProcessor implements ProcessorInterface
{
    /** * Adds request, shop and session info */
    public function __invoke(array $record)
    {
        if ($request = Shopware()->Front()->Request()) {
            $record['extra']['request'] = [
                'uri' => $request->getRequestUri(),
                'method' => $request->getMethod(),
                'query' => $this->filterRequestUserData($request->getQuery()),
                'post' => $this->filterRequestUserData($request->getPost()),
            ];
        } elseif (!empty($_SERVER['REQUEST_URI'])) {
            $record['extra']['request'] = [
                'uri' => $_SERVER['REQUEST_URI'],
                'method' => $_SERVER['REQUEST_METHOD'],
                'query' => $this->filterRequestUserData($_GET),
                

    protected $resource;

    public function preDispatch()
    {
        if (($this->resource instanceof AbstractResource) && $this->container->initialized('auth')) {
            $this->resource->setAcl($this->container->get('acl'));
            $this->resource->setRole($this->container->get('auth')->getIdentity()->role);
        }

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

        $this->apiBaseUrl = $this->Request()->getScheme()
           . '://'
           . $this->Request()->getHttpHost()
           . $this->Request()->getBaseUrl()
           . '/api/';
    }

    public function postDispatch()
    {
        $data = $this->View()->getAssign();
        
class Shopware_Controllers_Widgets_Index extends Enlight_Controller_Action
{
    /** * Pre dispatch method */
    public function preDispatch(): void
    {
        $this->Response()->setHeader('x-robots-tag', 'noindex');

        if (strtolower($this->Request()->getActionName()) === 'refreshstatistic') {
            $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        }
    }

    /** * Refresh shop statistic */
    public function refreshStatisticAction(): void
    {
        $request = $this->Request();
        $response = $this->Response();

        


    /** * Event listener method * * @return \sSystem */
    public function onInitResourceSystem(Enlight_Event_EventArgs $args)
    {
        $config = Shopware()->Config();

        $request = Shopware()->Front()->Request();
        $system = new sSystem($request);

        Shopware()->Container()->set('system', $system);

        $system->sMODULES = Shopware()->Modules();
        $system->sSMARTY = Shopware()->Template();
        $system->sCONFIG = $config;
        $system->sMailer = Shopware()->Container()->get('mail');

        if (Shopware()->Container()->initialized('session')) {
            $system->_SESSION = Shopware()->Session();
            
                $this->sendMail(Shopware()->System()->_POST['newsletter'], 'sNEWSLETTERCONFIRMATION');
            }
        } else {
            $this->View()->assign('sStatus', Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST['newsletter']));

            if ($this->View()->getAssign('sStatus')['code'] == 3) {
                if ($this->View()->getAssign('sStatus')['isNewRegistration']) {
                    Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST['newsletter'], true);
                    $hash = Random::getAlphanumericString(32);
                    $data = serialize(Shopware()->System()->_POST->toArray());

                    $link = $this->Front()->ensureRouter()->assemble(['sViewport' => 'newsletter', 'action' => 'index', 'sConfirmation' => $hash]);

                    $this->sendMail(Shopware()->System()->_POST['newsletter'], 'sOPTINNEWSLETTER', $link);

                    Shopware()->Db()->query(' INSERT INTO s_core_optin (datum,hash,data,type) VALUES ( now(),?,?,"swNewsletter" ) ', [$hash$data]);
                }

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


    /** * @return array */
    private function convertProducts(ProductSearchResult $result)
    {
        $products = [];
        foreach ($result->getProducts() as $product) {
            $productArray = $this->get(LegacyStructConverter::class)->convertListProductStruct($product);

            $productArray['link'] = $this->Front()->ensureRouter()->assemble([
                'controller' => 'detail',
                'sArticle' => $product->getId(),
                'number' => $product->getNumber(),
                'title' => $product->getName(),
            ]);
            $productArray['name'] = $product->getName();
            $products[] = $productArray;
        }

        return $products;
    }

    
EmailValidatorInterface $emailValidator = null,
        ?Shopware_Components_Translation $translationComponent = null,
        ?Connection $connection = null,
        ?OptInLoginServiceInterface $optInLoginService = null,
        ?CSRFTokenValidator $csrfTokenValidator = null,
        ?ShippingCostServiceInterface $shippingCostService = null
    ) {
        $this->db = $db ?: Shopware()->Db();
        $this->eventManager = $eventManager ?: Shopware()->Events();
        $this->config = $config ?: Shopware()->Config();
        $this->session = $session ?: Shopware()->Session();
        $this->front = $front ?: Shopware()->Front();
        $this->passwordEncoder = $passwordEncoder ?: Shopware()->PasswordEncoder();
        $this->snippetManager = $snippetManager ?: Shopware()->Snippets();
        $this->moduleManager = $moduleManager ?: Shopware()->Modules();
        $this->sSYSTEM = $systemModule ?: Shopware()->System();

        $mainShop = Shopware()->Shop()->getMain() !== null ? Shopware()->Shop()->getMain() : Shopware()->Shop();
        $this->scopedRegistration = $mainShop->getCustomerScope();

        $this->contextService = $contextService ?: Shopware()->Container()->get(ContextServiceInterface::class);
        $this->emailValidator = $emailValidator ?: Shopware()->Container()->get(EmailValidator::class);
        $this->subshopId = $this->contextService->getShopContext()->getShop()->getParentId();
        
Home | Imprint | This part of the site doesn't use cookies.