示例#1
0
 /**
  * {@inheritdoc}
  */
 public function match($pathInfo, Context $context)
 {
     if (strpos($pathInfo, '/backend/') === 0 || strpos($pathInfo, '/api/') === 0) {
         return $pathInfo;
     }
     if ($context->getShopId() === null) {
         //only frontend
         return $pathInfo;
     }
     $request = new EnlightRequest();
     $request->setBaseUrl($context->getBaseUrl());
     $request->setPathInfo($pathInfo);
     $event = $this->eventManager->notifyUntil('Enlight_Controller_Router_Route', ['request' => $request, 'context' => $context]);
     return $event !== null ? $event->getReturn() : false;
 }
示例#2
0
 /**
  * Runs a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Event_EventArgs
  * @throw Enlight_Exception
  */
 public function runJob(Enlight_Components_Cron_Job $job)
 {
     // Fix cron action name
     $action = $job->getAction();
     if (strpos($action, 'Shopware_') !== 0) {
         $action = str_replace(' ', '', ucwords(str_replace('_', ' ', $job->getAction())));
         $job->setAction('Shopware_CronJob_' . $action);
     }
     try {
         if ($this->adapter->startJob($job)) {
             $jobArgs = new $this->eventArgsClass(array('subject' => $this, 'job' => $job));
             $jobArgs->setReturn($job->getData());
             $jobArgs = $this->eventManager->notifyUntil($job->getAction(), $jobArgs);
             if ($jobArgs !== null) {
                 $job->setData($jobArgs->getReturn());
                 $this->adapter->updateJob($job);
             }
             $this->endJob($job);
             return $jobArgs;
         }
     } catch (Exception $e) {
         $job->setData(array('error' => $e->getMessage()));
         $this->disableJob($job);
         throw $e;
     }
 }
示例#3
0
 /**
  * function to execute risk rules
  * @param string $rule
  * @param array $user
  * @param array $basket
  * @param string $value
  * @return bool
  */
 public function executeRiskRule($rule, $user, $basket, $value)
 {
     if ($event = $this->eventManager->notifyUntil('Shopware_Modules_Admin_Execute_Risk_Rule_' . $rule, ['rule' => $rule, 'user' => $user, 'basket' => $basket, 'value' => $value])) {
         return $event->getReturn();
     }
     return $this->{$rule}($user, $basket, $value);
 }
示例#4
0
 /**
  * Runs a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Event_EventArgs
  * @throw Enlight_Exception
  */
 public function run(Enlight_Components_Cron_Job $job)
 {
     try {
         if ($this->startJob($job)) {
             $jobArgs = $this->_eventManager->notifyUntil($job->getAction(), new Enlight_Components_Cron_EventArgs($job));
             $this->endJob($job);
             return $jobArgs;
         }
     } catch (Exception $e) {
         $job->setData(array('error' => $e->getMessage()));
         $this->disableJob($job);
         throw $e;
     }
 }
示例#5
0
 /**
  * Runs a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Event_EventArgs
  * @throw Enlight_Exception
  */
 public function runJob(Enlight_Components_Cron_Job $job)
 {
     try {
         if ($this->adapter->startJob($job)) {
             $jobArgs = new $this->eventArgsClass(array('subject' => $this, 'job' => $job));
             $jobArgs->setReturn($job->getData());
             $jobArgs = $this->eventManager->notifyUntil($job->getAction(), $jobArgs);
             if ($jobArgs !== null) {
                 $job->setData($jobArgs->getReturn());
                 $this->adapter->updateJob($job);
             }
             $this->endJob($job);
             return $jobArgs;
         }
     } catch (Exception $e) {
         $job->setData(array('error' => $e->getMessage()));
         $this->disableJob($job);
         throw $e;
     }
 }
