Exemplo n.º 1
0
 /**
  * Shopware\EventListener: Enlight_Controller_Front_RouteShutdown
  *
  * @param \Enlight_Controller_EventArgs $args
  */
 public function registerBackendTheme(\Enlight_Controller_EventArgs $args)
 {
     if ($args->getRequest()->getModuleName() != 'backend') {
         return;
     }
     $directory = $this->container->get('theme_path_resolver')->getExtJsThemeDirectory();
     $this->container->get('template')->setTemplateDir(array('backend' => $directory, 'include_dir' => '.'));
 }
Exemplo n.º 2
0
 /**
  * Generates a mediaUrl based on the request or router
  *
  * @return string
  * @throws \Exception
  */
 private function createFallbackMediaUrl()
 {
     $request = $this->container->get('front')->Request();
     if ($request && $request->getHttpHost()) {
         return ($request->isSecure() ? 'https' : 'http') . '://' . $request->getHttpHost() . $request->getBasePath() . "/";
     } else {
         return $this->container->get('front')->Router()->assemble(['controller' => 'index', 'module' => 'frontend']);
     }
 }
 /**
  * Listener method of the Enlight_Controller_Front_DispatchLoopShutdown event.
  * On Dispatch Shutdown collects results and dumps to log component.
  *
  * @param \Enlight_Event_EventArgs $args
  */
 public function onDispatchLoopShutdown(\Enlight_Event_EventArgs $args)
 {
     /** @var \Enlight_Controller_Request_Request $request */
     $request = $args->getSubject()->Request();
     /** @var Clockwork $clockwork */
     $clockwork = $this->container->get('shopwareclockwork.clockwork');
     /** @var \Enlight_Controller_Response_ResponseHttp $response */
     $response = $args->getResponse();
     $response->setHeader("X-Clockwork-Id", $clockwork->getRequest()->id);
     $response->setHeader("X-Clockwork-Version", $clockwork::VERSION);
     $response->setHeader("X-Clockwork-Path", '/Clockwork/index/id/');
     $shopwareDataSource = $this->container->get('shopwareclockwork.datasource');
     $shopwareDataSource->setBaseInfo($request);
     $clockwork->addDataSource(new PhpDataSource());
     $clockwork->addDataSource($shopwareDataSource);
     $clockwork->resolveRequest();
     $clockwork->storeRequest();
 }
Exemplo n.º 4
0
 /**
  * Collects third party adapters
  *
  * @param array $config
  * @return AdapterInterface
  * @throws \Enlight_Event_Exception
  * @throws \Exception
  */
 private function collectAdapterByType($config)
 {
     $adapters = new ArrayCollection();
     $adapters = $this->container->get('events')->collect('Shopware_Collect_MediaAdapter_' . $config['type'], $adapters, ['config' => $config]);
     $adapter = $adapters->first();
     if (!$adapter) {
         throw new \Exception("CDN Adapter '" . $config['type'] . "' not found.");
     }
     return $adapter;
 }
Exemplo n.º 5
0
 /**
  * Live migration to fill width/height
  *
  * @param LifecycleEventArgs $eventArgs
  * @throws \Exception
  */
 private function migrateMeta(LifecycleEventArgs $eventArgs)
 {
     $media = $eventArgs->getEntity();
     if (!$media instanceof Media) {
         return;
     }
     if ($media->getType() !== Media::TYPE_IMAGE) {
         return;
     }
     $mediaService = $this->container->get('shopware_media.media_service');
     if ((!$media->getHeight() || !$media->getWidth()) && $mediaService->has($media->getPath())) {
         list($width, $height) = getimagesizefromstring($mediaService->read($media->getPath()));
         if ($media->getId()) {
             $eventArgs->getEntityManager()->getConnection()->executeUpdate('UPDATE s_media SET width = :width, height = :height WHERE id = :id', [':width' => $width, ':height' => $height, ':id' => $media->getId()]);
         }
         $media->setWidth($width);
         $media->setHeight($height);
     }
 }
