Example #1
0
 /**
  * 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;
     }
 }
Example #2
0
 /**
  * Run task
  *
  * @return void
  */
 protected function doActionRun()
 {
     $event = \XLite\Core\Request::getInstance()->event;
     $result = false;
     $errors = array();
     $task = \XLite\Core\Database::getRepo('XLite\\Model\\EventTask')->findOneBy(array('name' => $event));
     if ($task) {
         if (\XLite\Core\EventListener::getInstance()->handle($task->getName(), $task->getArguments())) {
             \XLite\Core\Database::getEM()->remove($task);
             $result = true;
         }
         $errors = \XLite\Core\EventListener::getInstance()->getErrors();
     } else {
         \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->removeEventState($event);
     }
     \XLite\Core\Database::getEM()->flush();
     $state = \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventState($event);
     $this->setPureAction(true);
     if ($result && $state) {
         \XLite\Core\Event::eventTaskRun(array('percent' => \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventStatePercent($event), 'error' => !empty($errors)));
     } else {
         $result = false;
     }
     if ($errors) {
         foreach ($errors as $message) {
             \XLite\Core\TopMessage::addError($message);
         }
         $result = false;
     }
     $this->valid = $result;
 }
Example #3
0
 /**
  * Fire event 
  * 
  * @return void
  */
 protected function fireEvent()
 {
     \XLite\Core\Event::switchStorefront(array('opened' => !\XLite\Core\Auth::getInstance()->isClosedStorefront(), 'link' => $this->buildURL('storefront', '', array('action' => \XLite\Core\Auth::getInstance()->isClosedStorefront() ? 'open' : 'close')), 'privatelink' => $this->getAccessibleShopURL(false)));
     if ($this->isAJAX()) {
         $this->silent = true;
         $this->setSuppressOutput(true);
     }
 }
Example #4
0
 /**
  * Do action
  *
  * @return void
  */
 protected function doActionConfirmWithPassword()
 {
     $password = \XLite\Core\Request::getInstance()->password;
     $result = null !== $password && \XLite\Core\Auth::comparePassword(\XLite\Core\Auth::getInstance()->getProfile()->getPassword(), $password);
     if (!$result) {
         \XLite\Core\TopMessage::addError('Incorrect password. Please try again.');
     }
     \XLite\Core\Event::passwordConfirmed(array('result' => $result));
 }
Example #5
0
 /**
  * Do action update
  *
  * @return void
  */
 protected function doActionUpdate()
 {
     $this->getModelForm()->performAction('modify');
     $itemsList = new \XLite\View\ItemsList\Model\Shipping\Markups();
     $itemsList->processQuick();
     $this->setReturnURL($this->buildURL('shipping_rates', '', array('widget' => 'XLite\\View\\Shipping\\EditMethod', 'methodId' => $this->getModelForm()->getModelObject()->getMethodId(), 'shippingZone' => \XLite\Core\Request::getInstance()->shippingZone)));
     $this->setInternalRedirect();
     \XLite\Core\Event::updateShippingMethods();
 }
