Template example

$cacheDir = Shopware()->Container()->getParameter('shopware.product_export.cache_dir');
        if (!is_dir($cacheDir)) {
            if (@mkdir($cacheDir, 0777, true) === false) {
                throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", 'Productexport', $cacheDir));
            }
        } elseif (!is_writable($cacheDir)) {
            throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", 'Productexport', $cacheDir));
        }

        $export = Shopware()->Modules()->Export();
        $export->sSYSTEM = Shopware()->System();
        $sSmarty = Shopware()->Template();

        $productFeedRepository = Shopware()->Models()->getRepository(ProductFeed::class);
        $activeFeeds = $productFeedRepository->getActiveListQuery()->getResult();
        foreach ($activeFeeds as $feedModel) {
            $fileName = $feedModel->getHash() . '_' . $feedModel->getFileName();
            $filePath = $cacheDir . $fileName;

            if ($feedModel->getInterval() === 0) {
                continue;
            } elseif ($feedModel->getInterval() > 0) {
                $diffInterval = time();
                
parent::postDispatch();

        $this->View()->assign('sType', $this->type);
        $this->View()->assign('sFields', $this->getFields());
        $this->View()->assign('sAction', $this->Request()->getActionName());
        $this->View()->assign('sTitleKey', $this->type->getViewTitleFieldName());
        $this->View()->assign('sMetaTitleKey', $this->type->getViewMetaTitleFieldName());
        $this->View()->assign('sDescriptionKey', $this->type->getViewDescriptionFieldName());
        $this->View()->assign('sMetaDescriptionKey', $this->type->getViewMetaDescriptionFieldName());
        $this->View()->assign('sImageKey', $this->type->getViewImageFieldName());

        if (!$this->View()->templateExists($this->View()->Template()->template_resource)) {
            if ($this->Request()->getActionName() === 'index') {
                $this->View()->Template()->template_resource = 'frontend/content_type/index.tpl';

                return;
            }

            $this->View()->Template()->template_resource = 'frontend/content_type/detail.tpl';
        }
    }

    public function getBreadcrumb(?array $item = null): array
    {


    public function onRegisterControllerTemplate(Enlight_Controller_ActionEventArgs $args): void
    {
        $viewsDirectory = $this->pluginPath . '/Resources/views';

        $controller = $args->getSubject();

        try {
            $view = $controller->View();
            if ($view !== null) {
                $view->Template()->Engine()->addTemplateDir($viewsDirectory);
            }
        } catch (Enlight_Exception $ignored) {
        }
    }

    /** * @param string $baseDir resource base directory * @param string $type `css` or `js` * * @return array<string> */
    
Enlight_Template_Manager $template = null,
        ?Shopware_Components_Modules $moduleManager = null,
        ?SlugInterface $slug = null,
        ?ContextServiceInterface $contextService = null,
        ?ShopPageServiceInterface $shopPageService = null,
        ?Shopware_Components_Translation $translationComponent = null
    ) {
        $this->db = $db ?: Shopware()->Db();
        $this->config = $config ?: Shopware()->Config();
        $this->modelManager = $modelManager ?: Shopware()->Models();
        $this->sSYSTEM = $systemModule ?: Shopware()->System();
        $this->template = $template ?: Shopware()->Template();
        $this->moduleManager = $moduleManager ?: Shopware()->Modules();
        $this->slug = $slug ?: Shopware()->Container()->get('shopware.slug');
        $this->contextService = $contextService ?: Shopware()->Container()->get(ContextServiceInterface::class);
        $this->shopPageService = $shopPageService ?: Shopware()->Container()
            ->get('shopware_storefront.shop_page_service');
        $this->translationComponent = $translationComponent ?: Shopware()->Container()->get(Shopware_Components_Translation::class);
    }

    /** * Getter function for retrieving last ID from sCreateRewriteTableArticles() * * @return string|null */
/** * @return ValidationException */
    public static function createFromFormError(FormErrorIterator $errors)
    {
        $violations = [];

        foreach ($errors as $error) {
            if (!$error instanceof FormError) {
                continue;
            }
            $message = Shopware()->Template()->fetch('string:' . $error->getMessage());

            $origin = $error->getOrigin();
            $violations[] = new ConstraintViolation(
                $message,
                $error->getMessageTemplate(),
                $error->getMessageParameters(),
                $origin ? $origin->getRoot() : null,
                $origin ? (string) $origin->getPropertyPath() : null,
                $origin ? $origin->getData() : null,
                $error->getMessagePluralization(),
                null,
                
$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 */
    public function setAddressAction()
    {

    public function initTemplate($mailing)
    {
        $template = clone Shopware()->Template();
        $shop = Shopware()->Shop();
        $inheritance = Shopware()->Container()->get('theme_inheritance');

        $config = $inheritance->buildConfig(
            $shop->getTemplate(),
            $shop,
            false
        );

        $user = $this->getMailingUserByEmail(Shopware()->Config()->get('Mail'));
        $template->assign('sUser', $user, true);
        
$customerEmail = (string) Shopware()->Models()->createQueryBuilder()
            ->select('customer.email')
            ->from(Customer::class, 'customer')
            ->where('customer.id = ?1')
            ->setParameter(1, $userId)
            ->getQuery()
            ->getSingleScalarResult();

        $mail->addTo($customerEmail);

        Shopware()->Template()->assign('data', [
            'orderNumber' => $orderNumber,
            'accountHolder' => $data['account_holder'],
            'address' => $data['address'],
            'city' => $data['city'],
            'zipCode' => $data['zipcode'],
            'bankName' => $data['bank_name'],
            'iban' => $data['iban'],
            'bic' => $data['bic'],
        ]);
        Shopware()->Template()->assign('config', [
            'sepaCompany' => Shopware()->Config()->get('sepaCompany'),
            
return $this;
    }

    /** * Renders the Enlight_Template_Default of the Enlight_View_Default * which is set in the Enlight_Controller_Action. * * @return Enlight_Controller_Plugins_ViewRenderer_Bootstrap */
    public function render()
    {
        $template = $this->Action()->View()->Template();

        return $this->renderTemplate($template);
    }

    /** * Checks if the template should be rendered. * * @return bool */
    public function shouldRender()
    {
        
$contentType = $controller->Response()->headers->get('content-type', 'text/html');

        if (strpos($contentType, 'text/html') !== 0) {
            return false;
        }

        if (!$controller->View()->hasTemplate() || \in_array(strtolower($controller->Request()->getModuleName())['backend', 'api'])) {
            return false;
        }

        $templateFile = $controller->View()->Template()->template_resource;

        if (substr($templateFile, -3) === '.js') {
            return false;
        }

        // The cart page can become very slow very fast due to many html tags for amount selections         return $controller->Front()->Request()->getControllerName() !== 'checkout';
    }
}
->where('detail.id = :id')
            ->setParameter('id', $article->getMainDetail()->getId());

        $data = $builder->getQuery()->getArrayResult();
        $data = $data[0];

        foreach ($data['prices'] as &$price) {
            $customerGroup = $this->getCustomerGroupRepository()->find($price['customerGroup']['id']);
            $price['customerGroup'] = $customerGroup;
        }

        $template = new Template();
        $template->fromArray($data);
        $template->setArticle($article);

        if ($data['unitId']) {
            $productUnit = $this->get('models')->find(Unit::class$data['unitId']);
            if ($productUnit !== null) {
                $template->setUnit($productUnit);
            }
        }

        $this->get('models')->persist($template);
        

    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();
            $system->sSESSION_ID = Shopware()->Session()->get('sessionId');
            if ($request !== null && Shopware()->Session()->get('Bot') === null) {
                /** @var Shopware_Plugins_Frontend_Statistics_Bootstrap $plugin */
                $plugin = Shopware()->Plugins()->Frontend()->Statistics();
                Shopware()->Session()->set('Bot', $plugin->checkIsBot($request->getHeader('USER_AGENT') ?: ''));
            }
            
$listener->onKernelView($event);
        $this->assertSame('Bar', $event->getResponse()->getContent());

        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, null, $controllerArgumentsEvent);
        $listener->onKernelView($event);
        $this->assertSame('Bar', $event->getResponse()->getContent());

        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, null);
        $listener->onKernelView($event);
        $this->assertNull($event->getResponse());

        $request->attributes->set('_template', new Template('templates/foo.html.twig'));
        $event = new ViewEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, []);
        $listener->onKernelView($event);
        $this->assertSame('Bar', $event->getResponse()->getContent());
    }

    public function testForm()
    {
        $request = new Request();
        $kernel = $this->createMock(HttpKernelInterface::class);
        $controllerArgumentsEvent = new ControllerArgumentsEvent($kernel[new TemplateAttributeController(), 'foo'][]$request, null);
        $listener = new TemplateAttributeListener($this->createMock(Environment::class));

        
'email' => trim($user['email']),
            'frommail' => $mail->getFrom(),
            'fromname' => $mail->getFromName(),
        ];

        $return = $this->eventManager->filter('Shopware_Controllers_Backend_OrderState_Filter', $return[
            'subject' => Shopware()->Front(),
            'id' => $orderId,
            'status' => $statusId,
            'mailname' => $templateName,
            'mail' => $mail,
            'engine' => Shopware()->Template(),
        ]);

        $mail->clearSubject();
        $mail->setSubject($return['subject']);

        $mail->setBodyText($return[CartKey::POSITIONS]);

        $mail->clearFrom();
        $mail->setFrom($return['frommail']$return['fromname']);

        $mail->addTo($return['email']);

        


    /** * Initiate smarty template engine * * @throws Exception */
    protected function initTemplateEngine()
    {
        $frontendThemeDirectory = Shopware()->Container()->get(PathResolver::class)->getFrontendThemeDirectory();

        $this->_template = clone Shopware()->Template();
        $this->_view = $this->_template->createData();

        $path = basename($this->_subshop['doc_template']);

        if ($this->_template->security_policy) {
            $this->_template->security_policy->secure_dir[] = $frontendThemeDirectory . DIRECTORY_SEPARATOR . $path;
        }
        $this->_template->setTemplateDir(['custom' => $path]);
        $this->_template->setCompileId(str_replace('/', '_', $path) . '_' . $this->_subshop['id']);
    }

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