Esempio n. 1
0
 /**
  * Create missed LiteCommerce accounts 
  * 
  * @return void
  */
 protected function createMissedLCAccounts()
 {
     foreach ($this->drupalAccounts as $k => $account) {
         if ($this->checkUserAccountsPerStepCounter()) {
             $profile = new \XLite\Model\Profile();
             $profile->setLogin($account->mail);
             $profile->setCmsProfileId($account->uid);
             $profile->setCmsName(\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->getCMSName());
             $profile->setStatus(1 === intval($account->status) ? 'E' : 'D');
             $pass = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->generatePassword();
             $profile->setPassword(md5($pass));
             $user = user_load($account->uid);
             if (user_access(\XLite\Module\CDev\DrupalConnector\Drupal\Profile::LC_DRUPAL_ADMIN_ROLE_NAME, $user)) {
                 $profile->setAccessLevel(\XLite\Core\Auth::getInstance()->getAdminAccessLevel());
             }
             $profile->create();
             unset($this->drupalAccounts[$k]);
         } else {
             break;
         }
     }
 }
Esempio n. 2
0
 /**
  * Get or create cart profile
  *
  * @return \XLite\Model\Profile
  */
 protected function getCartProfile()
 {
     $profile = $this->getCart()->getProfile();
     if (!$profile) {
         $profile = new \XLite\Model\Profile();
         $profile->setLogin('');
         $profile->setOrder($this->getCart());
         $profile->create();
         $this->getCart()->setProfile($profile);
         \XLite\Core\Auth::getInstance()->loginProfile($profile);
         \XLite\Core\Database::getEM()->persist($profile);
         \XLite\Core\Database::getEM()->flush();
     }
     return $profile;
 }
Esempio n. 3
0
 /**
  * Fetches an existing social login profile or creates new
  *
  * @param string $login          E-mail address
  * @param string $socialProvider SocialLogin auth provider
  * @param string $socialId       SocialLogin provider-unique id
  * @param array  $profileInfo    Profile info OPTIONAL
  *
  * @return \XLite\Model\Profile
  */
 protected function getSocialLoginProfile($login, $socialProvider, $socialId, $profileInfo = array())
 {
     $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('socialLoginProvider' => $socialProvider, 'socialLoginId' => $socialId, 'order' => null));
     if (!$profile) {
         $profile = new \XLite\Model\Profile();
         $profile->setLogin($login);
         $profile->setSocialLoginProvider($socialProvider);
         $profile->setSocialLoginId($socialId);
         $existingProfile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $login, 'order' => null));
         if ($existingProfile) {
             $profile = null;
         } else {
             $profile->create();
             if ($profileInfo && isset($profileInfo['given_name']) && isset($profileInfo['family_name']) && isset($profileInfo['address'])) {
                 $address = new \XLite\Model\Address();
                 $address->setProfile($profile);
                 $address->setFirstname($profileInfo['given_name']);
                 $address->setLastname($profileInfo['family_name']);
                 if (isset($profileInfo['address']['country']) && isset($profileInfo['address']['region'])) {
                     $address->setCountryCode($profileInfo['address']['country']);
                     $state = \XLite\Core\Database::getRepo('XLite\\Model\\State')->findOneByCountryAndCode($profileInfo['address']['country'], $profileInfo['address']['region']);
                     if ($state) {
                         $address->setState($state);
                     }
                 }
                 if (isset($profileInfo['address']['locality'])) {
                     $address->setCity($profileInfo['address']['locality']);
                 }
                 if (isset($profileInfo['address']['street_address'])) {
                     $address->setStreet($profileInfo['address']['street_address']);
                 }
                 if (isset($profileInfo['address']['postal_code'])) {
                     $address->setZipcode($profileInfo['address']['postal_code']);
                 }
                 if (isset($profileInfo['phone_number'])) {
                     $address->setPhone($profileInfo['phone_number']);
                 }
                 $address->setIsShipping(true);
                 $address->setIsBilling(true);
                 $profile->addAddresses($address);
                 $address->create();
             }
         }
     }
     return $profile;
 }
