Example #1
0
 /**
  * Convenience function to check if there is at least one order with the
  * provided cleared status.
  *
  * @param int $cleared
  * @return boolean
  */
 private function riskCheckClearedLevel($cleared)
 {
     if (!$this->session->offsetGet('sUserId')) {
         return false;
     }
     $checkOrder = $this->db->fetchRow("\n            SELECT id FROM s_order\n            WHERE cleared = ? AND userID = ?", array($cleared, $this->session->offsetGet('sUserId')));
     return $checkOrder && $checkOrder["id"];
 }
Example #2
0
 /**
  * Helper method for sAdmin::sGetPremiumShippingcosts()
  * Calculates payment mean surcharge
  *
  * @param $country
  * @param $payment
  * @param $currencyFactor
  * @param $dispatch
  * @param $discount_tax
  */
 private function handlePaymentMeanSurcharge($country, $payment, $currencyFactor, $dispatch, $discount_tax)
 {
     $surcharge_name = $this->config->get('sPAYMENTSURCHARGEABSOLUTE', 'Zuschlag für Zahlungsart');
     $surcharge_ordernumber = $this->config->get('sPAYMENTSURCHARGEABSOLUTENUMBER', 'PAYMENTSURCHARGEABSOLUTENUMBER');
     $percent_ordernumber = $this->config->get('sPAYMENTSURCHARGENUMBER', "PAYMENTSURCHARGE");
     // Country surcharge
     if (!empty($payment['country_surcharge'][$country['countryiso']])) {
         $payment['surcharge'] += $payment['country_surcharge'][$country['countryiso']];
     }
     $payment['surcharge'] = round($payment['surcharge'] * $currencyFactor, 2);
     // Fixed surcharge
     if (!empty($payment['surcharge']) && (empty($dispatch) || $dispatch['surcharge_calculation'] == 3)) {
         $surcharge = round($payment['surcharge'], 2);
         $payment['surcharge'] = 0;
         if (empty($this->sSYSTEM->sUSERGROUPDATA["tax"]) && !empty($this->sSYSTEM->sUSERGROUPDATA["id"])) {
             $surcharge_net = $surcharge;
             //$tax_rate = 0;
         } else {
             $surcharge_net = round($surcharge / (100 + $discount_tax) * 100, 2);
         }
         $tax_rate = $discount_tax;
         $this->db->insert('s_order_basket', array('sessionID' => $this->session->offsetGet('sessionId'), 'articlename' => $surcharge_name, 'articleID' => 0, 'ordernumber' => $surcharge_ordernumber, 'quantity' => 1, 'price' => $surcharge, 'netprice' => $surcharge_net, 'tax_rate' => $tax_rate, 'datum' => new Zend_Date(), 'modus' => 4, 'currencyFactor' => $currencyFactor));
     }
     // Percentage surcharge
     if (!empty($payment['debit_percent']) && (empty($dispatch) || $dispatch['surcharge_calculation'] != 2)) {
         $amount = $this->db->fetchOne('SELECT SUM(quantity*price) as amount
             FROM s_order_basket
             WHERE sessionID = ? GROUP BY sessionID', array($this->session->offsetGet('sessionId')));
         $percent = round($amount / 100 * $payment['debit_percent'], 2);
         if ($percent > 0) {
             $percent_name = $this->config->get('sPAYMENTSURCHARGEADD');
         } else {
             $percent_name = $this->config->get('sPAYMENTSURCHARGEDEV');
         }
         if (empty($this->sSYSTEM->sUSERGROUPDATA["tax"]) && !empty($this->sSYSTEM->sUSERGROUPDATA["id"])) {
             $percent_net = $percent;
         } else {
             $percent_net = round($percent / (100 + $discount_tax) * 100, 2);
         }
         $tax_rate = $discount_tax;
         $this->db->insert('s_order_basket', array('sessionID' => $this->session->offsetGet('sessionId'), 'articlename' => $percent_name, 'articleID' => 0, 'ordernumber' => $percent_ordernumber, 'quantity' => 1, 'price' => $percent, 'netprice' => $percent_net, 'tax_rate' => $tax_rate, 'datum' => new Zend_Date(), 'modus' => 4, 'currencyFactor' => $currencyFactor));
     }
     return $payment;
 }
 /**
  * Get all articles and a table of their properties as an array
  * @return array Associative array with all articles or empty array
  */
 public function sGetComparisonList()
 {
     if (!$this->session->offsetGet('sessionId')) {
         return [];
     }
     $articles = [];
     // Get all comparisons for this user
     $checkForArticle = $this->db->fetchAll("SELECT * FROM s_order_comparisons WHERE sessionID=?", [$this->session->offsetGet('sessionId')]);
     if (!count($checkForArticle)) {
         return [];
     }
     foreach ($checkForArticle as $article) {
         if ($article["articleID"]) {
             $articles[] = $this->articleModule->sGetPromotionById("fix", 0, (int) $article["articleID"]);
         }
     }
     $properties = $this->sGetComparisonProperties($articles);
     $articles = $this->sFillUpComparisonArticles($properties, $articles);
     return ["articles" => $articles, "properties" => $properties];
 }
Example #4
0
 /**
  * Gets article base price info for sUpdateArticle
  *
  * @param $id
  * @param $quantity
  * @param $queryAdditionalInfo
  * @return array
  */
 private function getPriceForUpdateArticle($id, $quantity, $queryAdditionalInfo)
 {
     // Price groups
     if ($queryAdditionalInfo["pricegroupActive"]) {
         $quantitySQL = 'AND s_articles_prices.from = 1 LIMIT 1';
     } else {
         $quantitySQL = $this->db->quoteInto(' AND s_articles_prices.from <= ? AND (s_articles_prices.to >= ? OR s_articles_prices.to = 0)', $quantity);
     }
     // Get the order number
     $sql = 'SELECT s_articles_prices.price AS price, taxID, s_core_tax.tax AS tax,
           tax_rate, s_articles_details.id AS articleDetailsID, s_articles_details.articleID,
           s_order_basket.config, s_order_basket.ordernumber
         FROM s_articles_details, s_articles_prices, s_order_basket,
           s_articles, s_core_tax
         WHERE s_order_basket.id = ? AND s_order_basket.sessionID = ?
         AND s_order_basket.ordernumber = s_articles_details.ordernumber
         AND s_articles_details.id=s_articles_prices.articledetailsID
         AND s_articles_details.articleID = s_articles.id
         AND s_articles.taxID = s_core_tax.id
         AND s_articles_prices.pricegroup = ?';
     $queryNewPrice = $this->db->fetchRow($sql . ' ' . $quantitySQL, array($id, $this->session->get('sessionId'), $this->sSYSTEM->sUSERGROUP)) ?: array();
     // Load prices from default group if article prices are not defined
     if (!$queryNewPrice["price"]) {
         // In the case no price is available for this customer group, use price of default customer group
         $sql = 'SELECT s_articles_prices.price AS price, taxID, s_core_tax.tax AS tax,
           s_articles_details.id AS articleDetailsID, s_articles_details.articleID,
           s_order_basket.config, s_order_basket.ordernumber
         FROM s_articles_details, s_articles_prices, s_order_basket,
           s_articles, s_core_tax
         WHERE s_order_basket.id = ? AND s_order_basket.sessionID = ?
         AND s_order_basket.ordernumber = s_articles_details.ordernumber
         AND s_articles_details.id=s_articles_prices.articledetailsID
         AND s_articles_details.articleID = s_articles.id
         AND s_articles.taxID = s_core_tax.id
         AND s_articles_prices.pricegroup = \'EK\'';
         $queryNewPrice = $this->db->fetchRow($sql . ' ' . $quantitySQL, array($id, $this->session->get('sessionId'))) ?: array();
     }
     $queryNewPrice = $this->eventManager->filter('Shopware_Modules_Basket_getPriceForUpdateArticle_FilterPrice', $queryNewPrice, array("id" => $id, 'subject' => $this, "quantity" => $quantity));
     return $queryNewPrice;
 }
 /**
  * @param \Enlight_Controller_ActionEventArgs $args
  * @return bool
  */
 public function onPreRedirectToPayPal($args)
 {
     $controller = $args->getSubject();
     $view = $controller->View();
     $userData = $view->getAssign('sUserData');
     $paymentId = $this->session->offsetGet('PaypalPlusPayment');
     $payment = $userData['additional']['payment'];
     $this->session->sOrderVariables['sPayment'] = $payment;
     $this->session->sOrderVariables['sUserData']['additional']['payment'] = $payment;
     $requestData = array(array('op' => 'add', 'path' => '/transactions/0/item_list/shipping_address', 'value' => $this->getShippingAddress($userData)));
     $uri = 'payments/payment/' . $paymentId;
     $view->loadTemplate('');
     try {
         $this->restClient->patch($uri, $requestData);
     } catch (Exception $e) {
         $this->logException('An error occurred on patching the address to the payment', $e);
         echo json_encode(array('success' => false));
         return true;
     }
     echo json_encode(array('success' => true));
     return true;
 }
 /**
  * @param \Enlight_Controller_ActionEventArgs $args
  */
 public function onPostDispatchCheckout($args)
 {
     $cameFromStep2 = $this->session->offsetGet('PayPalPlusCameFromStep2');
     if (!$cameFromStep2) {
         unset($this->session->PaypalPlusPayment);
     }
     $action = $args->getSubject();
     $request = $action->Request();
     $response = $action->Response();
     $view = $action->View();
     // Secure dispatch
     if (!$request->isDispatched() || $response->isException() || $response->isRedirect()) {
         return;
     }
     /** @var $shopContext \Shopware\Models\Shop\Shop */
     $shopContext = $this->bootstrap->get('shop');
     $templateVersion = $shopContext->getTemplate()->getVersion();
     if ($request->getActionName() == 'finish') {
         $this->addInvoiceInstructionsToView($view, $templateVersion);
     }
     //Fix payment description
     $newDescription = $this->bootstrap->Config()->get('paypalPlusDescription', '');
     $newAdditionalDescription = $this->bootstrap->Config()->get('paypalPlusAdditionalDescription', '');
     $payments = $view->getAssign('sPayments');
     if (!empty($payments)) {
         foreach ($payments as $key => $payment) {
             if ($payment['name'] == 'paypal') {
                 $payments[$key]['description'] = $newDescription;
                 $payments[$key]['additionaldescription'] = $payment['additionaldescription'] . $newAdditionalDescription;
                 break;
             }
         }
         $view->assign('sPayments', $payments);
     }
     $user = $view->getAssign('sUserData');
     if (!empty($user['additional']['payment']['name']) && $user['additional']['payment']['name'] == 'paypal') {
         $user['additional']['payment']['description'] = $newDescription;
         $user['additional']['payment']['additionaldescription'] = $newAdditionalDescription;
         $view->assign('sUserData', $user);
     }
     if (method_exists($this->paypalBootstrap, 'getPayment')) {
         $payPalPaymentId = $this->paypalBootstrap->getPayment()->getId();
     } else {
         //fallback for SwagPaymentPaypal verion < 3.3.4
         $payPalPaymentId = $this->paypalBootstrap->Payment()->getId();
     }
     $view->assign('PayPalPaymentId', $payPalPaymentId);
     $allowedActions = array('confirm', 'shippingPayment', 'saveShippingPayment');
     // Check action
     if (!in_array($request->getActionName(), $allowedActions, true)) {
         return;
     }
     if ($request->get('ppplusRedirect')) {
         $action->redirect(array('controller' => 'checkout', 'action' => 'payment', 'sAGB' => 1));
         return;
     }
     // Paypal plus conditions
     $user = $view->getAssign('sUserData');
     $countries = $this->bootstrap->Config()->get('paypalPlusCountries');
     if ($countries instanceof \Enlight_Config) {
         $countries = $countries->toArray();
     } else {
         $countries = (array) $countries;
     }
     if (!empty($this->session->PaypalResponse['TOKEN']) || empty($user['additional']['payment']['name']) || !in_array($user['additional']['country']['id'], $countries)) {
         return;
     }
     if ($this->session->offsetExists('PaypalCookieValue') && $request->getActionName() != 'shippingPayment') {
         setcookie('paypalplus_session', $this->session->offsetGet('PaypalCookieValue'));
         $view->assign('cameFromStep2', $cameFromStep2);
         $this->session->offsetUnset('PaypalCookieValue');
         $this->session->offsetUnset('PayPalPlusCameFromStep2');
     }
     $this->bootstrap->registerMyTemplateDir();
     if ($request->getActionName() == 'shippingPayment' || !$cameFromStep2) {
         $this->onPaypalPlus($action);
     }
     if ($templateVersion < 3) {
         // emotion template
         $view->extendsTemplate('frontend/payment_paypal_plus/checkout.tpl');
     }
 }
Example #7
0
 /**
  * @param Session $session
  * @param Struct\ShopContextInterface $context
  * @return null|Struct\Country\State
  */
 protected function createStateStruct(Session $session, Struct\ShopContextInterface $context)
 {
     $state = null;
     if ($session->offsetGet('sState')) {
         $state = $this->countryGateway->getState($session->offsetGet('sState'), $context);
         return $state;
     }
     return $state;
 }
Example #8
-1
 /**
  * @param Container $container
  * @return \Enlight_Components_Session_Namespace
  */
 public function factory(Container $container)
 {
     $sessionOptions = Shopware()->getOption('session', array());
     if (!empty($sessionOptions['unitTestEnabled'])) {
         \Enlight_Components_Session::$_unitTestEnabled = true;
     }
     unset($sessionOptions['unitTestEnabled']);
     if (\Enlight_Components_Session::isStarted()) {
         \Enlight_Components_Session::writeClose();
     }
     /** @var $shop \Shopware\Models\Shop\Shop */
     $shop = $container->get('Shop');
     $name = 'session-' . $shop->getId();
     $sessionOptions['name'] = $name;
     if (!isset($sessionOptions['save_handler']) || $sessionOptions['save_handler'] == 'db') {
         $config_save_handler = array('db' => $container->get('Db'), 'name' => 's_core_sessions', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'expiry');
         \Enlight_Components_Session::setSaveHandler(new \Enlight_Components_Session_SaveHandler_DbTable($config_save_handler));
         unset($sessionOptions['save_handler']);
     }
     \Enlight_Components_Session::start($sessionOptions);
     $container->set('SessionID', \Enlight_Components_Session::getId());
     $namespace = new \Enlight_Components_Session_Namespace('Shopware');
     $namespace->offsetSet('sessionId', \Enlight_Components_Session::getId());
     return $namespace;
 }