Exemplo n.º 6
0
 /**
  * Collect mails
  * @param \Enlight_Event_EventArgs $args
  */
 public function onSendMails(\Enlight_Event_EventArgs $args)
 {
     /** @var \Enlight_Components_Mail $mail */
     $mail = $args->get('mail');
     $context = $this->container->get('templatemail')->getStringCompiler()->getContext();
     /**
      * Remove some objects
      */
     unset($context['sConfig']);
     $this->mails[] = ['from' => $mail->getFrom(), 'fromName' => $mail->getFromName(), 'to' => $mail->getTo(), 'subject' => $mail->getSubject(), 'bodyPlain' => $mail->getPlainBodyText(), 'bodyHtml' => $mail->getPlainBody(), 'context' => $context];
 }
Exemplo n.º 7
0
 /**
  * @param \Enlight_Event_EventArgs $args
  * @throws \Exception
  */
 public function onDispatch(\Enlight_Event_EventArgs $args)
 {
     /**@var $controller \Enlight_Controller_Action*/
     $controller = $args->get('subject');
     if (!$controller->View()) {
         return;
     }
     /**@var $shop Shop*/
     $shop = $this->container->get('shop');
     if ($shop->getTemplate()->getVersion() < 3) {
         return;
     }
     $templateManager = $this->container->get('template');
     $themeSettings = $templateManager->getTemplateVars('theme');
     if (!empty($themeSettings)) {
         return;
     }
     $inheritance = $this->container->get('theme_inheritance');
     $config = $inheritance->buildConfig($shop->getTemplate(), $shop, false);
     $templateManager->addPluginsDir($inheritance->getSmartyDirectories($shop->getTemplate()));
     $templateManager->assign('theme', $config);
 }
 protected function getCategoryTree($id, $mainId)
 {
     $sql = '
         SELECT `id`, `description`, `parent`
         FROM `s_categories`
         WHERE `id` = ?
     ';
     $cat = $this->container->get('db')->fetchRow($sql, array($id));
     if (empty($cat['id']) || $id == $cat['parent'] || $id == $mainId) {
         return array();
     } else {
         $cats = $this->getCategoryTree($cat['parent'], $mainId);
         $cats[$id] = $cat;
         return $cats;
     }
 }
Exemplo n.º 9
0
 /**
  * @return string
  */
 private function buildBaseUrl()
 {
     /** @var $config \Shopware_Components_Config */
     $config = $this->container->get('config');
     $request = null;
     if ($this->container->initialized('front')) {
         /** @var $front \Enlight_Controller_Front */
         $front = $this->container->get('front');
         $request = $front->Request();
     }
     if ($request !== null) {
         $baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
     } else {
         $baseUrl = 'http://' . $config->get('basePath');
     }
     return $baseUrl;
 }
Exemplo n.º 10
0
 /**
  * This helper method will reload the EntityManager.
  * This is useful if the EntityManager was closed due to an error on the
  * PDO connection.
  */
 protected function resetEntityManager()
 {
     $this->getContainer()->reset('models')->reset('db_connection')->load('models');
     $this->getContainer()->load('db_connection');
     $this->setManager($this->container->get('models'));
 }
Exemplo n.º 11
0
 /**
  * Runs the garbage collector
  *
  * @return bool
  * @throws \Exception
  */
 public function runCronjob()
 {
     $garbageCollector = $this->container->get('shopware_media.garbage_collector');
     $garbageCollector->run();
     return true;
 }
Exemplo n.º 12
0
 /**
  * @return SettingsInterface[]
  * @throws \Enlight_Event_Exception
  */
 private function collectSettings()
 {
     $collection = new ArrayCollection();
     $this->container->get('events')->collect('Shopware_ESIndexingBundle_Collect_Settings', $collection);
     return array_merge($collection->toArray(), $this->settings);
 }
