/** * Main registration function used by the Register controller * Calls all previously defined helper functions to save user data * * @throws Enlight_Exception On database errors * @return boolean If the operation was successful */ public function sSaveRegister() { if ($this->eventManager->notifyUntil('Shopware_Modules_Admin_SaveRegister_Start', array('subject' => $this))) { return false; } if (!$this->session->offsetGet('sRegisterFinished')) { $register = $this->session->offsetGet('sRegister'); if (empty($register["payment"]["object"]["id"])) { // predefined payment out of the pre calculation of the shipping costs in the cart if ($this->session->offsetExists("sPaymentID")) { $register["payment"]["object"]["id"] = $this->session->offsetGet("sPaymentID"); } else { // if no predefined payment exists use the default payment $register["payment"]["object"]["id"] = $this->config->get('sDEFAULTPAYMENT'); } $this->session->offsetSet('sRegister', $register); } $this->validateRegistrationFields($register); if (!$register["payment"]["object"]["id"]) { $register["payment"]["object"]["id"] = $this->config->get('sPAYMENTDEFAULT'); } // Save main user data $userID = $this->sSaveRegisterMainData($register); if ($this->db->getErrorMessage() || !$userID) { throw new Enlight_Exception("sSaveRegister #01: Could not save data" . $this->db->getErrorMessage() . print_r($register)); } if ($register["auth"]["receiveNewsletter"]) { $this->sSaveRegisterNewsletter($register); } // Save user billing address $userBillingID = $this->sSaveRegisterBilling($userID, $register); if ($this->db->getErrorMessage() || !$userBillingID) { throw new Enlight_Exception("sSaveRegister #02: Could not save data (billing-adress)" . $this->db->getErrorMessage() . print_r($register, true)); } if ($this->config->get('sSHOPWAREMANAGEDCUSTOMERNUMBERS')) { if (!$this->eventManager->notifyUntil('Shopware_Modules_Admin_SaveRegister_GetCustomerNumber', array('subject' => $this, 'id' => $userID))) { $this->assignCustomerNumber($userID); } } // Save user shipping address if (count($register["shipping"])) { $userShippingID = $this->sSaveRegisterShipping($userID, $register); if ($this->db->getErrorMessage() || !$userShippingID) { throw new Enlight_Exception("sSaveRegister #02: Could not save data (shipping-address)" . $this->db->getErrorMessage() . print_r($register, true)); } } $uMail = $register["auth"]["email"]; $uPass = $register["auth"]["password"]; if ($register["auth"]["accountmode"] < 1) { try { $this->sSaveRegisterSendConfirmation($uMail); } catch (Exception $e) { $this->logRegistrationMailException($e, $uMail); } $this->session->offsetSet('sOneTimeAccount', false); } else { $this->session->offsetSet('sOneTimeAccount', true); } // Save referer where user comes from $referer = $this->session->offsetGet('sReferer'); if (!empty($referer)) { $this->db->insert('s_emarketing_referer', array('userID' => $userID, 'referer' => $referer, 'date' => new Zend_Date())); } $this->front->Request()->setPost('email', $uMail); $this->front->Request()->setPost('passwordMD5', $uPass); // Login user $this->sLogin(true); // The user is now registered $this->session->offsetSet('sRegisterFinished', true); $this->eventManager->notify('Shopware_Modules_Admin_SaveRegister_Successful', array('subject' => $this, 'id' => $userID, 'billingID' => $userBillingID, 'shippingID' => $userShippingID)); // Garbage $this->session->offsetUnset('sRegister'); } else { $this->front->Request()->setPost('email', $this->session->offsetGet('sUserMail')); $this->front->Request()->setPost('passwordMD5', $this->session->offsetGet('sUserPassword')); $this->sLogin($this->session->offsetGet('sOneTimeAccount')); } 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'); } }