Basket example


    public function sGetPaymentMeanById($id$user = false)
    {
        $id = (int) $id;
        $resetPayment = false;

        $data = $this->db->fetchRow(
            'SELECT * FROM s_core_paymentmeans WHERE id = ?',
            [$id]
        ) ?: [];

        $sEsd = $this->moduleManager->Basket()->sCheckForESD();
        $isMobile = $this->front->Request()->getDeviceType() === 'mobile';

        $customer = $user;
        if (!\is_array($customer)) {
            $customer = [];
        }

        $paymentId = $data['id'] ?? null;

        // Check for risk management         // If rules match, reset to default payment mean if this payment mean was not
$container = Shopware()->Container();

        $category = $container->get('shop')->getCategory();
        $this->categoryId = (int) ($category ? $category->getId() : 0);
        $this->contextService = $contextService ?? $container->get(ContextServiceInterface::class);
        $this->customerGroupId = (int) $this->contextService->getShopContext()->getCurrentCustomerGroup()->getId();

        $this->additionalTextService = $additionalTextService ?? $container->get(AdditionalTextServiceInterface::class);

        $this->config = $config ?? $container->get('config');
        $this->productModule = $productModule ?? $container->get('modules')->Articles();
        $this->basketModule = $basketModule ?? $container->get('modules')->Basket();
        $this->front = $front ?: $container->get('front');
        $this->connection = $connection ?: $container->get(Connection::class);
        $this->modelManager = $modelManager ?: $container->get(ModelManager::class);
        $this->mediaService = $mediaService ?: $container->get(MediaServiceInterface::class);
        $this->storefrontMediaService = $storefrontMediaService ?: $container->get(StorefrontMediaServiceInterface::class);
        $this->legacyStructConverter = $legacyStructConverter ?: $container->get(LegacyStructConverter::class);
        $this->eventManager = $eventManager ?: $container->get(ContainerAwareEventManager::class);
    }

    /** * @param int $articleId * @param int $limit * * @return array<array<string, mixed>> */


        // Start session in frontend controllers         $session = $this->get('session');

        if ($cookieKey !== null) {
            $session->set($cookieKey$cookieValue);
        }

        // Refresh basket on currency change         if ($session->has('sBasketCurrency') && $shop->getCurrency()->getId() != $session->get('sBasketCurrency')) {
            Shopware()->Modules()->Basket()->sRefreshBasket();
        }

        // Upgrade template         if ($session->has('template') && !empty($session->get('Admin'))) {
            $repository = $this->get(ModelManager::class)->getRepository(Template::class);
            $template = $session->get('template');
            $template = $repository->findOneBy(['template' => $template]);

            $this->get(Enlight_Template_Manager::class)->setTemplateDir([]);

            if ($template !== null) {
                
/** * Pre dispatch method */
    public function preDispatch()
    {
        $this->View()->setScope(Enlight_Template_Manager::SCOPE_PARENT);
        $this->View()->assign('userInfo', $this->get('shopware_account.store_front_greeting_service')->fetch());
    }

    public function postDispatch()
    {
        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'));
    }
$view->assign('sShopname', Shopware()->Config()->get('shopName'));
    }

    /** * Returns basket amount * * @return float */
    public function getBasketAmount()
    {
        $amount = Shopware()->Modules()->Basket()->sGetAmount();

        return empty($amount) ? 0 : array_shift($amount);
    }

    /** * Returns current category id * * @param int $default * * @return int */
    
$modules = $this->container->get('modules');
        $customerData = $modules->Admin()->sGetUserData();
        $session = $this->container->get('session');

        if (\is_array($customerData)) {
            $session->offsetSet('sCountry', (int) $customerData['additional']['countryShipping']['id']);
            $session->offsetSet('sArea', (int) $customerData['additional']['countryShipping']['areaID']);
        }

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

        $modules->Basket()->sRefreshBasket();
    }

    private function forwardDownloadError(int $errorCode): void
    {
        $this->View()->assign('sErrorCode', $errorCode);

        $this->forward('downloads');
    }

    /** * @param array<string, mixed> $orderData * * @return array<string, mixed> */

    protected $session;

    /** * Pre dispatch method */
    public function preDispatch()
    {
        $this->module = Shopware()->Modules()->Basket();
        $this->session = Shopware()->Session();
        $this->Response()->setHeader('x-robots-tag', 'noindex');
    }

    public function infoAction()
    {
        $view = $this->View();

        $view->assign('userInfo', $this->get('shopware_account.store_front_greeting_service')->fetch());
        $view->assign('sBasketQuantity', isset($this->session->sBasketQuantity) ? $this->session->sBasketQuantity : 0);
        $view->assign('sBasketAmount', isset($this->session->sBasketAmount) ? $this->session->sBasketAmount : 0);
        
/** * Will be called when no action is supplied */
    public function indexAction()
    {
        $sTarget = $this->Request()->getParam('sTarget', 'account');
        $sTargetAction = $this->Request()->getParam('sTargetAction', 'index');

        $this->View()->assign([
            'sTarget' => $sTarget,
            'sTargetAction' => $sTargetAction,
            'sEsd' => Shopware()->Modules()->Basket()->sCheckForESD(),
            'showNoAccount' => $this->Request()->getParam('showNoAccount', false),
            'accountMode' => $this->Request()->getParam('skipLogin'),
        ]);

        if ($this->shouldRedirectToAccount()) {
            $this->forward('index', 'account');

            return;
        }

        if ($this->shouldRedirectToCheckout()) {
            
 catch (InvalidOrderNumberException $exception) {
                        // Explicit empty catch                     } catch (TypeError $exception) {
                        // Explicit empty catch                     }
                }

                if ($element['name'] === 'inquiry' && !empty($this->Request()->sInquiry)) {
                    switch ($this->Request()->sInquiry) {
                        case 'basket':
                            $text = Shopware()->Snippets()->getNamespace('frontend/detail/comment')->get('InquiryTextBasket');
                            $getBasket = Shopware()->Modules()->Basket()->sGetBasket();
                            foreach ($getBasket[CartKey::POSITIONS] ?? [] as $basketRow) {
                                if (empty($basketRow['modus'])) {
                                    $text .= sprintf(
                                        "\n%s x %s (%s) - %s %s",
                                        $basketRow['quantity'],
                                        $basketRow['articlename'],
                                        $basketRow['ordernumber'],
                                        $basketRow['price'],
                                        Shopware()->System()->sCurrency['currency']
                                    );
                                }
                            }
/** * 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',
            'ajaxDeleteArticle',
            
Home | Imprint | This part of the site doesn't use cookies.