示例#6
0
 /**
  * Get all data from the current logged in user
  *
  * @return array|false User data, of false if interrupted
  */
 public function sGetUserData()
 {
     if ($this->eventManager->notifyUntil('Shopware_Modules_Admin_GetUserData_Start', array('subject' => $this))) {
         return false;
     }
     $register = $this->session->offsetGet('sRegister');
     if (empty($register)) {
         $this->session->offsetSet('sRegister', array());
     }
     $userData = array();
     $countryQuery = 'SELECT c.*, a.name AS countryarea
       FROM s_core_countries c
       LEFT JOIN s_core_countries_areas a
        ON a.id = c.areaID AND a.active = 1
       WHERE c.id = ?';
     // If user is logged in
     $userId = $this->session->offsetGet('sUserId');
     if (!empty($userId)) {
         $userData = $this->getUserBillingData($userId, $userData);
         $userData = $this->getUserCountryData($userData, $userId);
         $newsletter = $this->db->fetchRow("SELECT id FROM s_campaigns_mailaddresses WHERE email = ?", array($userData["additional"]["user"]["email"]));
         $userData["additional"]["user"]["newsletter"] = $newsletter["id"] ? 1 : 0;
         $userData = $this->getUserShippingData($userId, $userData, $countryQuery);
     } else {
         // No user logged in
         $register = $this->session->offsetGet('sRegister');
         if ($this->session->offsetGet('sCountry') && $this->session->offsetGet('sCountry') != $register["billing"]["country"]) {
             $register['billing']['country'] = intval($this->session->offsetGet('sCountry'));
             $this->session->offsetSet('sRegister', $register);
         }
         $userData["additional"]["country"] = $this->db->fetchRow($countryQuery, array(intval($register["billing"]["country"])));
         $userData["additional"]["country"] = $userData["additional"]["country"] ?: array();
         $userData["additional"]["countryShipping"] = $userData["additional"]["country"];
         $state = $this->session->offsetGet('sState');
         $userData["additional"]["stateShipping"]["id"] = !empty($state) ? $state : 0;
     }
     $userData = $this->eventManager->filter('Shopware_Modules_Admin_GetUserData_FilterResult', $userData, array('subject' => $this, 'id' => $this->session->offsetGet('sUserId')));
     return $userData;
 }
示例#7
0
 /**
  * Add product to cart
  * Used in multiple locations
  *
  * @param int $id Order number (s_articles_details.ordernumber)
  * @param int $quantity Amount
  * @throws Enlight_Exception If no price could be determined, or a database error occurs
  * @return int|false Id of the inserted basket entry, or false on failure
  */
 public function sAddArticle($id, $quantity = 1)
 {
     $sessionId = $this->session->get('sessionId');
     if ($this->session->get('Bot') || empty($sessionId)) {
         return false;
     }
     $quantity = empty($quantity) || !is_numeric($quantity) ? 1 : (int) $quantity;
     if ($quantity <= 0) {
         $quantity = 1;
     }
     if ($this->eventManager->notifyUntil('Shopware_Modules_Basket_AddArticle_Start', array('subject' => $this, 'id' => $id, "quantity" => $quantity))) {
         return false;
     }
     $article = $this->getArticleForAddArticle($id);
     if (!$article) {
         return false;
     }
     $chkBasketForArticle = $this->checkIfArticleIsInBasket($article["articleID"], $article["ordernumber"], $sessionId);
     // Shopware 3.5.0 / sth / laststock - instock check
     if (!empty($chkBasketForArticle["id"])) {
         if ($article["laststock"] == true && $article["instock"] < $chkBasketForArticle["quantity"] + $quantity) {
             $quantity -= $chkBasketForArticle["quantity"];
         }
     } else {
         if ($article["laststock"] == true && $article["instock"] <= $quantity) {
             $quantity = $article["instock"];
             if ($quantity <= 0) {
                 return;
             }
         }
     }
     if ($chkBasketForArticle) {
         // Article is already in basket, update quantity
         $quantity += $chkBasketForArticle["quantity"];
         $this->sUpdateArticle($chkBasketForArticle["id"], $quantity);
         return $chkBasketForArticle["id"];
     }
     $price = $this->getPriceForAddArticle($article);
     // For variants, extend the article name
     if ($article["additionaltext"]) {
         $article["articleName"] .= " " . $article["additionaltext"];
     }
     if (!$article["shippingfree"]) {
         $article["shippingfree"] = "0";
     }
     // Check if article is an esd-article
     // - add flag to basket
     $getEsd = $this->db->fetchOne('SELECT s_articles_esd.id AS id, serials
         FROM s_articles_esd, s_articles_details
         WHERE s_articles_esd.articleID = ?
         AND s_articles_esd.articledetailsID = s_articles_details.id
         AND s_articles_details.ordernumber = ?', array($article["articleID"], $article["ordernumber"]));
     $sEsd = $getEsd ? '1' : '0';
     $quantity = (int) $quantity;
     $sql = "\n            INSERT INTO s_order_basket (id, sessionID, userID, articlename, articleID,\n                ordernumber, shippingfree, quantity, price, netprice,\n                datum, esdarticle, partnerID, config)\n            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )\n        ";
     $params = array('', (string) $sessionId, (string) $this->session->get('sUserId'), $article["articleName"], $article["articleID"], (string) $article["ordernumber"], $article["shippingfree"], $quantity, $price["price"], $price["netprice"], date("Y-m-d H:i:s"), $sEsd, (string) $this->session->get('sPartner'), '');
     $sql = $this->eventManager->filter('Shopware_Modules_Basket_AddArticle_FilterSql', $sql, array('subject' => $this, 'article' => $article, 'price' => $price, 'esd' => $sEsd, 'quantity' => $quantity, 'partner' => $this->session->get('sPartner')));
     $result = $this->db->query($sql, $params);
     if (!$result) {
         throw new Enlight_Exception("BASKET-INSERT #02 SQL-Error" . $sql);
     }
     $insertId = $this->db->lastInsertId();
     $this->db->insert('s_order_basket_attributes', array('basketID' => $insertId, 'attribute1' => ''));
     $this->sUpdateArticle($insertId, $quantity);
     return $insertId;
 }
示例#8
0
 /**
  * send order confirmation mail
  * @access public
  */
 public function sendMail($variables)
 {
     $variables = $this->eventManager->filter('Shopware_Modules_Order_SendMail_FilterVariables', $variables, array('subject' => $this));
     $shopContext = $this->contextService->getShopContext();
     $context = array('sOrderDetails' => $variables["sOrderDetails"], 'billingaddress' => $variables["billingaddress"], 'shippingaddress' => $variables["shippingaddress"], 'additional' => $variables["additional"], 'sTaxRates' => $variables["sTaxRates"], 'sShippingCosts' => $variables["sShippingCosts"], 'sAmount' => $variables["sAmount"], 'sAmountNet' => $variables["sAmountNet"], 'sOrderNumber' => $variables["ordernumber"], 'sOrderDay' => $variables["sOrderDay"], 'sOrderTime' => $variables["sOrderTime"], 'sComment' => $variables["sComment"], 'attributes' => $variables["attributes"], 'sCurrency' => $this->sSYSTEM->sCurrency["currency"], 'sLanguage' => $shopContext->getShop()->getId(), 'sSubShop' => $shopContext->getShop()->getId(), 'sEsd' => $variables["sEsd"], 'sNet' => $this->sNet);
     // Support for individual payment means with custom-tables
     if ($variables["additional"]["payment"]["table"]) {
         $paymentTable = $this->db->fetchRow("\n                  SELECT * FROM {$variables["additional"]["payment"]["table"]}\n                  WHERE userID=?", array($variables["additional"]["user"]["id"]));
         $context["sPaymentTable"] = $paymentTable ?: array();
     } else {
         $context["sPaymentTable"] = array();
     }
     if ($variables["sDispatch"]) {
         $context['sDispatch'] = $variables["sDispatch"];
     }
     if ($variables['sBookingID']) {
         $context['sBookingID'] = $variables["sBookingID"];
     }
     $mail = null;
     if ($event = $this->eventManager->notifyUntil('Shopware_Modules_Order_SendMail_Create', array('subject' => $this, 'context' => $context, 'variables' => $variables))) {
         $mail = $event->getReturn();
     }
     if (!$mail instanceof \Zend_Mail) {
         $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);
     }
     $mail->addTo($this->sUserData["additional"]["user"]["email"]);
     if (!$this->config->get("sNO_ORDER_MAIL")) {
         $mail->addBcc($this->config->get('sMAIL'));
     }
     $mail = $this->eventManager->filter('Shopware_Modules_Order_SendMail_Filter', $mail, array('subject' => $this, 'context' => $context, 'variables' => $variables));
     if (!$mail instanceof \Zend_Mail) {
         return;
     }
     $this->eventManager->notify('Shopware_Modules_Order_SendMail_BeforeSend', array('subject' => $this, 'mail' => $mail, 'context' => $context, 'variables' => $variables));
     $shouldSendMail = !(bool) $this->eventManager->notifyUntil('Shopware_Modules_Order_SendMail_Send', array('subject' => $this, 'mail' => $mail, 'context' => $context, 'variables' => $variables));
     if ($shouldSendMail && $this->config->get('sendOrderMail')) {
         $mail->send();
     }
 }
