/** * @param Enlight_Event_EventArgs $args * @return bool */ public function onMyCustomRule(Enlight_Event_EventArgs $args) { $rule = $args->get('rule'); $user = $args->get('user'); $basket = $args->get('basket'); $value = $args->get('value'); if ($basket['AmountNumeric'] > $value) { return true; // it's a risky customer } return false; }
/** * Called from the Event Manager after the dispatch process * * @param Enlight_Event_EventArgs $args * @return bool */ public function onPostDispatch(Enlight_Event_EventArgs $args) { /** @var $subject Enlight_Controller_Action */ $subject = $args->get('subject'); $response = $subject->Response(); $request = $subject->Request(); if (!$request->isDispatched()) { return; } // If the attribute padding is a boolean true if ($this->padding === true) { $this->padding = $request->getParam('callback'); $this->padding = preg_replace('#[^0-9a-z_]+#i', '', (string) $this->padding); } // decide if we should render the data or the whole page if ($this->renderer === true) { $content = $subject->View()->getAssign(); } elseif (!empty($this->padding)) { $content = $response->getBody(); } else { return; } // Convert content to json $content = $this->convertToJson($content); if (!empty($this->padding)) { $response->setHeader('Content-type', 'text/javascript', true); $response->setBody($this->addPadding($content, $this->padding)); } elseif ($this->renderer === true) { $response->setHeader('Content-type', 'application/json', true); $response->setBody($content); } $this->padding = null; $this->encoding = 'UTF-8'; $this->renderer = null; }
/** * Called from the event manager before the dispatch process. * Parse the json input data, when it was activated. * * @param Enlight_Event_EventArgs $args * @return bool */ public function onPreDispatch(Enlight_Event_EventArgs $args) { /** @var $subject Enlight_Controller_Action */ $subject = $args->get('subject'); $request = $subject->Request(); // Parses the json input data, if the content type is correct if ($this->parseInput === true && ($contentType = $request->getHeader('Content-Type')) !== false && strpos($contentType, 'application/json') === 0 && ($input = file_get_contents('php://input')) !== false) { $input = Zend_Json::decode($input); foreach ((array) $input as $key => $value) { if ($value !== null) { $request->setPost($key, $value); } } } // Parse the json Params if (count($this->parseParams)) { foreach ($this->parseParams as $Param) { if (($value = $request->getParam($Param)) !== null) { $value = Zend_Json::decode($value); $request->setParam($Param, $value); } } } // Rests the configuration for the next dispatch $this->parseInput = false; $this->parseParams = array(); }
public function onSecureCheckoutConfirmPostDispatch(Enlight_Event_EventArgs $arguments) { $controller = $arguments->get('subject'); $view = $controller->View(); $view->addTemplateDir($this->Path() . '/Views'); $view->assign('number', $this->Config()->get('number')); }
/** * Creates adapter instance * * @param Enlight_Event_EventArgs $args * @return AdapterInterface */ public function createS3Adapter(Enlight_Event_EventArgs $args) { $defaultConfig = ['key' => '', 'secret' => '', 'region' => '', 'version' => 'latest', 'bucket' => '', 'prefix' => '']; $config = array_merge($defaultConfig, $args->get('config')); $client = S3Client::factory(['credentials' => ['key' => $config['key'], 'secret' => $config['secret']], 'region' => $config['region'], 'version' => $config['version']]); return new AwsS3Adapter($client, $config['bucket'], $config['prefix']); }
public function onFrontendPostDispatch(Enlight_Event_EventArgs $args) { $controller = $args->get('subject'); $view = $controller->View(); $view->addTemplateDir(__DIR__ . '/Views'); $view->assign('facebookLink', $this->Config()->get('facebook-link')); $view->assign('twitterLink', $this->Config()->get('twitter-link')); $view->assign('emailLink', $this->Config()->get('email-link')); }
public function onFrontendPostDispatch(Enlight_Event_EventArgs $args) { /** @var \Enlight_Controller_Action $controller */ $controller = $args->get('subject'); $view = $controller->View(); $view->addTemplateDir(__DIR__ . '/Views'); $view->assign('sloganSize', $this->Config()->get('font-size')); $view->assign('italic', $this->Config()->get('italic')); $view->assign('slogan', $this->getSlogan()); }
/** * Provide the store data for the current store. * * @param \Enlight_Event_EventArgs $args * @return array|mixed */ public function handleElement(\Enlight_Event_EventArgs $args) { /** @var $controller \Enlight_Controller_Action */ $controller = $args->get('subject'); /** @var CustomComponents $customComponents */ $customComponents = $controller->get('swag_dynamic_emotion.custom_components'); $element = $args->get('element'); $data = $args->getReturn(); $storeId = $controller->Request()->getParam('currentStore'); // just modify our own components if (!$customComponents->isCustomComponents($element['component']['cls'])) { return $data; } // if no $storeId is available (e.g. shopping world preview), get a fallback $storeId = isset($storeId) ? $storeId : Shopware()->Db()->fetchOne('SELECT id FROM swag_store LIMIT 1'); // if still not available (e.g. no stores) - return if (!$storeId) { return $data; } /** @var ModelRepository $storeRepo */ $storeRepo = Shopware()->Models()->getRepository('Shopware\\CustomModels\\SwagDynamicEmotion\\Store'); return array_merge($data, ['store' => $storeRepo->find($storeId)]); }
public function onShopwareStartDispatch(Enlight_Event_EventArgs $args) { /** @var \Enlight_Controller_Front $subject */ $subject = $args->get('subject'); if ($subject->getParam('noErrorHandler')) { $requestUri = $subject->Request()->getRequestUri(); if (file_exists($this->Path() . 'vendor/autoload.php')) { require_once $this->Path() . 'vendor/autoload.php'; } $whoops = new Run(); if ($subject->Request()->isXmlHttpRequest() || strstr($requestUri, '/backend') || strstr($requestUri, '/ajax')) { $whoops->pushHandler(new JsonResponseHandler()); } else { $whoops->pushHandler(new PrettyPageHandler()); } $whoops->register(); restore_error_handler(); } }
/** * @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); }
public function validatePaymentContextData(Enlight_Event_EventArgs $args) { $context = $args->get('context'); $this->assertInternalType('array', $context['sPaymentTable']); $this->assertCount(0, $context['sPaymentTable']); }
/** * @param Enlight_Event_EventArgs $eventArgs */ public function onPostPersist(Enlight_Event_EventArgs $eventArgs) { if(empty($this->Config()->proxyBan)) { return; } if($this->proxyUrl === null || $this->request->getHeader('Surrogate-Capability') === false) { return; } $entity = $eventArgs->get('entity'); if ($entity instanceof \Doctrine\ORM\Proxy\Proxy) { $entityName = get_parent_class($entity); } else { $entityName = get_class($eventArgs->getEntity()); } $categoryIds = array(); $articleIds = array(); switch ($entityName) { case 'Shopware\Models\Article\Article': $articleIds[] = $entity->getId(); foreach ($entity->getCategories() as $category) { $categoryIds[] = $category->getId(); } break; case 'Shopware\Models\Category\Category': $categoryIds[] = $entity->getId(); break; case 'Shopware\Models\Banner\Banner': $categoryIds[] = $entity->getCategoryId(); break; } $client = new Zend_Http_Client(null, array( 'useragent' => 'Shopware/' . Shopware()->Config()->version, 'timeout' => 5, )); try { foreach ($categoryIds as $categoryId) { $client->setUri( $this->proxyUrl . urlencode('c-' . $categoryId) )->request('BAN'); } foreach ($articleIds as $articleId) { $client->setUri( $this->proxyUrl . urlencode('a-' . $articleId) )->request('BAN'); } } catch(Exception $e) { } }
/** * Complements the generated urls with scheme, host and basePath, if required. * * @param Enlight_Event_EventArgs $args * @return string */ public function onFilterUrl(Enlight_Event_EventArgs $args) { /** @var $userParams array */ $userParams = $args->get('userParams'); /** @var $request Enlight_Controller_Request_RequestHttp */ $request = $args->get('subject')->Front()->Request(); /** @var $url string */ $url = $args->getReturn(); if (!empty($url) && ($url[0] === '/' || preg_match('|^[a-z]+://|', $url))) { return $url; } $forceSecure = !empty($this->Config()->forceSecure) || !empty($userParams['forceSecure']); $forceSecure = $forceSecure && !empty($this->Config()->enableSecure); $forceAbsolute = !empty($this->Config()->forceAbsolute) || !empty($userParams['forceAbsolute']); if ($forceAbsolute || $forceSecure) { $prepend = $forceSecure ? 'https://' : 'http://'; if ($forceSecure) { $prepend .= $this->Config()->get('secureHttpHost', $request->getHttpHost()); $prepend .= $this->Config()->get('secureBaseUrl', $request->getBaseUrl()); } else { $prepend .= $this->Config()->get('httpHost', $request->getHttpHost()); $prepend .= $this->Config()->get('baseUrl', $request->getBaseUrl()); } $url = $prepend . '/' . $url; } return $url; }
/** * Creates local media adapter * * @param \Enlight_Event_EventArgs $args * @return ArrayCollection */ public function createLocalAdapter(\Enlight_Event_EventArgs $args) { $config = $args->get('config'); return new ArrayCollection([new Local($config['path'])]); }
/** * updates the session ID, if it changed * * @param \Enlight_Event_EventArgs $args */ public function onUpdateSessionId(\Enlight_Event_EventArgs $args) { $this->sessionId = $args->get('newSessionId'); }
/** * Adds Sepa-Information to Order confirmation mail * * @param Enlight_Event_EventArgs $arguments */ public function beforeSendingMail(Enlight_Event_EventArgs $arguments) { $context = $arguments->get('context'); if ($context['additional']['payment']['name'] != 'paymilldebit' || !isset($context['sOrderNumber'])) { return; } $paymillSepaDate = $this->util->getSepaDate($context['sOrderNumber']); if (!empty($paymillSepaDate)) { $context['paymillSepaDate'] = date("d.m.Y", $paymillSepaDate); $mail = Shopware()->TemplateMail()->createMail('sORDER', $context); $arguments->setReturn($mail); return $mail; } }
/** * Cache invalidation based on model events * * @param Enlight_Event_EventArgs $eventArgs */ public function onPostPersist(Enlight_Event_EventArgs $eventArgs) { if (!$this->Config()->get('proxyPrune')) { return; } $entity = $eventArgs->get('entity'); if ($entity instanceof \Doctrine\ORM\Proxy\Proxy) { $entityName = get_parent_class($entity); } else { $entityName = get_class($entity); } $cacheIds = array(); switch ($entityName) { case 'Shopware\\Models\\Article\\Article': $cacheIds[] = 'a' . $entity->getId(); break; case 'Shopware\\Models\\Article\\Detail': $cacheIds[] = 'a' . $entity->getArticleId(); break; case 'Shopware\\Models\\Category\\Category': $cacheIds[] = 'c' . $entity->getId(); break; case 'Shopware\\Models\\Banner\\Banner': $cacheIds[] = 'c' . $entity->getCategoryId(); break; case 'Shopware\\Models\\Blog\\Blog': $cacheIds[] = 'c' . $entity->getCategoryId(); break; case 'Shopware\\Models\\Emotion\\Emotion': $cacheIds[] = 'e' . $entity->getId(); break; } foreach ($cacheIds as $cacheId) { $this->invalidateCacheId($cacheId); } }
/** * 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]; }
/** * Creates adapter instance * * @param Enlight_Event_EventArgs $args * @return AdapterInterface */ public function createSftpAdapter(Enlight_Event_EventArgs $args) { $defaultConfig = ['host' => '', 'port' => 22, 'username' => '', 'password' => '', 'privateKey' => '', 'root' => '', 'timeout' => 10]; $config = array_merge($defaultConfig, $args->get('config')); return new SftpAdapter(['host' => $config['host'], 'port' => $config['port'], 'username' => $config['username'], 'password' => $config['password'], 'privateKey' => $config['privateKey'], 'root' => $config['root'], 'timeout' => $config['timeout']]); }
/** * @param EventArgs $eventArgs */ public function onProductStockWasChanged(EventArgs $eventArgs) { $backlog = new Backlog(ORMBacklogSubscriber::EVENT_VARIANT_UPDATED, ['number' => $eventArgs->get('number')]); $this->container->get('shopware_elastic_search.backlog_processor')->add([$backlog]); }
/** * Stores the id of the created order into the plenty_order table * * @param Enlight_Event_EventArgs $arguments * @return boolean */ public function onOrderModelPostPersist(Enlight_Event_EventArgs $arguments) { $model = $arguments->get('entity'); $orderId = $model->getId(); Shopware()->Db()->query(' INSERT INTO plenty_order SET shopwareId = ? ', array($orderId)); return true; }
/** * Assembles a url with the symfony url generator based on the parameters. * * @param Enlight_Event_EventArgs $args * @return string|null */ public function onAssemble(Enlight_Event_EventArgs $args) { /** @var $request Request */ $request = $args->get('subject')->Front()->Request(); /** @var $params array */ $params = $args->get('params'); /** @var $routes Symfony\Component\Routing\RouteCollection */ $routes = $this->Application()->SymfonyRoutes(); $context = $this->getRequestContext($request); $matcher = new UrlGenerator($routes, $context); foreach ($routes as $name => $route) { try { if (($url = $matcher->generate($name, $params)) !== null) { return ltrim($url, '/'); } } catch (Exception $e) { } } return null; }
/** * @param EventArgs $arguments */ public function preRemoveCategory(EventArgs $arguments) { $categoryModel = $arguments->get('entity'); $categoryId = $categoryModel->getId(); $builder = $this->em->getDBALQueryBuilder(); $builder->delete('s_articles_sort')->where('categoryId = :categoryId')->setParameter('categoryId', $categoryId); $builder->execute(); }
public function onFrontendPostDispatch(Enlight_Event_EventArgs $args) { $controller = $args->get('subject'); $view = $controller->View(); $view->addTemplateDir(__DIR__ . '/Views'); }
/** * Eventhandler disabling the status mailing for sofort payments * * @param Enlight_Event_EventArgs $arguments * * @return boolean|void */ public function disableStatusMails(Enlight_Event_EventArgs $arguments) { $variables = $arguments->get('variables'); $paymentName = $variables['additional']['payment']['name']; if ($paymentName === 'sofortideal' || $paymentName === 'sofortbanking') { if (Shopware()->Session()->sofortSendMail === false) { Shopware()->Session()->offsetSet('sofortMailVariables', serialize($variables)); return true; } } }
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; }