Example #1
0
    /**
     * Refresh partner log
     *
     * @param   \Enlight_Controller_Request_RequestHttp $request
     * @param   \Enlight_Controller_Response_ResponseHttp $response
     */
    public function refreshPartner($request, $response)
    {
        $partner = $request->getParam('partner', $request->getParam('sPartner'));
        if ($partner !== null) {
            if (strpos($partner, 'sCampaign') === 0) {
                $campaignID = (int) str_replace('sCampaign', '', $partner);
                if (!empty($campaignID)) {
                    Shopware()->Session()->sPartner = 'sCampaign' . $campaignID;
                    $sql = '
						UPDATE s_campaigns_mailings
						SET clicked = clicked + 1
						WHERE id = ?
					';
                    Shopware()->Db()->query($sql, array($campaignID));
                }
            } else {
                $sql = 'SELECT * FROM s_emarketing_partner WHERE active=1 AND idcode=?';
                $row = Shopware()->Db()->fetchRow($sql, array($partner));
                if (!empty($row)) {
                    if ($row['cookielifetime']) {
                        $valid = time() + $row['cookielifetime'];
                    } else {
                        $valid = 0;
                    }
                    $response->setCookie('partner', $row['idcode'], $valid, '/');
                }
                Shopware()->Session()->sPartner = $partner;
            }
        } elseif ($request->getCookie('partner') !== null) {
            $sql = 'SELECT idcode FROM s_emarketing_partner WHERE active=1 AND idcode=?';
            $partner = Shopware()->Db()->fetchOne($sql, array($request->getCookie('partner')));
            if (empty($partner)) {
                unset(Shopware()->Session()->sPartner);
            } else {
                Shopware()->Session()->sPartner = $partner;
            }
        }
    }
 /**
  * Returns an array with all current values in _COOKIE
  *
  * @return array
  */
 public function toArray()
 {
     return $this->request->getCookie();
 }
Example #3
0
 /**
  * Returns array of nocache-tags in the request cookie
  *
  * <code>
  * array (
  *     0 => 'detail-1',
  *     1 => 'checkout-1',
  * )
  * </code>
  *
  * @param Enlight_Controller_Request_RequestHttp $request
  * @return array
  */
 protected function getNoCacheTagsFromCookie(\Enlight_Controller_Request_RequestHttp $request)
 {
     $noCacheCookie = $request->getCookie('nocache', false);
     if (false === $noCacheCookie) {
         return array();
     }
     $noCacheTags = explode(',', $noCacheCookie);
     $noCacheTags = array_map('trim', $noCacheTags);
     return $noCacheTags;
 }
Example #4
0
 /**
  * @param Enlight_Controller_Request_RequestHttp $request
  * @param Enlight_Controller_Response_ResponseHttp $response
  */
 protected function upgradeShop($request, $response)
 {
     $bootstrap = $this->Application()->Bootstrap();
     $shop = $this->Application()->Shop();
     $cookieKey = null;
     $cookieValue = null;
     switch (true) {
         case $request->getPost('sLanguage') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getPost('sLanguage');
             break;
         case $request->getPost('sCurrency') !== null:
             $cookieKey = 'currency';
             $cookieValue = $request->getPost('sCurrency');
             break;
         case $request->getPost('__shop') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getPost('__shop');
             break;
         case $request->getQuery('__shop') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getQuery('__shop');
             break;
         case $request->getPost('__currency') !== null:
             $cookieKey = 'currency';
             $cookieValue = $request->getPost('__currency');
             break;
         case $request->getQuery('__template') !== null:
             $cookieKey = 'template';
             $cookieValue = $request->getQuery('__template');
             break;
     }
     // Redirect on shop change
     if ($cookieKey === 'shop') {
         /** @var $repository Shopware\Models\Shop\Repository */
         $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Shop\\Shop');
         $newShop = $repository->getActiveById($cookieValue);
         if ($newShop !== null) {
             if ($newShop->getHost() !== null && $newShop->getHost() !== $shop->getHost() || $newShop->getBaseUrl() !== null && $newShop->getBaseUrl() !== $shop->getBaseUrl()) {
                 $url = sprintf('%s://%s%s%s', $request::SCHEME_HTTP, $newShop->getHost(), $newShop->getBaseUrl(), '/');
                 $path = rtrim($newShop->getBasePath(), '/') . '/';
                 $response->setCookie($cookieKey, $cookieValue, 0, $path);
                 $response->setRedirect($url);
                 return;
             }
         }
     }
     // Refresh on shop change
     if ($cookieKey !== null && $cookieKey != 'template') {
         $path = rtrim($shop->getBasePath(), '/') . '/';
         $response->setCookie($cookieKey, $cookieValue, 0, $path);
         if ($request->isPost() && $request->getQuery('__shop') === null) {
             $url = sprintf('%s://%s%s', $request->getScheme(), $request->getHttpHost(), $request->getRequestUri());
             $response->setRedirect($url);
             return;
         }
     }
     // Upgrade currency
     if ($request->getCookie('currency') !== null) {
         $currencyValue = $request->getCookie('currency');
         foreach ($shop->getCurrencies() as $currency) {
             if ($currencyValue == $currency->getId() || $currencyValue == $currency->getCurrency()) {
                 $shop->setCurrency($currency);
                 break;
             }
         }
     }
     // Start session in frontend controllers
     $session = Shopware()->Session();
     if ($cookieKey !== null) {
         $session->{$cookieKey} = $cookieValue;
     }
     // Refresh basket on currency change
     if (isset($session->sBasketCurrency) && $shop->getCurrency()->getId() != $session->sBasketCurrency) {
         Shopware()->Modules()->Basket()->sRefreshBasket();
     }
     // Upgrade template
     if (isset($session->template) && !empty($session->Admin)) {
         $repository = 'Shopware\\Models\\Shop\\Template';
         $repository = Shopware()->Models()->getRepository($repository);
         $template = $session->template;
         $template = $repository->findOneBy(array('template' => $template));
         if ($template !== null) {
             $shop->setTemplate($template);
         } else {
             unset($session->template);
         }
     } else {
         unset($session->template);
     }
     // Save upgrades
     $shop->registerResources($bootstrap);
     if ($request->isSecure()) {
         $template = $bootstrap->getResource('Template');
         $template->setCompileId($template->getCompileId() . '_secure');
     }
 }
Example #5
0
 /**
  * @param $noCacheTag
  * @param bool $remove
  * @return void
  */
 public function setNoCacheTag($noCacheTag, $remove = false)
 {
     static $noCacheTags, $shopId;
     if(!isset($noCacheTags)) {
         if($this->request->getCookie('nocache')) {
             $noCacheTags = $this->request->getCookie('nocache');
             $noCacheTags = explode(', ', $noCacheTags);
         } else {
             $noCacheTags = array();
         }
         $shopId = Shopware()->Shop()->getId();
     }
     if(!empty($noCacheTag)) {
         $noCacheTag .= '-' . $shopId;
     }
     if(empty($noCacheTag)) {
         $newCacheTags = array();
     } elseif($remove && in_array($noCacheTag, $noCacheTags)) {
         $newCacheTags = array_diff($noCacheTags, array($noCacheTag));
     } elseif(!$remove && !in_array($noCacheTag, $noCacheTags)) {
         $newCacheTags = $noCacheTags;
         $newCacheTags[] = $noCacheTag;
     }
     if (isset($newCacheTags)) {
         $this->response->setCookie(
             'nocache',
             implode(', ', $newCacheTags),
             0,
             $this->request->getBasePath() . '/',
             $this->request->getHttpHost()
         );
     }
 }