示例#9
0
 /**
  * Get basic article data in various modes (firmly definied by id, random, top,new)
  * @param string $mode Modus (fix, random, top, new)
  * @param int $category filter by category
  * @param int $value article id / ordernumber for firmly definied articles
  * @param bool $withImage
  * @return array
  */
 public function sGetPromotionById($mode, $category = 0, $value = 0, $withImage = false)
 {
     $notifyUntil = $this->eventManager->notifyUntil('Shopware_Modules_Articles_GetPromotionById_Start', array('subject' => $this, 'mode' => $mode, 'category' => $category, 'value' => $value));
     if ($notifyUntil) {
         return false;
     }
     $value = $this->getPromotionNumberByMode($mode, $category, $value, $withImage);
     if (!$value) {
         return false;
     }
     $result = $this->getPromotion($category, $value);
     if (!$result) {
         return false;
     }
     $result = $this->legacyEventManager->firePromotionByIdEvents($result, $category, $this);
     return $result;
 }
示例#10
0
 /**
  * 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;
 }
示例#11
0
 /**
  * @param string $event
  * @param null $eventArgs
  * @return Enlight_Event_EventArgs|null
  * @throws Enlight_Exception
  */
 public function notifyUntil($event, $eventArgs = null)
 {
     $this->getPluginBootstrap()->addEvent($event, 'notifyUntil', $this->getListeners($event), $eventArgs);
     return $this->events->notifyUntil($event, $eventArgs);
 }