/** * Update profile * FIXME * * @return void */ protected function updateProfile() { if ($this->isCreateProfile()) { $error = user_validate_name(\XLite\Core\Request::getInstance()->username); if ($error) { // Username validation error $this->valid = false; \XLite\Core\Event::invalidElement('username', $error); } elseif (user_load_by_name(\XLite\Core\Request::getInstance()->username)) { // Username is already exists $this->valid = false; $label = static::t('This user name is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL())); \XLite\Core\Event::invalidElement('username', $label); } elseif (\XLite\Core\Request::getInstance()->email && user_load_multiple(array(), array('mail' => \XLite\Core\Request::getInstance()->email))) { // E-mail is already exists in Drupal DB $this->valid = false; $label = static::t('This email address is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL())); \XLite\Core\Event::invalidElement('email', $label); } } parent::updateProfile(); if ($this->isCreateProfile() && $this->valid) { // Save username is session (temporary, wait place order procedure) \XLite\Core\Session::getInstance()->order_username = \XLite\Core\Request::getInstance()->create_profile ? \XLite\Core\Request::getInstance()->username : false; } }
/** * Get request data * * @return mixed */ public function getRequestData() { $data = null; $validator = $this->getValidator(); try { $validator->validate(\XLite\Core\Request::getInstance()->getData()); $data = $validator->sanitize(\XLite\Core\Request::getInstance()->getData()); } catch (\XLite\Core\Validator\Exception $exception) { $message = static::t($exception->getMessage(), $exception->getLabelArguments()); if ($exception->isInternal()) { \XLite\Logger::getInstance()->log($message, LOG_ERR); } else { \XLite\Core\Event::invalidElement($exception->getPath(), $message); } $this->validationMessage = ($exception->getPublicName() ? static::t($exception->getPublicName()) . ': ' : '') . $message; } return $data; }
/** * Apply coupon to the cart * * @return void */ protected function doActionAdd() { $code = (string) \XLite\Core\Request::getInstance()->code; /** @var \XLite\Module\CDev\Coupons\Model\Coupon $coupon */ $coupon = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Coupons\\Model\\Coupon')->findOneByCode($code); $cart = $this->getCart(); if ($coupon) { $error = $this->checkCompatibility($coupon, $cart); } else { $error = static::t('There is no such a coupon, please check the spelling: X', array('code' => $code)); } if ('' === $error) { $cart->addCoupon($coupon); \XLite\Core\Database::getEM()->flush(); $this->updateCart(); \XLite\Core\TopMessage::addInfo('The coupon has been applied to your order'); } elseif ($error) { \XLite\Core\Event::invalidElement('code', $error); } $this->setPureAction(); }
/** * doActionRecoverPassword * * @return void */ protected function doActionRecoverPassword() { if ($this->requestRecoverPassword($this->get('email'))) { \XLite\Core\TopMessage::addInfo('The confirmation URL link was mailed to email', array('email' => $this->get('email'))); if ($this->isAJAX()) { \XLite\Core\Event::recoverPasswordSent(array('email' => $this->get('email'))); $this->setSilenceClose(); } else { $this->setReturnURL($this->buildURL()); } } else { $this->setReturnURL($this->buildURL('recover_password')); if (!$this->isAJAX()) { \XLite\Core\TopMessage::addError('There is no user with specified email address'); } \XLite\Core\Event::invalidElement('email', static::t('There is no user with specified email address')); } }
/** * Update anonymous profile * * @return void */ protected function updateAnonymousProfile() { $login = $this->requestData['email']; if (null !== $login) { $tmpProfile = new \XLite\Model\Profile(); $tmpProfile->setProfileId(0); $tmpProfile->setLogin($login); $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findUserWithSameLogin($tmpProfile); $exists = $profile && !$profile->getAnonymous(); if ($profile) { \XLite\Core\Database::getEM()->detach($profile); } if ($exists) { \XLite\Core\Session::getInstance()->order_create_profile = false; } \XLite\Core\Session::getInstance()->lastLoginUnique = !$exists; $profile = $this->getCartProfile(); $profile->setLogin($login); \XLite\Core\Database::getEM()->flush($profile); \XLite\Core\Event::loginExists(array('value' => $exists)); if ($exists && $this->requestData['create_profile']) { // Profile with same login is exists $this->valid = false; } elseif (isset($this->requestData['password']) && !$this->requestData['password'] && $this->requestData['create_profile']) { $this->valid = false; $label = static::t('Field is required!'); \XLite\Core\Event::invalidElement('password', $label); } elseif (false !== $this->valid) { \XLite\Core\Session::getInstance()->order_create_profile = (bool) $this->requestData['create_profile']; if (\XLite\Core\Session::getInstance()->order_create_profile) { \XLite\Core\Session::getInstance()->createProfilePassword = $this->requestData['password']; } } } }
/** * Update profile * * @return void */ protected function updateProfile() { $login = $this->requestData['email']; if (isset($login)) { $tmpProfile = new \XLite\Model\Profile(); $tmpProfile->setProfileId(0); $tmpProfile->setLogin($login); $profile = $this->requestData['create_profile'] ? \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findUserWithSameLogin($tmpProfile) : null; if ($profile) { // Profile with same login is exists \XLite\Core\Database::getEM()->detach($profile); $this->valid = false; $label = static::t('This email address is used for an existing account. Enter another email address or sign in', array('URL' => $this->getLoginURL())); \XLite\Core\Event::invalidElement('email', $label); } elseif (false !== $this->valid) { $profile = $this->getCartProfile(); $profile->setLogin($login); $this->getCart()->setProfile($profile); \XLite\Core\Session::getInstance()->order_create_profile = (bool) $this->requestData['create_profile']; $this->getCart()->setOrigProfile($profile); $this->updateCart(); } } }
/** * Apply coupon to the cart * * @return void */ protected function doActionAdd() { $code = strval(\XLite\Core\Request::getInstance()->code); /** @var \XLite\Module\CDev\Coupons\Model\Coupon $coupon */ $coupon = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Coupons\\Model\\Coupon')->findOneByCode($code); $codes = $coupon ? $coupon->getErrorCodes($this->getCart()) : array(); $error = null; if (!$coupon || $codes) { $this->valid = false; if ($coupon && in_array(\XLite\Module\CDev\Coupons\Model\Coupon::ERROR_SINGLE_USE, $codes)) { $error = static::t('This coupon cannot be combined with other coupons'); } elseif ($coupon && in_array(\XLite\Module\CDev\Coupons\Model\Coupon::ERROR_SINGLE_USE2, $codes)) { $error = static::t('Sorry, this coupon cannot be combined with the coupon already applied. Revome the previously applied coupon and try again.'); } elseif ($coupon && in_array(\XLite\Module\CDev\Coupons\Model\Coupon::ERROR_TOTAL, $codes)) { $currency = $this->getCart()->getCurrency(); if (0 < $coupon->getTotalRangeBegin() && 0 < $coupon->getTotalRangeEnd()) { $error = static::t('To use the coupon, your order subtotal must be between X and Y', array('min' => $currency->formatValue($coupon->getTotalRangeBegin()), 'max' => $currency->formatValue($coupon->getTotalRangeEnd()))); } elseif (0 < $coupon->getTotalRangeBegin()) { $error = static::t('To use the coupon, your order subtotal must be at least X', array('min' => $currency->formatValue($coupon->getTotalRangeBegin()))); } else { $error = static::t('To use the coupon, your order subtotal must not exceed Y', array('max' => $currency->formatValue($coupon->getTotalRangeEnd()))); } } else { $error = static::t('There is no such a coupon, please check the spelling: X', array('code' => $code)); } } else { $found = false; foreach ($this->getCart()->getUsedCoupons() as $usedCoupon) { if ($usedCoupon->getCoupon() && $usedCoupon->getCoupon()->getId() == $coupon->getId()) { $found = true; break; } } if ($found) { // Duplicate $this->valid = false; $error = static::t('You have already used the coupon'); } else { // Create $usedCoupon = new \XLite\Module\CDev\Coupons\Model\UsedCoupon(); $usedCoupon->setOrder($this->getCart()); $this->getCart()->addUsedCoupons($usedCoupon); $usedCoupon->setCoupon($coupon); $coupon->addUsedCoupons($usedCoupon); \XLite\Core\Database::getEM()->persist($usedCoupon); $this->updateCart(); \XLite\Core\Database::getEM()->flush(); \XLite\Core\TopMessage::addInfo('The coupon has been applied to your order'); } } if ($error) { \XLite\Core\Event::invalidElement('code', $error); } $this->setPureAction(); }