/** * Clear HTTP-Cache */ public function clearHttpCache() { $cacheDir = $this->container->getParameter('shopware.httpCache.cache_dir'); $this->clearDirectory($cacheDir); // Fire event to let Plugin-Implementation clear cache $this->events->notify('Shopware_Plugins_HttpCache_ClearCache'); }
/** * Helper function for sLogin * Called when provided user data is incorrect * Handles account lockdown detection and brute force protection * * @param $addScopeSql * @param $email * @param $sErrorMessages * @param $password * @return array */ private function failedLoginUser($addScopeSql, $email, $sErrorMessages, $password) { // Check if account is disabled $sql = "SELECT id FROM s_user WHERE email=? AND active=0 " . $addScopeSql; $getUser = $this->db->fetchOne($sql, array($email)); if ($getUser) { $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('LoginFailureActive', 'Your account is disabled. Please contact us.'); } else { $getLockedUntilTime = $this->db->fetchOne("SELECT 1 FROM s_user WHERE email = ? AND lockeduntil > NOW()", array($email)); if (!empty($getLockedUntilTime)) { $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('LoginFailureLocked', 'Too many failed logins. Your account was temporary deactivated.'); } else { $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('LoginFailure', 'Wrong email or password'); } } // Prevent brute force login attempts if (!empty($email)) { $sql = "\n UPDATE s_user SET\n failedlogins = failedlogins + 1,\n lockeduntil = IF(\n failedlogins > 4,\n DATE_ADD(NOW(), INTERVAL (failedlogins + 1) * 30 SECOND),\n NULL\n )\n WHERE email = ? " . $addScopeSql; $this->db->query($sql, array($email)); } $this->eventManager->notify('Shopware_Modules_Admin_Login_Failure', array('subject' => $this, 'email' => $email, 'password' => $password, 'error' => $sErrorMessages)); $this->session->offsetUnset('sUserMail'); $this->session->offsetUnset('sUserPassword'); $this->session->offsetUnset('sUserId'); return $sErrorMessages; }
/** * Check if article is already in basket * * @param int $articleId * @param string $ordernumber * @param string $sessionId * @return array Example: ["id" => "731", "quantity" => "100"] */ private function checkIfArticleIsInBasket($articleId, $ordernumber, $sessionId) { $builder = Shopware()->Models()->getConnection()->createQueryBuilder(); $builder->select('id', 'quantity')->from('s_order_basket', 'basket')->where('articleID = :articleId')->andWhere('sessionID = :sessionId')->andWhere('ordernumber = :ordernumber')->andWhere('modus != 1')->setParameter('articleId', $articleId)->setParameter('sessionId', $sessionId)->setParameter('ordernumber', $ordernumber); $this->eventManager->notify('Shopware_Modules_Basket_AddArticle_CheckBasketForArticle', array('queryBuilder' => $builder, 'subject' => $this)); /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */ $statement = $builder->execute(); return $statement->fetch() ?: array(); }
/** * @param Request $request * @param ShopContextInterface $context * @param int $categoryId * @return \Shopware\Bundle\SearchBundle\Criteria */ public function createProductNavigationCriteria(Request $request, ShopContextInterface $context, $categoryId) { $criteria = $this->createCriteriaFromRequest($request, $context); $criteria->offset(0)->limit(null); $criteria->removeCondition('category'); $criteria->addBaseCondition(new CategoryCondition([$categoryId])); $this->eventManager->notify('Shopware_SearchBundle_Create_Product_Navigation_Criteria', ['criteria' => $criteria, 'request' => $request, 'context' => $context]); $criteria->resetFacets(); return $criteria; }
/** * Returns the query builder object to select the theme configuration for the * current shop. * * @param \Shopware\Models\Shop\Template $template * @param boolean $lessCompatible * @return \Doctrine\ORM\QueryBuilder|\Shopware\Components\Model\QueryBuilder * @throws \Enlight_Event_Exception */ private function getShopConfigQuery(Shop\Template $template, $lessCompatible) { $builder = $this->entityManager->createQueryBuilder(); $builder->select(array('element.name', 'values.value', 'element.defaultValue', 'element.type')); $builder->from('Shopware\\Models\\Shop\\TemplateConfig\\Element', 'element')->leftJoin('element.values', 'values', 'WITH', 'values.shopId = :shopId')->where('element.templateId = :templateId'); if ($lessCompatible) { $builder->andWhere('element.lessCompatible = 1'); } $this->eventManager->notify('Theme_Inheritance_Shop_Query_Built', array('builder' => $builder, 'template' => $template)); return $builder; }
/** * Helper function which compiles the passed less definition. * The shop parameter is required to build the shop url for the files. * * @param Shop\Shop $shop * @param LessDefinition $definition */ private function compileLessDefinition(Shop\Shop $shop, LessDefinition $definition) { //set unique import directory for less @import commands if ($definition->getImportDirectory()) { $this->compiler->setImportDirectories(array($definition->getImportDirectory())); } //allows to add own configurations for the current compile step. if ($definition->getConfig()) { $this->compiler->setVariables($definition->getConfig()); } $this->eventManager->notify('Theme_Compiler_Compile_Less', array('shop' => $shop, 'less' => $definition)); //needs to iterate files, to generate source map if configured. foreach ($definition->getFiles() as $file) { if (!file_exists($file)) { continue; } //creates the url for the compiler, this url will be prepend to each relative path. //the url is additionally used for the source map generation. $url = $this->formatPathToUrl($file); $this->compiler->compile($file, $url); } }
/** * Synchronize the theme configuration sets of the file system and * the database. * * @param Theme $theme * @param Shop\Template $template * @throws \Exception */ private function synchronizeSets(Theme $theme, Shop\Template $template) { $collection = new ArrayCollection(); $theme->createConfigSets($collection); $synchronized = array(); //iterates all configurations sets of the file system foreach ($collection as $item) { if (!$item instanceof ConfigSet) { throw new \Exception(sprintf("Theme %s adds a configuration set which isn't an instance of Shopware\\Components\\Theme\\ConfigSet.", $theme->getTemplate())); } $item->validate(); //check if this set is already defined, to prevent auto increment in the database. $existing = $this->getExistingConfigSet($template->getConfigSets(), $item->getName()); //if the set isn't defined, create a new one if (!$existing instanceof Shop\TemplateConfig\Set) { $existing = new Shop\TemplateConfig\Set(); $template->getConfigSets()->add($existing); } $existing->setTemplate($template); $existing->setName($item->getName()); $existing->setDescription($item->getDescription()); $existing->setValues($item->getValues()); $this->eventManager->notify('Theme_Configurator_Theme_ConfigSet_Updated', array('theme' => $theme, 'template' => $template, 'existing' => $existing, 'defined' => $item)); $synchronized[] = $existing; } //iterates all sets of the template, file system and database foreach ($template->getConfigSets() as $existing) { //check if the current set was synchronized in the foreach before $defined = $this->getExistingConfigSet($synchronized, $existing->getName()); if ($defined instanceof Shop\TemplateConfig\Set) { continue; } //if it wasn't synchronized, the file system theme want to remove the set. $this->entityManager->remove($existing); } $this->entityManager->flush(); $this->eventManager->notify('Theme_Configurator_Theme_ConfigSets_Synchronized', array('theme' => $theme, 'template' => $template)); }
/** * Create status mail * * @param int $orderId * @param int $statusId * @param string $templateName * @return Enlight_Components_Mail */ public function createStatusMail($orderId, $statusId, $templateName = null) { $statusId = (int) $statusId; $orderId = (int) $orderId; if (empty($templateName)) { $templateName = 'sORDERSTATEMAIL' . $statusId; } if (empty($orderId) || !is_numeric($statusId)) { return; } $order = $this->getOrderForStatusMail($orderId); $orderDetails = $this->getOrderDetailsForStatusMail($orderId); if (!empty($order['dispatchID'])) { $dispatch = $this->db->fetchRow(' SELECT name, description FROM s_premium_dispatch WHERE id=? ', array($order['dispatchID'])); } $user = $this->getCustomerInformationByOrderId($orderId); if (empty($order) || empty($orderDetails) || empty($user)) { return; } $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Shop\\Shop'); $shopId = is_numeric($order['language']) ? $order['language'] : $order['subshopID']; $shop = $repository->getActiveById($shopId); $shop->registerResources(Shopware()->Bootstrap()); $order['status_description'] = Shopware()->Snippets()->getNamespace('backend/static/order_status')->get($order['status_name'], $order['status_description']); $order['cleared_description'] = Shopware()->Snippets()->getNamespace('backend/static/payment_status')->get($order['cleared_name'], $order['cleared_description']); /* @var $mailModel \Shopware\Models\Mail\Mail */ $mailModel = Shopware()->Models()->getRepository('Shopware\\Models\\Mail\\Mail')->findOneBy(array('name' => $templateName)); if (!$mailModel) { return; } $context = array('sOrder' => $order, 'sOrderDetails' => $orderDetails, 'sUser' => $user); if (!empty($dispatch)) { $context['sDispatch'] = $dispatch; } $result = $this->eventManager->notify('Shopware_Controllers_Backend_OrderState_Notify', array('subject' => Shopware()->Front(), 'id' => $orderId, 'status' => $statusId, 'mailname' => $templateName)); if (!empty($result)) { $context['EventResult'] = $result->getValues(); } $mail = Shopware()->TemplateMail()->createMail($templateName, $context, $shop); $return = array('content' => $mail->getPlainBodyText(), 'subject' => $mail->getPlainSubject(), 'email' => trim($user['email']), 'frommail' => $mail->getFrom(), 'fromname' => $mail->getFromName()); $return = $this->eventManager->filter('Shopware_Controllers_Backend_OrderState_Filter', $return, array('subject' => Shopware()->Front(), 'id' => $orderId, 'status' => $statusId, 'mailname' => $templateName, 'mail' => $mail, 'engine' => Shopware()->Template())); $mail->clearSubject(); $mail->setSubject($return['subject']); $mail->setBodyText($return['content']); $mail->clearFrom(); $mail->setFrom($return['frommail'], $return['fromname']); $mail->addTo($return['email']); return $mail; }
/** * Dispatch function of the front controller. * * If the flags noErrorHandler and noViewRenderer aren't set, the error handler and the view renderer * plugins will be loaded. After the plugins loaded the Enlight_Controller_Front_StartDispatch * event is notified. * After the event is done, enlight sets the router, dispatcher, request and response object automatically. * If the objects has been set, the Enlight_Controller_Front_RouteStartup event is notified. * After the event is done, the route routes the request to controller/action. * Then the Enlight_Controller_Front_RouteShutdown event and the Enlight_Controller_Front_DispatchLoopStartup * event are notified. After this events the controller runs the dispatch * of the request unless according to request everything was dispatched. During the dispatch * two events are notified:<br> * - Enlight_Controller_Front_PreDispatch => before the dispatch<br> * - Enlight_Controller_Front_PostDispatch => after the dispatch<br><br> * When everything is dispatched the Enlight_Controller_Front_DispatchLoopShutdown event will be notified. * At last the response is sent. As well as the dispatch, two events are notified: * - Enlight_Controller_Front_SendResponse => before the response is sent<br> * - Enlight_Controller_Front_AfterSendResponse => after the response is sent * * @throws Exception * @return Enlight_Controller_Response_ResponseHttp */ public function dispatch() { if (!$this->getParam('noErrorHandler')) { $this->Plugins()->load('ErrorHandler'); } if (!$this->getParam('noViewRenderer')) { $this->Plugins()->load('ViewRenderer'); } $eventArgs = new Enlight_Controller_EventArgs(array('subject' => $this)); $this->eventManager->notify('Enlight_Controller_Front_StartDispatch', $eventArgs); if (!$this->router) { $this->setRouter('Enlight_Controller_Router_Default'); } if (!$this->dispatcher) { $this->setDispatcher('Enlight_Controller_Dispatcher_Default'); } if (!$this->request) { $this->setRequest('Enlight_Controller_Request_RequestHttp'); } if (!$this->response) { $this->setResponse('Enlight_Controller_Response_ResponseHttp'); } $eventArgs->set('request', $this->Request()); $eventArgs->set('response', $this->Response()); try { /** * Notify plugins of router startup */ $this->eventManager->notify('Enlight_Controller_Front_RouteStartup', $eventArgs); /** * Route request to controller/action, if a router is provided */ try { $this->router->route($this->request); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of router completion */ $this->eventManager->notify('Enlight_Controller_Front_RouteShutdown', $eventArgs); /** * Notify plugins of dispatch loop startup */ $this->eventManager->notify('Enlight_Controller_Front_DispatchLoopStartup', $eventArgs); /** * Attempts to dispatch the controller/action. If the $this->request * indicates that it needs to be dispatched, it moves to the next * action in the request. */ do { $this->request->setDispatched(true); /** * Notify plugins of dispatch startup */ try { $this->eventManager->notify('Enlight_Controller_Front_PreDispatch', $eventArgs); /** * Skip requested action if preDispatch() has reset it */ if (!$this->request->isDispatched()) { continue; } /** * Dispatch request */ try { $this->dispatcher->dispatch($this->request, $this->response); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of dispatch completion */ $this->eventManager->notify('Enlight_Controller_Front_PostDispatch', $eventArgs); } while (!$this->request->isDispatched()); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of dispatch loop completion */ try { $this->eventManager->notify('Enlight_Controller_Front_DispatchLoopShutdown', $eventArgs); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } if ($this->returnResponse()) { return $this->response; } if (!$this->eventManager->notifyUntil('Enlight_Controller_Front_SendResponse', $eventArgs)) { $this->Response()->sendResponse(); } $this->eventManager->notify('Enlight_Controller_Front_AfterSendResponse', $eventArgs); return 0; }
/** * Notify a lifecycleCallback event of doctrine over the enlight event manager * @param $eventName string * @param $eventArgs LifecycleEventArgs * @return \Enlight_Event_EventArgs|null */ protected function notifyEvent($eventName, $eventArgs) { return $this->eventManager->notify($eventName, array('entityManager' => $eventArgs->getEntityManager(), 'entity' => $eventArgs->getEntity())); }
/** * Generates the theme directory in engine/Shopware/Themes * @param $name */ private function createThemeDirectory($name) { $directory = $this->getThemeDirectory($name); $this->fileSystem->mkdir($directory); $this->eventManager->notify('Theme_Generator_Theme_Directory_Created', array('name' => $name, 'directory' => $directory)); }
/** * @param string $event * @param null $eventArgs * @return Enlight_Event_EventArgs|null * @throws Enlight_Event_Exception */ public function notify($event, $eventArgs = null) { $this->getPluginBootstrap()->addEvent($event, 'notify', $this->getListeners($event), $eventArgs); return $this->events->notify($event, $eventArgs); }