Exemplo n.º 13
0
 public function registerFacetHandler()
 {
     return new EsdFacetHandler($this->container->get('shopware_searchdbal.dbal_query_builder_factory'), $this->container->get('snippets'));
 }
Exemplo n.º 14
0
 /**
  * Smarty preFilter callback. Modify template and return
  *
  * @param $source
  * @param $template
  * @return mixed
  */
 public function preFilter($source, $template)
 {
     return $this->container->get('shyim_profiler.block_annotator')->annotate($source);
 }
Exemplo n.º 15
-1
 /**
  * @return DefaultSortRequestHandler
  */
 private function getSortRequestHandler()
 {
     if (!$this->sortRequestHandler) {
         $this->sortRequestHandler = new DefaultSortRequestHandler($this->container->get('swag_default_sort.database_adapter'), $this->container->get('swag_default_sort.rule_vo_hydrator'));
     }
     return $this->sortRequestHandler;
 }
Exemplo n.º 16
-1
 /**
  * Sets the Container.
  *
  * @param Container $container
  */
 public function setContainer(Container $container = null)
 {
     if ($container) {
         $this->request = $container->get('front')->Request();
         $this->cacheManager = $container->get('shopware.cache_manager');
     }
 }
Exemplo n.º 17
-1
 /**
  * Loads the Zend resource and initials the Enlight_Controller_Front class.
  * After the front resource is loaded, the controller path is added to the
  * front dispatcher. After the controller path is set to the dispatcher,
  * the plugin namespace of the front resource is set.
  *
  * @param Container $container
  * @param \Shopware_Bootstrap $bootstrap
  * @param \Enlight_Event_EventManager $eventManager
  * @param array $options
  * @throws \Exception
  * @return \Enlight_Controller_Front
  */
 public function factory(Container $container, \Shopware_Bootstrap $bootstrap, \Enlight_Event_EventManager $eventManager, array $options)
 {
     /** @var $front \Enlight_Controller_Front */
     $front = \Enlight_Class::Instance('Enlight_Controller_Front', array($eventManager));
     $front->setDispatcher($container->get('Dispatcher'));
     $front->Dispatcher()->addModuleDirectory(Shopware()->AppPath('Controllers'));
     $front->setRouter($container->get('Router'));
     $front->setParams($options);
     /** @var $plugins  \Enlight_Plugin_PluginManager */
     $plugins = $container->get('Plugins');
     $plugins->registerNamespace($front->Plugins());
     $front->setParam('bootstrap', $bootstrap);
     if (!empty($options['throwExceptions'])) {
         $front->throwExceptions((bool) $options['throwExceptions']);
     }
     try {
         $container->load('Cache');
         $container->load('Db');
         $container->load('Plugins');
     } catch (\Exception $e) {
         if ($front->throwExceptions()) {
             throw $e;
         }
         $front->Response()->setException($e);
     }
     return $front;
 }
Exemplo n.º 18
-1
 /**
  * @param Container $container
  * @return \Enlight_Components_Session_Namespace
  */
 public function factory(Container $container)
 {
     $sessionOptions = Shopware()->getOption('session', array());
     if (!empty($sessionOptions['unitTestEnabled'])) {
         \Enlight_Components_Session::$_unitTestEnabled = true;
     }
     unset($sessionOptions['unitTestEnabled']);
     if (\Enlight_Components_Session::isStarted()) {
         \Enlight_Components_Session::writeClose();
     }
     /** @var $shop \Shopware\Models\Shop\Shop */
     $shop = $container->get('Shop');
     $name = 'session-' . $shop->getId();
     $sessionOptions['name'] = $name;
     if (!isset($sessionOptions['save_handler']) || $sessionOptions['save_handler'] == 'db') {
         $config_save_handler = array('db' => $container->get('Db'), 'name' => 's_core_sessions', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'expiry');
         \Enlight_Components_Session::setSaveHandler(new \Enlight_Components_Session_SaveHandler_DbTable($config_save_handler));
         unset($sessionOptions['save_handler']);
     }
     \Enlight_Components_Session::start($sessionOptions);
     $container->set('SessionID', \Enlight_Components_Session::getId());
     $namespace = new \Enlight_Components_Session_Namespace('Shopware');
     $namespace->offsetSet('sessionId', \Enlight_Components_Session::getId());
     return $namespace;
 }