Esempio n. 4
0
 /**
  * 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'];
             }
         }
     }
 }
Esempio n. 5
0
 protected function checkAnonymousProfile()
 {
     // amazon checkout is always anonymous, logoff but not clear cart
     if (\XLite\Core\Auth::getInstance()->isLogged()) {
         \XLite\Core\Auth::getInstance()->logoff();
         $tmpProfile = new \XLite\Model\Profile();
         $tmpProfile->setAnonymous(true);
         \XLite\Core\Database::getEM()->persist($tmpProfile);
         $this->getCart()->setProfile($tmpProfile);
         $this->getCart()->setOrigProfile($tmpProfile);
         \XLite\Core\Database::getEM()->flush();
     }
 }
Esempio n. 6
0
 /**
  * Method to access a singleton
  *
  * @param boolean $doCalculate Flag for cart recalculation OPTIONAL
  *
  * @return \XLite\Model\Cart
  */
 public static function getInstance($doCalculate = true)
 {
     $className = get_called_class();
     // Create new instance of the object (if it is not already created)
     if (!isset(static::$instances[$className])) {
         $auth = \XLite\Core\Auth::getInstance();
         if ($auth->isLogged()) {
             // Try to find cart of logged in user
             $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->findOneByProfile($auth->getProfile());
         }
         if (empty($cart)) {
             // Try to get cart from session
             $orderId = \XLite\Core\Session::getInstance()->order_id;
             if ($orderId) {
                 $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->findOneForCustomer($orderId);
                 // Forget cart if cart is order
                 if ($cart && !$cart->hasCartStatus()) {
                     unset(\XLite\Core\Session::getInstance()->order_id, $cart);
                 }
             }
         }
         if (!isset($cart)) {
             // Cart not found - create a new instance
             $cart = new $className();
             $cart->initializeCart();
         }
         static::$instances[$className] = $cart;
         if ($auth->isLogged() && (!$cart->getProfile() || $auth->getProfile()->getProfileId() != $cart->getProfile()->getProfileId())) {
             $cart->setProfile($auth->getProfile());
             $cart->setOrigProfile($auth->getProfile());
         }
         // Check login state
         if (\XLite\Core\Session::getInstance()->lastLoginUnique === null && $cart->getProfile() && $cart->getProfile()->getAnonymous() && $cart->getProfile()->getLogin()) {
             $tmpProfile = new \XLite\Model\Profile();
             $tmpProfile->setProfileId(0);
             $tmpProfile->setLogin($cart->getProfile()->getLogin());
             $profile2 = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findUserWithSameLogin($tmpProfile);
             if ($profile2) {
                 \XLite\Core\Database::getEM()->detach($profile2);
             }
             \XLite\Core\Session::getInstance()->lastLoginUnique = !$profile2;
         }
         if (!$doCalculate) {
             $cart->setIgnoreLongCalculations();
         }
         if (!$cart->isIgnoreLongCalculations() && ($cart instanceof \XLite\Model\Cart || \XLite\Core\Converter::time() - static::RENEW_PERIOD > $cart->getLastRenewDate())) {
             $cart->renew();
         } else {
             $cart->calculate();
         }
         $cart->renewSoft();
         \XLite\Core\Session::getInstance()->order_id = $cart->getOrderId();
     }
     return static::$instances[$className];
 }
Esempio n. 7
0
/**
 * Create an administrator account
 *
 * @param array  $params     Database access data and other parameters
 * @param bool   $silentMode Do not display any output during installing
 *
 * @return bool
 */
function doCreateAdminAccount(&$params, $silentMode = false)
{
    global $error;
    $result = true;
    if ($silentMode) {
        ob_start();
    }
    $login = get_magic_quotes_gpc() ? trim(stripslashes($params['login'])) : $params['login'];
    $password = get_magic_quotes_gpc() ? trim(stripslashes($params["password"])) : $params["password"];
    if (empty($login) || empty($password)) {
        $result = false;
        $errorMsg = fatal_error(xtr('Login and password can\'t be empty.'), 'params', 'empty admin login or password');
    } else {
        $password = md5($password);
    }
    $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($login);
    if (is_null($profile)) {
        // Register default admin account
        $profile = new \XLite\Model\Profile();
        $profile->setLogin($login);
        echo xtr('Registering primary administrator profile...');
    } else {
        // Account already exists
        echo xtr('Updating primary administrator profile...');
    }
    // Add banner for Paypal express checkout on the admin dashboard
    if ('ru' !== XLITE_EDITION_LNG && class_exists('\\XLite\\Module\\CDev\\Paypal\\Main')) {
        $expressCheckout = \XLite\Module\CDev\Paypal\Main::getPaymentMethod(\XLite\Module\CDev\Paypal\Main::PP_METHOD_EC);
        $expressCheckout->setSetting('email', $login);
        $expressCheckout->setEnabled(true);
        \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'CDev\\Paypal', 'name' => 'show_admin_welcome', 'value' => 'Y'));
    }
    $profile->setPassword($password);
    $profile->setAccessLevel(100);
    $profile->enable();
    $role = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneRoot();
    $profile->addRoles($role);
    $profile->create();
    $role->addProfiles($profile);
    \XLite\Core\Database::getEM()->persist($role);
    \XLite\Core\Database::getEM()->flush();
    if ($silentMode) {
        ob_end_clean();
    }
    return $result;
}
Esempio n. 8
0
 /**
  * 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();
         }
     }
 }
Esempio n. 9
0
 /**
  * Get or create cart profile
  *
  * @return \XLite\Model\Profile
  */
 protected function getCartProfile()
 {
     $profile = $this->getCart()->getProfile();
     if (!$profile) {
         $profile = new \XLite\Model\Profile();
         $profile->setLogin('');
         $profile->setOrder($this->getCart());
         $profile->setAnonymous(true);
         $this->getCart()->setProfile($profile);
         $profile->create();
     }
     return $profile;
 }
