Admin example

/** * @var AddressServiceInterface */
    protected $addressService;

    /** * Pre dispatch method */
    public function preDispatch()
    {
        $this->admin = Shopware()->Modules()->Admin();

        $session = $this->container->get('session');
        if ($session->get('sOneTimeAccount') && $this->Request()->has('sidebar')) {
            $this->admin->logout();
        }

        $this->addressRepository = $this->get(ModelManager::class)->getRepository(Address::class);
        $this->addressService = $this->get(AddressServiceInterface::class);

        $this->View()->assign('sUserLoggedIn', $this->admin->sCheckUser());

        
return (int) $dbal->fetchColumn(
            'SELECT default_shipping_address_id FROM s_user WHERE id = :id ',
            ['id' => $this->session->offsetGet('sUserId')]
        );
    }

    private function shouldVerifyCaptcha(Shopware_Components_Config $config): bool
    {
        return $config->get('newsletterCaptcha') !== 'nocaptcha'
            && !($config->get('noCaptchaAfterLogin') && Shopware()->Modules()->Admin()->sCheckUser());
    }

    private function getBasketQueryBuilder(string $amount, string $netAmount): QueryBuilder
    {
        $queryBuilder = $this->connection->createQueryBuilder()
            ->select([
                'MIN(d.instock>=b.quantity) as instock',
                'MIN(d.instock>=(b.quantity+d.stockmin)) as stockmin',
                'MIN(a.laststock) as laststock',
                'SUM(d.weight*b.quantity) as weight',
                'SUM(IF(a.id,b.quantity,0)) as count_article',
                
use Shopware\Components\Random;

class Shopware_Controllers_Frontend_Newsletter extends Enlight_Controller_Action
{
    /** * Index action method */
    public function indexAction()
    {
        $this->View()->assign('voteConfirmed', $this->isConfirmed());
        $this->Request()->setParam('voteConfirmed', $this->View()->voteConfirmed);
        $this->View()->assign('sUserLoggedIn', Shopware()->Modules()->Admin()->sCheckUser());

        $this->front->setParam('voteConfirmed', $this->View()->voteConfirmed);
        $this->front->setParam('optinNow', (new DateTime())->format('Y-m-d H:i:s'));

        if ($this->Request()->get('sUnsubscribe') !== null) {
            $this->View()->assign('sUnsubscribe', true);
        } else {
            $this->View()->assign('sUnsubscribe', false);
        }

        $this->View()->assign('_POST', Shopware()->System()->_POST->toArray());

        
if (empty($this->get('session')->get('sUserId'))) {
            $modules->System()->sUSERGROUP = $shop->getCustomerGroup()->getKey();
            $modules->System()->sUSERGROUPDATA = $shop->getCustomerGroup()->toArray();
            $modules->System()->sCurrency = $shop->getCurrency()->toArray();
        }

        $this->get(ContextServiceInterface::class)->initializeContext();

        $shopContext = $this->get(ContextServiceInterface::class)->getShopContext();

        $modules->Basket()->sRefreshBasket();
        $modules->Admin()->sGetPremiumShippingcosts($shopContext->getCountry() ? $shopContext->getCountry()->jsonSerialize() : null);

        $amount = $modules->Basket()->sGetAmount();
        $this->get('session')->offsetSet('sBasketAmount', empty($amount) ? 0 : array_shift($amount));
    }
}

        Shopware()->Session()->set('sNotesQuantity', Shopware()->Modules()->Basket()->sCountNotes());
    }

    /** * @return void */
    public function indexAction()
    {
        $view = $this->View();
        $view->assign('sNotes', Shopware()->Modules()->Basket()->sGetNotes());
        $view->assign('sUserLoggedIn', Shopware()->Modules()->Admin()->sCheckUser());
        $view->assign('sOneTimeAccount', Shopware()->Session()->offsetGet('sOneTimeAccount'));
    }

    /** * @return void */
    public function deleteAction()
    {
        if (!empty($this->Request()->sDelete)) {
            Shopware()->Modules()->Basket()->sDeleteNote($this->Request()->sDelete);
        }

        
return;
        }

        if ($this->shouldRedirectToTarget()) {
            $this->redirect(['controller' => $sTarget, 'action' => $sTargetAction]);

            return;
        }

        $this->View()->assign('isAccountless', $this->get('session')->get('isAccountless'));
        $this->View()->assign('register', $this->getRegisterData());
        $this->View()->assign('countryList', $this->get('modules')->Admin()->sGetCountryList());
    }

    /** * Checks the registration */
    public function saveRegisterAction()
    {
        if (!$this->request->isPost()) {
            $this->forward('index');

            return;
        }
$this->db->commit();
        } catch (Exception $e) {
            $this->db->rollBack();
            throw new Enlight_Exception(sprintf('Shopware Order Fatal-Error %s :%s', $_SERVER['HTTP_HOST']$e->getMessage()), 0, $e);
        }

        if (!$affectedRows || !$orderID) {
            throw new Enlight_Exception(sprintf('Shopware Order Fatal-Error %s : No rows affected or no order id created.', $_SERVER['HTTP_HOST']), 0);
        }

        try {
            $paymentData = Shopware()->Modules()->Admin()
                ->sGetPaymentMeanById($this->getPaymentId()Shopware()->Modules()->Admin()->sGetUserData());
            $paymentClass = Shopware()->Modules()->Admin()->sInitiatePaymentClass($paymentData);
            if ($paymentClass instanceof BasePaymentMethod) {
                $paymentClass->createPaymentInstance(
                    $orderID,
                    $this->sUserData['additional']['user']['id'],
                    $this->getPaymentId()
                );
            }
        } catch (Exception $e) {
            // Payment method code failure
return;
        }

        // Load the right template         if (!empty($blogArticleData['template'])) {
            $this->View()->loadTemplate('frontend/blog/' . $blogArticleData['template']);
        }

        $this->View()->assign('userLoggedIn', !empty(Shopware()->Session()->get('sUserId')));
        if (!empty(Shopware()->Session()->get('sUserId')) && empty($this->Request()->get('name'))
            && $this->Request()->getParam('__cache') === null) {
            $customerData = Shopware()->Modules()->Admin()->sGetUserData();
            if (\is_array($customerData)) {
                $this->View()->assign('sFormData', [
                    'eMail' => $customerData['additional']['user']['email'],
                    'name' => $customerData['billingaddress']['firstname'] . ' ' . $customerData['billingaddress']['lastname'],
                ]);
            }
        }

        $mediaIds = array_column($blogArticleData['media'], 'mediaId');
        $context = $this->get(ContextServiceInterface::class)->getShopContext();
        $mediaStructs = $this->get(MediaServiceInterface::class)->getList($mediaIds$context);

        