Example #6
0
 protected function doActionConnect()
 {
     $method = \XLite\Core\Database::getRepo('\\XLite\\Model\\Payment\\Method')->createQueryBuilder('p')->where('p.service_name = \'BitPay\'')->getResult()[0];
     $bitpayWrapper = new XcartWrapper($method);
     $connection = $bitpayWrapper->setting('connection');
     $private_key = $bitpayWrapper->setting('private_key');
     if (!empty($private_key) || $connection !== 'disconnected') {
         $bitpayWrapper->checkConnection();
     }
     \XLite\Core\Event::connectionState($connection);
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 /**
  * 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();
 }
Example #9
0
 /**
  * Assemble updateCart event
  *
  * @return boolean
  */
 protected function assembleEvent()
 {
     $result = false;
     $diff = array();
     $old = $this->initialCartFingerprint;
     $new = $this->getCart()->getEventFingerprint();
     $items = array();
     // Assembly changed
     foreach ($new['items'] as $n => $cell) {
         $found = false;
         foreach ($old['items'] as $i => $oldCell) {
             if ($cell['key'] == $oldCell['key']) {
                 if ($cell['quantity'] != $oldCell['quantity']) {
                     $cell['quantity_change'] = $cell['quantity'] - $oldCell['quantity'];
                     $items[] = $cell;
                 }
                 unset($old['items'][$i]);
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $cell['quantity_change'] = $cell['quantity'];
             $items[] = $cell;
         }
     }
     // Assemble removed
     foreach ($old['items'] as $cell) {
         $cell['quantity_change'] = $cell['quantity'] * -1;
         $items[] = $cell;
     }
     if ($items) {
         $diff['items'] = $items;
     }
     if ($old['total'] != $this->getCart()->getTotal()) {
         $diff['total'] = $this->getCart()->getTotal() - $old['total'];
     }
     if ($diff) {
         \XLite\Core\Event::updateCart($diff);
         $result = true;
     }
     return $result;
 }
Example #10
0
 /**
  * Select address
  *
  * @return void
  */
 protected function doActionSelect()
 {
     $atype = \XLite\Core\Request::getInstance()->atype;
     $addressId = \XLite\Core\Request::getInstance()->addressId;
     if (\XLite\Model\Address::SHIPPING != $atype && \XLite\Model\Address::BILLING != $atype) {
         $this->valid = false;
         \XLite\Core\TopMessage::addError('Address type has wrong value');
     } elseif (!$addressId) {
         $this->valid = false;
         \XLite\Core\TopMessage::addError('Address is not selected');
     } else {
         $address = \XLite\Core\Database::getRepo('XLite\\Model\\Address')->find($addressId);
         if (!$address) {
             // Address not found
             $this->valid = false;
             \XLite\Core\TopMessage::addError('Address not found');
         } elseif (\XLite\Model\Address::SHIPPING == $atype && $this->getCart()->getProfile()->getShippingAddress() && $address->getAddressId() == $this->getCart()->getProfile()->getShippingAddress()->getAddressId()) {
             // This shipping address is already selected
             $this->silenceClose = true;
         } elseif (\XLite\Model\Address::BILLING == $atype && $this->getCart()->getProfile()->getBillingAddress() && $address->getAddressId() == $this->getCart()->getProfile()->getBillingAddress()->getAddressId()) {
             // This billing address is already selected
             $this->silenceClose = true;
         } else {
             if (\XLite\Model\Address::SHIPPING == $atype) {
                 $old = $this->getCart()->getProfile()->getShippingAddress();
                 if ($old) {
                     $old->setIsShipping(false);
                 }
                 $address->setIsShipping(true);
                 $event = array('shippingAddress' => true);
             } else {
                 $old = $this->getCart()->getProfile()->getBillingAddress();
                 if ($old) {
                     $old->setIsBilling(false);
                 }
                 $address->setIsBilling(true);
                 $event = array('billingAddress' => array('same' => $address->getIsShipping()));
             }
             \XLite\Core\Event::updateCart($event);
             \XLite\Core\Database::getEM()->flush();
             $this->updateCart();
             $this->silenceClose = true;
         }
     }
 }
Example #11
0
 /**
  * Add top message if log in is failed
  *
  * @param mixed $result Result of log in procedure
  *
  * @return void
  */
 protected function addLoginFailedMessage($result)
 {
     if (in_array($result, array(\XLite\Core\Auth::RESULT_ACCESS_DENIED, \XLite\Core\Auth::RESULT_PASSWORD_NOT_EQUAL))) {
         \XLite\Core\TopMessage::addError('Invalid login or password');
         \XLite\Core\Event::invalidForm('login-form', static::t('Invalid login or password'));
     }
 }
Example #12
0
 /**
  * Process import step 
  * 
  * @return void
  */
 protected function processImportStep()
 {
     $this->startImportStep();
     $expire = time() + static::IMPORT_TTL;
     while (time() < $expire && !feof($this->filePointer)) {
         $row = fgetcsv($this->filePointer, 0, static::DELIMIER);
         $row = is_array($row) ? array_map('trim', $row) : array();
         if ($row && preg_grep('/^.+$/Ss', $row)) {
             // Assemble associated list
             $list = $this->assembleImportRow($row);
             // Detect and get product
             $product = $this->getProduct($list);
             if (!$product->getId()) {
                 if ($this->checkRequiredImportFields($list)) {
                     \XLite\Core\Database::getEM()->persist($product);
                 } else {
                     $product = null;
                 }
             }
             if ($product) {
                 if (count($list) != $this->importCell['row_length']) {
                     $this->logImportWarning(static::t('The string is different from that of the title number of columns - X instead of Y', array('right' => $this->importCell['row_length'], 'wrong' => count($list))), $this->importCell['position'], null, null, $product);
                 }
                 $this->importRow($product, $list);
                 if (!$product->getId()) {
                     $this->importCell['new']++;
                 }
                 \XLite\Core\Database::getEM()->flush();
             }
         }
         $this->importCell['position']++;
     }
     if (feof($this->filePointer)) {
         \XLite\Core\Event::importFinish();
         $this->postprocessImport();
         $this->clearImportCell();
     } else {
         \XLite\Core\Session::getInstance()->importCell = $this->importCell;
         $position = ftell($this->filePointer);
         fseek($this->filePointer, 0, SEEK_END);
         \XLite\Core\Event::importAfterStep(array('position' => $position, 'length' => ftell($this->filePointer)));
     }
     fclose($this->filePointer);
 }
Example #13
0
 /**
  * Display content for the AJAX requests
  *
  * @param string $content Content to display
  *
  * @return void
  */
 protected function displayAJAXContent($content)
 {
     // Dispatch events
     \XLite\Core\Event::getInstance()->display();
     \XLite\Core\Event::getInstance()->clear();
     // Send headers. TODO: Should be one header sending point.
     \XLite\View\Controller::sendHeaders();
     // Display content
     echo '<h2 class="ajax-title-loadable">' . $this->getTitle() . '</h2>';
     echo '<div class="ajax-container-loadable">' . $content . '</div>';
     exit(0);
 }
Example #14
0
 /**
  * Update profile billing address
  *
  * @return void
  */
 protected function updateBillingAddress()
 {
     $noAddress = false;
     $data = empty($this->requestData['billingAddress']) ? null : $this->requestData['billingAddress'];
     $profile = $this->getCartProfile();
     if (isset($this->requestData['same_address'])) {
         \XLite\Core\Session::getInstance()->same_address = (bool) $this->requestData['same_address'];
     }
     if ($this->requestData['same_address']) {
         // Shipping and billing are same addresses
         $address = $profile->getBillingAddress();
         if ($address) {
             // Unselect old billing address
             $address->setIsBilling(false);
         }
         $address = $profile->getShippingAddress();
         if ($address) {
             // Link shipping and billing address
             $address->setIsBilling(true);
         }
     } elseif (isset($this->requestData['same_address']) && !$this->requestData['same_address']) {
         // Unlink shipping and billing addresses
         $address = $profile->getShippingAddress();
         if ($address && $address->getIsBilling()) {
             $address->setIsBilling(false);
         }
     }
     if (is_array($data) && !$this->requestData['same_address']) {
         // Save separate billing address
         $address = $profile->getBillingAddress();
         if ($address) {
             \XLite\Core\Database::getEM()->refresh($address);
         }
         $andAsShipping = false;
         $current = new \XLite\Model\Address();
         $current->map($this->prepareAddressData($data, 'billing'));
         $equal = null;
         foreach ($profile->getAddresses() as $addressEqual) {
             if ($addressEqual->isEqualAddress($current) && (!$address || $address->getAddressId() != $addressEqual->getAddressId())) {
                 $equal = $addressEqual;
                 break;
             }
         }
         if ($equal) {
             if ($address && $address->getIsWork()) {
                 $profile->getAddresses()->removeElement($address);
                 \XLite\Core\Database::getEM()->remove($address);
             }
             if ($address) {
                 $andAsShipping = $address->getIsShipping();
                 $address->setIsBilling(false);
                 if ($andAsShipping) {
                     $address->setIsShipping(false);
                 }
             }
             $address = $equal;
             $address->setIsBilling(true);
             if ($andAsShipping) {
                 $address->setIsShipping($andAsShipping);
             }
         }
         if (!$address || !$address->getIsWork() && !$address->isEqualAddress($current)) {
             if ($address) {
                 $andAsShipping = $address->getIsShipping();
                 $address->setIsBilling(false);
                 $address->setIsShipping(false);
             }
             $address = new \XLite\Model\Address();
             $address->setProfile($profile);
             $address->setIsBilling(true);
             $address->setIsShipping($andAsShipping);
             $address->setIsWork(true);
             if (!(bool) \XLite\Core\Request::getInstance()->only_calculate) {
                 $profile->addAddresses($address);
                 \XLite\Core\Database::getEM()->persist($address);
                 $noAddress = true;
             }
         }
         $address->map($this->prepareAddressData($data, 'billing'));
         \XLite\Core\Session::getInstance()->same_address = $this->getCart()->getProfile()->isEqualAddress();
     }
     if ($noAddress) {
         \XLite\Core\Event::createBillingAddress(array('id' => $address->getAddressId()));
     }
 }
Example #15
0
 /**
  * Select address
  *
  * @return void
  */
 protected function doActionSelect()
 {
     $atype = \XLite\Core\Request::getInstance()->atype;
     $addressId = \XLite\Core\Request::getInstance()->addressId;
     if (\XLite\Model\Address::SHIPPING != $atype && \XLite\Model\Address::BILLING != $atype) {
         $this->valid = false;
         \XLite\Core\TopMessage::addError('Address type has wrong value');
     } elseif (!$addressId) {
         $this->valid = false;
         \XLite\Core\TopMessage::addError('Address is not selected');
     } else {
         $address = \XLite\Core\Database::getRepo('XLite\\Model\\Address')->find($addressId);
         if (!$address) {
             // Address not found
             $this->valid = false;
             \XLite\Core\TopMessage::addError('Address not found');
         } elseif (\XLite\Model\Address::SHIPPING == $atype && $this->getCart()->getProfile()->getShippingAddress() && $address->getAddressId() == $this->getCart()->getProfile()->getShippingAddress()->getAddressId()) {
             // This shipping address is already selected
             $this->silenceClose = true;
         } elseif (\XLite\Model\Address::BILLING == $atype && $this->getCart()->getProfile()->getBillingAddress() && $address->getAddressId() == $this->getCart()->getProfile()->getBillingAddress()->getAddressId()) {
             // This billing address is already selected
             $this->silenceClose = true;
         } else {
             if (\XLite\Model\Address::SHIPPING == $atype) {
                 $old = $this->getCart()->getProfile()->getShippingAddress();
                 $andAsBilling = false;
                 if ($old) {
                     $old->setIsShipping(false);
                     $andAsBilling = $old->getIsBilling();
                     if ($old->getIsWork()) {
                         $this->getCart()->getProfile()->getAddresses()->removeElement($old);
                         \XLite\Core\Database::getEM()->remove($old);
                     } elseif ($andAsBilling) {
                         $old->setIsBilling(false);
                     }
                 } elseif (!$this->getCart()->getProfile()->getBillingAddress()) {
                     $andAsBilling = true;
                 }
                 $address->setIsShipping(true);
                 if ($andAsBilling) {
                     $address->setIsBilling($andAsBilling);
                 }
             } else {
                 $old = $this->getCart()->getProfile()->getBillingAddress();
                 $andAsShipping = false;
                 if ($old) {
                     $old->setIsBilling(false);
                     $andAsShipping = $old->getIsShipping();
                     if ($old->getIsWork()) {
                         $this->getCart()->getProfile()->getAddresses()->removeElement($old);
                         \XLite\Core\Database::getEM()->remove($old);
                     } elseif ($andAsShipping) {
                         $old->setIsShipping(false);
                     }
                 } elseif (!$this->getCart()->getProfile()->getShippingAddress()) {
                     $andAsShipping = true;
                 }
                 $address->setIsBilling(true);
                 if ($andAsShipping) {
                     $address->setIsShipping($andAsShipping);
                 }
             }
             \XLite\Core\Session::getInstance()->same_address = $this->getCart()->getProfile()->isEqualAddress();
             \XLite\Core\Event::selectCartAddress(array('type' => $atype, 'addressId' => $address->getAddressId(), 'same' => $this->getCart()->getProfile()->isSameAddress()));
             \XLite\Core\Database::getEM()->flush();
             $this->updateCart();
             $this->silenceClose = true;
         }
     }
 }
Example #16
0
 /**
  * Display recalculate item price
  *
  * @param \XLite\Model\OrderItem $item Order item
  *
  * @return void
  */
 protected function displayRecalculateItemPrice(\XLite\Model\OrderItem $item)
 {
     \XLite\Core\Event::recalculateItem($this->assembleRecalculateItemEvent($item));
 }
Example #17
0
 /**
  * Change shipping method
  *
  * @return void
  */
 protected function doActionChangeMethod()
 {
     if (\XLite\Core\Request::getInstance()->methodId && $this->getCart()->getShippingId() != \XLite\Core\Request::getInstance()->methodId) {
         $this->getCart()->setShippingId(\XLite\Core\Request::getInstance()->methodId);
         $address = $this->getCartProfile()->getShippingAddress();
         if (!$address) {
             // Default address
             $profile = $this->getCartProfile();
             $address = new \XLite\Model\Address();
             $addr = $this->getAddress();
             // Country
             $c = 'US';
             if ($addr && isset($addr['country'])) {
                 $c = $addr['country'];
             } elseif (\XLite\Core\Config::getInstance()->General->default_country) {
                 $c = \XLite\Core\Config::getInstance()->General->default_country;
             }
             $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find($c);
             if ($country) {
                 $address->setCountry($country);
             }
             // State
             $state = null;
             if ($addr && !empty($addr['state'])) {
                 $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->find($addr['state']);
             } elseif (!$addr && \XLite\Core\Config::getInstance()->Shipping->anonymous_custom_state) {
                 $state = new \XLite\Model\State();
                 $state->setState(\XLite\Core\Config::getInstance()->Shipping->anonymous_custom_state);
             }
             if ($state) {
                 $address->setState($state);
             }
             // Zip code
             $address->setZipcode(\XLite\Core\Config::getInstance()->General->default_zipcode);
             $address->setProfile($profile);
             $address->setIsShipping(true);
             $profile->addAddresses($address);
             \XLite\Core\Database::getEM()->persist($address);
         }
         $this->updateCart();
         \XLite\Core\Event::updateCart(array('items' => array(), 'shipping' => $this->getCart()->getShippingId()));
     }
     $this->valid = true;
     $this->setSilenceClose();
 }
Example #18
0
 /**
  * Update profile
  *
  * @return void
  */
 protected function doActionUpdateProfile()
 {
     parent::doActionUpdateProfile();
     $showSaveCardBox = $this->showSaveCardBox() ? 'Y' : 'N';
     $checkCheckoutAction = $this->checkCheckoutAction() ? 'Y' : 'N';
     \XLite\Core\Event::xpcEvent(array('showSaveCardBox' => $showSaveCardBox, 'checkCheckoutAction' => $checkCheckoutAction));
 }
Example #19
0
 /**
  * Update list
  *
  * @return void
  */
 protected function doActionUpdate()
 {
     $list = new \XLite\View\ItemsList\Model\AttributeGroup();
     $list->processQuick();
     if (!$this->isActionError()) {
         $this->setSilenceClose();
         \XLite\Core\Event::updateAttributeGroups();
     }
 }
Example #20
0
 /**
  * Update model
  *
  * @return void
  */
 protected function doActionUpdate()
 {
     if ($this->getModelForm()->getModelObject()->getId()) {
         $this->setSilenceClose();
     } else {
         $this->setInternalRedirect();
     }
     $list = new \XLite\View\ItemsList\Model\AttributeOption();
     $list->processQuick();
     if ($this->getModelForm()->performAction('modify')) {
         \XLite\Core\Event::updateAttribute(array('id' => $this->getModelForm()->getModelObject()->getId()));
         $this->setReturnUrl(\XLite\Core\Converter::buildURL('attribute', '', array('id' => $this->getModelForm()->getModelObject()->getId(), 'product_class_id' => \XLite\Core\Request::getInstance()->product_class_id, 'widget' => 'XLite\\View\\Attribute')));
     }
 }
Example #21
0
 /**
  * Assemble updateCart event
  *
  * @return boolean
  */
 protected function assembleEvent()
 {
     $diff = $this->getCartFingerprintDifference($this->initialCartFingerprint, $this->getCart()->getEventFingerprint($this->getCartFingerprintExclude()));
     if ($diff) {
         $actualDiff = $this->posprocessCartFingerprintDifference($diff);
         if ($actualDiff) {
             \XLite\Core\Event::updateCart($actualDiff);
         }
     }
     return (bool) $diff;
 }
Example #22
0
 /**
  * Perform redirect
  *
  * @param string $url Redirect URL OPTIONAL
  *
  * @return void
  */
 protected function redirect($url = null)
 {
     $location = $this->getReturnURL();
     if (!isset($location)) {
         $location = isset($url) ? $url : $this->getURL();
     }
     // filter FORM ID from redirect url
     // FIXME - check if it's really needed
     $action = $this->get('action');
     if (empty($action)) {
         $location = $this->filterXliteFormID($location);
     }
     \XLite\Core\Event::getInstance()->display();
     \XLite\Core\Event::getInstance()->clear();
     $location = $this->addCleanupCacheMark($location);
     \XLite\Core\Operator::redirect($location, $this->getRedirectMode(), $this->getParam(static::PARAM_REDIRECT_CODE));
 }
Example #23
0
 /**
  * Update profiel billing address
  *
  * @return void
  */
 protected function updateBillingAddress()
 {
     $data = $this->requestData['billingAddress'];
     $profile = $this->getCartProfile();
     if ($this->requestData['same_address']) {
         // Shipping and billing are same addresses
         $address = $profile->getBillingAddress();
         if ($address) {
             // Unselect old billing address
             $address->setIsBilling(false);
         }
         $address = $profile->getShippingAddress();
         if ($address) {
             // Link shipping and billing address
             $address->setIsBilling(true);
         } else {
             $this->valid = false;
         }
     } elseif (isset($this->requestData['same_address']) && !$this->requestData['same_address']) {
         // Unlink shipping and billing addresses
         $address = $profile->getShippingAddress();
         if ($address && $address->getIsBilling()) {
             $address->setIsBilling(false);
         }
     }
     if (!$this->requestData['same_address'] && is_array($data)) {
         // Save separate billing address
         $address = $profile->getBillingAddress();
         if ($address) {
             \XLite\Core\Database::getEM()->refresh($address);
         }
         $andAsShipping = false;
         if (!$address || $data['save_as_new']) {
             if ($address) {
                 $andAsShipping = $address->getIsShipping();
                 $address->setIsBilling(false);
                 $address->setIsShipping(false);
             }
             $address = new \XLite\Model\Address();
             $address->setProfile($profile);
             $address->setIsBilling(true);
             $address->setIsShipping($andAsShipping);
             if (!(bool) \XLite\Core\Request::getInstance()->only_calculate) {
                 $profile->addAddresses($address);
                 \XLite\Core\Database::getEM()->persist($address);
             }
         }
         $address->map($this->prepareAddressData($data));
         \XLite\Core\Event::updateCart(array('billingAddress' => array('same' => $address->getIsShipping())));
     }
     $this->updateCart();
 }
Example #24
0
 /**
  * Recover password
  *
  * @param string $email     Profile email
  * @param string $requestID Request ID
  *
  * @return boolean
  */
 protected function doPasswordRecovery($email, $requestID)
 {
     $result = false;
     $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($email);
     if (!isset($profile) || $profile->isAdmin()) {
         \XLite\Core\TopMessage::addError('There is no user with specified email address');
     } elseif ($profile->getPasswordResetKey() != $requestID || \XLite\Core\Converter::time() > $profile->getPasswordResetKeyDate()) {
         \XLite\Core\TopMessage::addError('Your "Password reset key" has expired. Please enter the email address associated with your user account to get a new "Password reset key".');
         $profile->setPasswordResetKey('');
         $profile->setPasswordResetKeyDate(0);
         $profile->update();
     } else {
         $pass = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->generatePassword();
         $profile->setPassword(\XLite\Core\Auth::encryptPassword($pass));
         $profile->setForceChangePassword(true);
         $profile->setPasswordResetKey('');
         $profile->setPasswordResetKeyDate(0);
         $result = $profile->update();
         if ($result) {
             $successfullyLogged = \XLite\Core\Auth::getInstance()->loginProfile($profile);
             if ($successfullyLogged) {
                 $profileCart = $this->getCart();
                 // We merge the logged in cart into the session cart
                 $profileCart->login($profile);
                 \XLite\Core\Database::getEM()->flush();
                 if ($profileCart->isPersistent()) {
                     $this->updateCart();
                     \XLite\Core\Event::getInstance()->exclude('updateCart');
                 }
             }
         }
     }
     return $result;
 }
Example #25
0
 /**
  * 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();
 }