Exemplo n.º 19
-1
 /**
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     $this->container = $container;
     $this->cache = $container->get('cache');
     $this->emConfig = $container->get('shopware.model_config');
     $this->db = $container->get('db');
     $this->config = $container->get('config');
     $this->events = $container->get('events');
 }
Exemplo n.º 20
-1
 /**
  * @param sArticles $articleModule
  * @param Container $container
  */
 public function __construct(sArticles $articleModule, Container $container)
 {
     $this->articleModule = $articleModule;
     $this->systemModule = $articleModule->sSYSTEM;
     $this->db = $container->get('db');
     $this->config = $container->get('config');
     $this->session = $container->get('session');
     $this->contextService = $container->get('shopware_storefront.context_service');
 }
Exemplo n.º 21
-1
 /**
  * @param Container $container
  * @return \Shopware_Components_TemplateMail
  */
 public function factory(Container $container)
 {
     $container->load('MailTransport');
     $stringCompiler = new \Shopware_Components_StringCompiler($container->get('Template'));
     $mailer = new \Shopware_Components_TemplateMail();
     if ($container->initialized('Shop')) {
         $mailer->setShop($container->get('Shop'));
     }
     $mailer->setModelManager($container->get('Models'));
     $mailer->setStringCompiler($stringCompiler);
     return $mailer;
 }
Exemplo n.º 22
-1
 public function onFilterCollectors(\Enlight_Event_EventArgs $arguments)
 {
     $collectors = $arguments->getReturn();
     $utils = $arguments->get('utils');
     foreach ($collectors as $key => $collector) {
         if ($collector instanceof EventCollector) {
             $collectors[$key] = new ClockworkEventCollector($arguments->get('eventManager'), $utils);
         } elseif ($collector instanceof TemplateCollector) {
             $collectors[$key] = new ClockworkTemplateCollector($this->container->get('template'), $utils, $this->container->get('kernel')->getRootDir());
         }
     }
     return $collectors;
 }
Exemplo n.º 23
-1
 /**
  * @param Container $container
  * @param EnlightEventManager $eventManager
  * @return \Shopware\Components\Routing\RouterInterface
  * @throws \Exception
  */
 public function factory(Container $container, EnlightEventManager $eventManager)
 {
     $queryAliasMapper = $container->get('query_alias_mapper');
     $matchers = [new Matchers\RewriteMatcher($container->get('dbal_connection'), $queryAliasMapper), new Matchers\EventMatcher($eventManager), new Matchers\DefaultMatcher($container->get('dispatcher'))];
     $generators = [new Generators\RewriteGenerator($container->get('dbal_connection'), $queryAliasMapper), new Generators\DefaultGenerator($container->get('dispatcher'))];
     $preFilters = [new GeneratorFilters\DefaultPreFilter(), new GeneratorFilters\FrontendPreFilter()];
     $postFilters = [new GeneratorFilters\FrontendPostFilter(), new GeneratorFilters\DefaultPostFilter()];
     $router = new \Shopware\Components\Routing\Router(Context::createEmpty(), $matchers, $generators, $preFilters, $postFilters);
     /** Still better than @see \Shopware\Models\Shop\Shop::registerResources */
     $eventManager->addListener('Enlight_Bootstrap_AfterRegisterResource_Shop', array($this, 'onAfterRegisterShop'), -100);
     $eventManager->addListener('Enlight_Controller_Front_PreDispatch', array($this, 'onPreDispatch'), -100);
     return $router;
 }
 /**
  * @param $containers
  * @param $orderData
  * @return mixed
  * @throws Exception
  */
 public function getPayPalInvoiceContentInfo($containers, $orderData)
 {
     $footer = $containers['Paypal_Content_Info'];
     $translationComp = new Shopware_Components_Translation();
     $translation = $translationComp->read($orderData['_order']['language'], 'documents', 1);
     $query = "SELECT * FROM s_core_documents_box WHERE id = ?";
     /** @var Enlight_Components_Db_Adapter_Pdo_Mysql $databaseConnection */
     $databaseConnection = $this->container->get('db');
     $rawFooter = $databaseConnection->fetchAssoc($query, array($footer['id']));
     if (!empty($translation[1]["Paypal_Content_Info_Value"])) {
         $rawFooter["value"] = $translation[1]["Paypal_Content_Info_Value"];
     }
     return $rawFooter[$footer['id']];
 }
