/**
  * @inheritdoc
  */
 public function savePaymentData($userId, \Enlight_Controller_Request_Request $request)
 {
     $lastPayment = $this->getCurrentPaymentDataAsArray($userId);
     $paymentMean = Shopware()->Models()->getRepository('\\Shopware\\Models\\Payment\\Payment')->getPaymentsQuery(array('name' => 'debit'))->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);
     $data = array('account_number' => $request->getParam("sDebitAccount"), 'bank_code' => $request->getParam("sDebitBankcode"), 'bankname' => $request->getParam("sDebitBankName"), 'account_holder' => $request->getParam("sDebitBankHolder"));
     if (!$lastPayment) {
         $date = new \DateTime();
         $data['created_at'] = $date->format('Y-m-d');
         $data['payment_mean_id'] = $paymentMean['id'];
         $data['user_id'] = $userId;
         Shopware()->Db()->insert("s_core_payment_data", $data);
     } else {
         $where = array('payment_mean_id = ?' => $paymentMean['id'], 'user_id = ?' => $userId);
         Shopware()->Db()->update("s_core_payment_data", $data, $where);
     }
     /**
      * This section is legacy code form the old core debit.php class
      * It's still used to avoid BC break, but should be considered deprecated
      * and it will be removed in future releases
      *
      * It updates the s_user_debit (deprecated) table with the submited data
      */
     $data = array($request->getParam("sDebitAccount"), $request->getParam("sDebitBankcode"), $request->getParam("sDebitBankName"), $request->getParam("sDebitBankHolder"), $userId);
     if ($this->getData($userId)) {
         $sql = "UPDATE s_user_debit SET account=?, bankcode=?, bankname=?, bankholder=?\n                WHERE userID = ?";
     } else {
         $sql = "INSERT INTO s_user_debit (account, bankcode, bankname, bankholder, userID)\n                VALUES (?,?,?,?,?)";
     }
     Shopware()->Db()->query($sql, $data);
 }
Ejemplo n.º 2
0
 /**
  * Detects if the current request represents a request for the backend's homepage
  *
  * @return bool
  */
 private function isBackendHomepage()
 {
     if ($this->request->getParam('controller', 'index') != 'index') {
         return false;
     }
     if ($this->request->getParam('action', 'index') != 'index') {
         return false;
     }
     if ($this->request->getParam('module', 'backend') != 'backend') {
         return false;
     }
     $basePath = $this->request->getBasePath();
     $uri = $this->request->getRequestUri();
     return str_replace($basePath, '', $uri) === '/backend/';
 }