protected TaxAggregatorInterface $taxAggregator;

    /** * Init method that get called automatically * * Set class properties * * @return void */
    public function init()
    {
        $this->admin = Shopware()->Modules()->Admin();
        $this->basket = Shopware()->Modules()->Basket();
        $this->session = Shopware()->Session();
        $this->taxAggregator = Shopware()->Container()->get(TaxAggregatorInterface::class);
    }

    public function getCSRFProtectedActions()
    {
        return [
            'ajaxAddArticle',
            'addArticle',
            'ajaxAddArticleCart',
            
return;
        }

        $view = $this->View();
        $view->assign('sAction', $view->getAssign('sAction') ?: 'index', true);
        $view->assign('sErrorFlag', $view->getAssign('sErrorFlag') ?: [], true);
        $view->assign('sFormData', $view->getAssign('sFormData') ?: [], true);
        $view->assign('userLoggedIn', (bool) $this->container->get('session')->get('sUserId'));

        if (!empty($this->container->get('session')->get('sUserId')) && empty($this->Request()->get('sVoteName'))
            && $this->Request()->getParam('__cache') !== null) {
            $userData = $this->container->get('modules')->Admin()->sGetUserData();
            if (\is_array($userData)) {
                $view->assign('sFormData', [
                    'sVoteMail' => $userData['additional']['user']['email'],
                    'sVoteName' => $userData['billingaddress']['firstname'] . ' ' . $userData['billingaddress']['lastname'],
                ]);
            }
        }

        $number = $this->Request()->getParam('number');
        $selection = $this->Request()->getParam('group', []);

        
$session->clear();
        $session->migrate(true);

        Shopware()->Session()->offsetSet('sessionId', $session->getId());
        Shopware()->Container()->set('sessionid', $session->getId());

        Shopware()->Session()->set('Admin', true);
        Shopware()->System()->_POST = [
            'email' => $user['email'],
            'passwordMD5' => $user['password'],
        ];
        Shopware()->Modules()->Admin()->sLogin(true);

        $hash = $this->container->get(OptinServiceInterface::class)->add(OptinServiceInterface::TYPE_CUSTOMER_LOGIN_FROM_BACKEND, 300, [
            'sessionId' => Shopware()->Session()->get('sessionId'),
            'shopId' => $shop->getId(),
        ]);

        $url = $this->Front()->ensureRouter()->assemble([
            'action' => 'performOrderRedirect',
            'hash' => $hash,
            'fullPath' => true,
        ]);

        

    public function sRefreshBasket()
    {
        // Update basket data         $this->moduleManager->Admin()->sGetUserData();
        $this->sGetBasket();
        $this->moduleManager->Admin()->sGetPremiumShippingcosts();

        // Update basket data in session         $this->session->offsetSet('sBasketCurrency', Shopware()->Shop()->getCurrency()->getId());
        $this->session->offsetSet('sBasketQuantity', $this->sCountBasket());
        $amount = $this->sGetAmount();
        $this->session->offsetSet('sBasketAmount', empty($amount) ? 0 : array_shift($amount));
    }

    /** * Checks if the vouchers on the current basket have already been used. * Return true if the current cart doesn't have a voucher or if the voucher is valid * Returns false if the current voucher has already been used. * * @param string $sessionId * @param int $userId * * @return bool */

        parent::__construct();
        $this->config = $config;
        $this->captchaValidator = $captchaValidator;
    }

    /** * @return void */
    public function init()
    {
        $this->admin = Shopware()->Modules()->Admin();
        $this->customerService = Shopware()->Container()->get(CustomerServiceInterface::class);
    }

    public function preDispatch()
    {
        $this->View()->setScope(Smarty::SCOPE_PARENT);
        if ($this->shouldForwardToRegister()) {
            $this->forward('index', 'register', 'frontend', $this->getForwardParameters());

            return;
        }
        
Home | Imprint | This part of the site doesn't use cookies.