Exemplo n.º 25
-1
 /**
  * Returns template cache information
  *
  * @return array
  */
 public function getThemeCacheInfo()
 {
     $dir = $this->container->get('theme_path_resolver')->getCacheDirectory();
     $info = $this->getDirectoryInfo($dir);
     $info['name'] = 'Shopware theme';
     return $info;
 }
Exemplo n.º 26
-1
 /**
  * This wraps Shopware:run execution and does not execute
  * the default dispatching process from symfony.
  * Therefore:
  * Arguments are currently ignored. No dispatcher, no response handling.
  * Shopware instance returns currently the rendered response directly.
  *
  * {@inheritdoc}
  *
  * @return SymfonyResponse
  */
 public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if (false === $this->booted) {
         $this->boot();
     }
     /** @var $front \Enlight_Controller_Front **/
     $front = $this->container->get('front');
     // alays return response from front controller
     // the response will be transformed to a symfony response
     // this is required for the http-cache to work
     $front->returnResponse(true);
     $request = $this->transformSymfonyRequestToEnlightRequest($request);
     if ($front->Request() === null) {
         $front->setRequest($request);
         $response = $front->dispatch();
     } else {
         $dispatcher = clone $front->Dispatcher();
         $response = clone $front->Response();
         $response->clearHeaders()->clearRawHeaders()->clearBody();
         $response->setHttpResponseCode(200);
         $request->setDispatched(true);
         $dispatcher->dispatch($request, $response);
     }
     $response = $this->transformEnlightResponseToSymfonyResponse($response);
     return $response;
 }
Exemplo n.º 27
-1
 private function processQueue()
 {
     if (empty($this->queue)) {
         return;
     }
     $this->container->get('shopware_elastic_search.backlog_processor')->add($this->queue);
     $this->queue = [];
 }
Exemplo n.º 28
-1
 /**
  * @param Container    $container
  * @param \Zend_Locale      $locale
  *
  * @return \Zend_Currency
  */
 public function factory(Container $container, \Zend_Locale $locale)
 {
     $currency = 'EUR';
     if ($container->has('Shop')) {
         $currency = $container->get('Shop')->getCurrency()->getCurrency();
     }
     return new \Zend_Currency($currency, $locale);
 }
Exemplo n.º 29
-1
 /**
  * Get and setup ProductService Component
  *
  * This method also does the setup like autoloading.
  *
  * @return \Shopware_StoreApi_Core_Service_Product
  */
 private function getProductService()
 {
     /** @var $communityStore CommunityStore */
     $communityStore = $this->container->get('CommunityStore');
     $storeApi = $communityStore->getApi();
     $productService = $storeApi->getProductService();
     return $productService;
 }
Exemplo n.º 30
-1
 /**
  * @param Container $container
  * @return \Zend_Locale
  */
 public function factory(Container $container)
 {
     $locale = 'de_DE';
     if ($container->has('Shop')) {
         $locale = $container->get('Shop')->getLocale()->getLocale();
     }
     return new \Zend_Locale($locale);
 }