Ejemplo n.º 3
0
 /**
  * Secure cron actions according to system settings
  *
  * @param Enlight_Controller_Request_Request $request
  * @return bool If cron action is authorized
  */
 public function authorizeCronAction($request)
 {
     // If called using CLI, always execute the cron tasks
     if (php_sapi_name() == 'cli') {
         return true;
     }
     // At least one of the security policies is enabled.
     // If at least one of them validates, cron tasks will be executed
     $cronSecureAllowedKey = Shopware()->Config()->get('cronSecureAllowedKey');
     $cronSecureAllowedIp = Shopware()->Config()->get('cronSecureAllowedIp');
     $cronSecureByAccount = Shopware()->Config()->get('cronSecureByAccount');
     // No security policy specified, accept all requests
     if (empty($cronSecureAllowedKey) && empty($cronSecureAllowedIp) && !$cronSecureByAccount) {
         return true;
     }
     // Validate key
     if (!empty($cronSecureAllowedKey)) {
         $urlKey = $request->getParam('key');
         if (strcmp($cronSecureAllowedKey, $urlKey) == 0) {
             return true;
         }
     }
     // Validate ip
     if (!empty($cronSecureAllowedIp)) {
         $requestIp = $request->getServer('REMOTE_ADDR');
         if (in_array($requestIp, explode(';', $cronSecureAllowedIp))) {
             return true;
         }
     }
     // Validate user auth
     if ($cronSecureByAccount) {
         if (Shopware()->Auth()->hasIdentity() === true) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Refresh partner log
  *
  * @param   \Enlight_Controller_Request_Request $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;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $basket
  * @param Request $request
  * @return array
  * @throws Exception
  */
 private function getInvalidAgreements($basket, Request $request)
 {
     $errors = [];
     if (!$this->container->get('config')->get('IgnoreAGB') && !$this->Request()->getParam('sAGB')) {
         $errors['agbError'] = true;
     }
     $esdAgreement = $request->getParam('esdAgreementChecked');
     if ($this->container->get('config')->get('showEsdWarning') && $this->basketHasEsdArticles($basket) && empty($esdAgreement)) {
         $errors['esdError'] = true;
     }
     $serviceChecked = $request->getParam('serviceAgreementChecked');
     if ($this->basketHasServiceArticles($basket) && empty($serviceChecked)) {
         $errors['serviceError'] = true;
     }
     return $errors;
 }
Ejemplo n.º 6
0
 /**
  * Returns a listing of products. Used for the backward compatibility category listings.
  * This function calls the new shopware core and converts the result to the old listing structure.
  *
  * @param $categoryId
  * @param StoreFrontBundle\Struct\ProductContextInterface $context
  * @param Enlight_Controller_Request_Request $request
  * @param SearchBundle\Criteria $criteria
  * @return array
  */
 private function getListing($categoryId, StoreFrontBundle\Struct\ProductContextInterface $context, Enlight_Controller_Request_Request $request, SearchBundle\Criteria $criteria)
 {
     $searchResult = $this->searchService->search($criteria, $context);
     $articles = array();
     /**@var $product StoreFrontBundle\Struct\ListProduct */
     foreach ($searchResult->getProducts() as $product) {
         $article = $this->legacyStructConverter->convertListProductStruct($product);
         if (!empty($categoryId) && $categoryId != $context->getShop()->getCategory()->getId()) {
             $article["linkDetails"] .= "&sCategory={$categoryId}";
         }
         if (isset($article['sVoteAverange']) && !empty($article['sVoteAverange'])) {
             // the listing pages use a 0 - 5 based average
             $article['sVoteAverange']['averange'] = $article['sVoteAverange']['averange'] / 2;
         }
         if ($this->config->get('useShortDescriptionInListing') && strlen($article['description']) > 5) {
             $article["description_long"] = $article['description'];
         }
         $article['description_long'] = $this->sOptimizeText($article['description_long']);
         $articles[$article['ordernumber']] = $article;
     }
     $pageSizes = explode("|", $this->config->get('numberArticlesToShow'));
     return array('sArticles' => $articles, 'criteria' => $criteria, 'facets' => $searchResult->getFacets(), 'sPage' => $request->getParam('sPage', 1), 'pageSizes' => $pageSizes, 'sPerPage' => $criteria->getLimit(), 'sNumberArticles' => $searchResult->getTotalCount(), 'shortParameters' => $this->queryAliasMapper->getQueryAliases(), 'sTemplate' => $request->getParam('sTemplate'), 'sSort' => $request->getParam('sSort', $this->config->get('defaultListingSorting')));
 }
 /**
  * @param \Enlight_Controller_Request_Request $request
  * @return array
  */
 private function getCategoryConfig(\Enlight_Controller_Request_Request $request)
 {
     return array('sSort' => $request->getParam('sSort', 0), 'sPage' => $request->getParam('sPage', 1), 'sTemplate' => $request->getParam('sTemplate', null), 'sPerPage' => $request->getParam('sPerPage', (int) $this->get('config')->get('articlesPerPage')), 'sSupplier' => $request->getParam('sSupplier', null), 'priceMin' => $request->getParam('priceMin', null), 'priceMax' => $request->getParam('priceMax', null), 'shippingFree' => $request->getParam('shippingFree', false), 'sFilterProperties' => $request->getParam('sFilterProperties', array()), 'immediateDelivery' => $request->getParam('immediateDelivery', false));
 }
Ejemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function savePaymentData($userId, \Enlight_Controller_Request_Request $request)
 {
     $lastPayment = $this->getCurrentPaymentDataAsArray($userId);
     $paymentMean = Shopware()->Models()->getRepository('\\Shopware\\Models\\Payment\\Payment')->getPaymentsQuery(array('name' => 'Sepa'))->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);
     $data = array('use_billing_data' => $request->getParam("sSepaUseBillingData") === 'true' ? 1 : 0, 'bankname' => $request->getParam("sSepaBankName"), 'iban' => preg_replace('/\\s+|\\./', '', $request->getParam("sSepaIban")), 'bic' => $request->getParam("sSepaBic"));
     if (!$lastPayment) {
         $date = new \DateTime();
         $data['created_at'] = $date->format('Y-m-d');
         $data['payment_mean_id'] = $paymentMean['id'];
         $data['user_id'] = $userId;
         Shopware()->Db()->insert("s_core_payment_data", $data);
     } else {
         $where = array('payment_mean_id = ?' => $paymentMean['id'], 'user_id = ?' => $userId);
         Shopware()->Db()->update("s_core_payment_data", $data, $where);
     }
 }
Ejemplo n.º 9
0
 public function assembleRoute(Request $request, Response $response)
 {
     $path = $request->getPathInfo();
     $path = explode('/', trim($path, '/'));
     $path = array_pad($path, 7, null);
     array_shift($path);
     $tmp = array_shift($path);
     $matches = array();
     if (preg_match('/^v([1-9])$/', $tmp, $matches) === 1) {
         $version = (int) $matches[1];
         $type = array_shift($path);
     } else {
         $version = 1;
         $type = $tmp;
     }
     $id = !empty($path[0]) ? $path[0] : false;
     $subType = !empty($path[1]) ? $path[1] : false;
     $subId = !empty($path[2]) ? $path[2] : false;
     $request->setControllerName($type);
     $request->setParam('id', $id);
     $request->setParam('subId', $subId);
     $request->setParam('version', $version);
     $method = strtoupper($request->getParam('_method', $request->getMethod()));
     $action = 'invalid';
     if ($method === 'GET' && $id === false) {
         $action = 'index';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'GET') {
         $action = 'get';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'PUT' && $id === false) {
         $action = 'batch';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'PUT') {
         $action = 'put';
     } elseif ($method === 'POST') {
         $action = 'post';
         // Set default http status code for successfull request
         $response->setHttpResponseCode(201);
     } elseif ($method === 'DELETE' && $id === false) {
         $action = 'batchDelete';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'DELETE') {
         $response->setHttpResponseCode(200);
         $action = 'delete';
     }
     if ($action == 'invalid') {
         $request->setControllerName('index');
         $request->setActionName($action);
         return;
     }
     if (!$subType) {
         $request->setActionName($action);
         return;
     }
     if ($action == 'get' && $subId === false) {
         $subAction = $subType . 'Index';
     } else {
         $subAction = $subType;
     }
     $action = $action . ucfirst($subAction);
     $request->setActionName($action);
 }