Esempio n. 10
0
/**
 * Create an administrator account
 *
 * @param array  $params     Database access data and other parameters
 * @param bool   $silentMode Do not display any output during installing
 *
 * @return bool
 */
function doCreateAdminAccount(&$params, $silentMode = false)
{
    global $error;
    $result = true;
    if ($silentMode) {
        ob_start();
    }
    $login = get_magic_quotes_gpc() ? trim(stripslashes($params['login'])) : $params['login'];
    $password = get_magic_quotes_gpc() ? trim(stripslashes($params["password"])) : $params["password"];
    if (empty($login) || empty($password)) {
        $result = false;
        $errorMsg = fatal_error(xtr('Login and password can\'t be empty.'));
    } else {
        $password = md5($password);
    }
    $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($login);
    if (is_null($profile)) {
        // Register default admin account
        $profile = new \XLite\Model\Profile();
        $profile->setLogin($login);
        echo xtr('Registering primary administrator profile...');
    } else {
        // Account already exists
        echo xtr('Updating primary administrator profile...');
    }
    $profile->setPassword($password);
    $profile->setAccessLevel(100);
    $profile->enable();
    $role = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneByName('Administrator');
    $profile->addRoles($role);
    $profile->create();
    $role->addProfiles($profile);
    \XLite\Core\Database::getEM()->persist($role);
    \XLite\Core\Database::getEM()->flush();
    if ($silentMode) {
        ob_end_clean();
    }
    return $result;
}
Esempio n. 11
0
 /**
  * getTestProfile
  *
  * @param int $selectedProfileId
  * @param int $selectedAddressesId
  *
  * @return \XLite\Model\Profile
  * @access protected
  * @see    ____func_see____
  * @since  1.0.0
  */
 protected function getTestProfile($selectedProfileId = 0, $selectedAddressesId = 0)
 {
     $profile = new \XLite\Model\Profile();
     $profile->map($this->testProfileData[$selectedProfileId]);
     if (1 == $selectedProfileId) {
         $m = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->find(1);
         $profile->setMembership($m);
         $profile->setPendingMembership($m);
     }
     foreach ($this->testAddresses[$selectedAddressesId] as $data) {
         $address = new \XLite\Model\Address();
         $address->map($data);
         $address->setProfile($profile);
         $profile->addAddresses($address);
     }
     $result = $profile->create();
     $this->assertNotNull($profile, sprintf('Profile creation failed (%d, %d)', $selectedProfileId, $selectedAddressesId));
     return $profile;
 }
Esempio n. 12
0
 /**
  * Fetches an existing social login profile or creates new
  *
  * @param string $login          E-mail address
  * @param string $socialProvider SocialLogin auth provider
  * @param string $socialId       SocialLogin provider-unique id
  *
  * @return \XLite\Model\Profile
  */
 protected function getSocialLoginProfile($login, $socialProvider, $socialId)
 {
     $profile = \XLite\Core\Database::getRepo('\\XLite\\Model\\Profile')->findOneBy(array('socialLoginProvider' => $socialProvider, 'socialLoginId' => $socialId, 'order' => null));
     if (!$profile) {
         $profile = new \XLite\Model\Profile();
         $profile->setLogin($login);
         $profile->setSocialLoginProvider($socialProvider);
         $profile->setSocialLoginId($socialId);
         $existingProfile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $login, 'order' => null));
         if ($existingProfile) {
             $profile = null;
         } else {
             $profile->create();
         }
     }
     return $profile;
 }