/** * @param \Enlight_Controller_ActionEventArgs $args */ public function onPostDispatchCheckoutSecure($args) { $controller = $args->getSubject(); $request = $controller->Request(); $view = $controller->View(); if ($controller->Response()->isRedirect()) { return; } $cameFromStep2 = $this->session->offsetGet('PayPalPlusCameFromStep2'); if (!$cameFromStep2 && $request->getActionName() !== 'preRedirect') { $this->session->offsetUnset('PaypalPlusPayment'); } /** @var $shop \Shopware\Models\Shop\Shop */ $shop = $this->bootstrap->get('shop'); $templateVersion = $shop->getTemplate()->getVersion(); if ($request->getActionName() === 'finish') { $this->addInvoiceInstructionsToView($view, $templateVersion); } $allowedActions = array('confirm', 'shippingPayment'); // Check action if (!in_array($request->getActionName(), $allowedActions, true)) { $this->session->offsetUnset('PayPalPlusCameFromStep2'); return; } if ($request->get('ppplusRedirect')) { $controller->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; } $this->bootstrap->registerMyTemplateDir(); if ($templateVersion < 3) { // emotion template $view->extendsTemplate('frontend/payment_paypal_plus/checkout.tpl'); } $this->addTemplateVariables($view); if ($request->getActionName() === 'shippingPayment') { $this->session->offsetSet('PayPalPlusCameFromStep2', true); $this->onPaypalPlus($controller); return; } $view->assign('cameFromStep2', $cameFromStep2); $this->session->offsetUnset('PayPalPlusCameFromStep2'); if (!$cameFromStep2 && $user['additional']['payment']['name'] === 'paypal') { $this->onPaypalPlus($controller); } }
/** * Refresh basket after login / currency change * Used in multiple locations */ public function sRefreshBasket() { // Update basket data $this->moduleManager->Admin()->sGetUserData(); $this->sGetBasket(); $this->moduleManager->Admin()->sGetPremiumShippingcosts(); // Update basket data in session $this->session->offsetSet('sBasketCurrency', Shopware()->Shop()->getCurrency()->getId()); $this->session->offsetSet('sBasketQuantity', $this->sCountBasket()); $amount = $this->sGetAmount(); $this->session->offsetSet('sBasketAmount', empty($amount) ? 0 : array_shift($amount)); }
/** * Helper function for sAdmin::sGetUserData() * Gets user shipping data (address, payment) * * @param $userId * @param $userData * @param $countryQuery * @return mixed */ private function getUserShippingData($userId, $userData, $countryQuery) { $shipping = $this->db->fetchRow("SELECT * FROM s_user_shippingaddress WHERE userID = ?", array($userId)); $shipping = $shipping ?: array(); $attributes = $this->getUserShippingAddressAttributes($userId); $userData["shippingaddress"] = array_merge($attributes, $shipping); // If shipping address is not available, billing address is coeval the shipping address $countryShipping = $this->config->get('sCOUNTRYSHIPPING'); if (!isset($userData["shippingaddress"]["firstname"])) { $userData["shippingaddress"] = $userData["billingaddress"]; $userData["shippingaddress"]["eqalBilling"] = true; } else { if ($userData["shippingaddress"]["countryID"] != $userData["billingaddress"]["countryID"] && empty($countryShipping)) { $this->db->update('s_user_shippingaddress', array('countryID' => $userData["billingaddress"]["countryID"]), array('id = ?' => $userData["shippingaddress"]["id"])); $userData["shippingaddress"]["countryID"] = $userData["billingaddress"]["countryID"]; } } if (empty($userData["shippingaddress"]["countryID"])) { $targetCountryId = $userData["billingaddress"]["countryID"]; } else { $targetCountryId = $userData["shippingaddress"]["countryID"]; } $userData["additional"]["countryShipping"] = $this->db->fetchRow($countryQuery, array($targetCountryId)); $userData["additional"]["countryShipping"] = $userData["additional"]["countryShipping"] ?: array(); $userData["additional"]["countryShipping"] = $this->sGetCountryTranslation($userData["additional"]["countryShipping"]); $this->session->offsetSet('sCountry', $userData["additional"]["countryShipping"]["id"]); // State selection $userData["additional"]["stateShipping"] = $this->db->fetchRow("SELECT * FROM s_core_countries_states WHERE id = ?", array($userData["shippingaddress"]["stateID"])); $userData["additional"]["stateShipping"] = $userData["additional"]["stateShipping"] ?: array(); $userData["additional"]["stateShipping"] = $this->sGetCountryStateTranslation($userData["additional"]["stateShipping"]); // Add stateId to session $this->session->offsetSet('sState', $userData["additional"]["stateShipping"]["id"]); // Add areaId to session $this->session->offsetSet('sArea', $userData["additional"]["countryShipping"]["areaID"]); $userData["additional"]["payment"] = $this->sGetPaymentMeanById($userData["additional"]["user"]["paymentID"], $userData); return $userData; }
/** * @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; }