예제 #1
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;
 }
예제 #2
0
파일: Order.php 프로젝트: kirkbauer2/kirkxc
 /**
  * Returns delivery source address
  *
  * @return \XLite\Model\Address
  */
 public function getSourceAddress()
 {
     if (null === $this->sourceAddress) {
         $address = new \XLite\Model\Address();
         $config = $this->getCompanyConfiguration();
         $address->setStreet($config->location_address);
         $address->setCity($config->location_city);
         $address->setCountryCode($config->location_country);
         if ($config->location_state) {
             $address->setStateId($config->location_state);
         }
         if ($config->location_custom_state) {
             $address->setCustomState($config->location_custom_state);
         }
         $address->setZipcode($config->location_zipcode);
         $this->sourceAddress = $address;
     }
     return $this->sourceAddress;
 }
예제 #3
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();
 }
예제 #4
0
 /**
  * Change shipping method
  * @todo: refactor (decompose)
  *
  * @return void
  */
 protected function doActionChangeMethod()
 {
     $methodId = \XLite\Core\Request::getInstance()->methodId;
     $cart = $this->getCart();
     if (null !== $methodId && $cart->getShippingId() != $methodId) {
         $cart->setLastShippingId($methodId);
         $cart->setShippingId($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'];
                 $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->find($c);
             } elseif (\XLite\Model\Address::getDefaultFieldValue('country')) {
                 $country = \XLite\Model\Address::getDefaultFieldValue('country');
             } else {
                 $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\Model\Address::getDefaultFieldValue('state')) {
                 $state = \XLite\Model\Address::getDefaultFieldValue('state');
             }
             if ($state) {
                 $address->setState($state);
             }
             // Zip code
             if (\XLite\Model\Address::getDefaultFieldValue('zipcode')) {
                 $address->setZipcode(\XLite\Model\Address::getDefaultFieldValue('zipcode'));
             }
             $address->setProfile($profile);
             $address->setIsShipping(true);
             $profile->addAddresses($address);
             \XLite\Core\Database::getEM()->persist($address);
         }
         $this->updateCart();
     }
     $this->valid = true;
     $this->setSilenceClose();
 }