/** * Link XLite and CMS profiles * * @param \XLite\Model\Profile $profile XLite profile * @param integer $cmsProfileId CMS profile id * * @return void */ public function linkProfiles(\XLite\Model\Profile $profile, $cmsProfileId) { $profile->setCMSProfileId($cmsProfileId); $profile->setCMSName(\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->getCMSName()); $this->defineUnlinkProfilesQuery($cmsProfileId)->execute(); $this->defineLinkProfilesQuery($profile->getProfileId(), $cmsProfileId)->execute(); }
/** * Define query for findAllOrdersWithEgoods() method * * @param \XLite\Model\Profile $profile Profile OPTIONAL * * @return \XLite\Model\QuieryBuilder\AQueryBuilder */ protected function defineFindAllOrdersWithEgoodsQuery(\XLite\Model\Profile $profile = null) { $qb = $this->createQueryBuilder('o')->innerJoin('o.items', 'item')->innerJoin('item.privateAttachments', 'pa')->leftJoin('o.orig_profile', 'op')->orderBy('o.date', 'desc'); if ($profile) { $qb->andWhere('op.profile_id = :opid')->setParameter('opid', $profile->getProfileId()); } return $qb; }
/** * {@inheritDoc} */ public function prepareEntityBeforeCommit($type) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type)); return parent::prepareEntityBeforeCommit($type); }
/** * Prepare query for countItemsPurchasedByCustomer() method * * @param integer $productId Product Id * @param \XLite\Model\Profile $profile Customer profile * * @return \Doctrine\ORM\QueryBuilder */ protected function defineCountItemsPurchasedByCustomer($productId, $profile) { $qb = $this->createQueryBuilder('i'); $qb->select('COUNT(i.item_id)')->innerJoin('i.object', 'p')->innerJoin('i.order', 'o')->innerJoin('o.orig_profile', 'profile')->innerJoin('o.paymentStatus', 'ps')->andWhere('p.product_id = :productId')->andWhere('profile.profile_id = :profileId')->andWhere($qb->expr()->in('ps.code', \XLite\Model\Order\Status\Payment::getPaidStatuses()))->setParameter('productId', $productId)->setParameter('profileId', $profile->getProfileId()); return $qb; }
/** * User can access profile only in two cases: * 1) he/she is an admin * 2) its the user's own account * * @param \XLite\Model\Profile $profile Profile to check * * @return boolean */ protected function checkProfileAccessibility(\XLite\Model\Profile $profile) { return $this->isAdmin($this->getProfile()) || $this->getProfile()->getProfileId() == $profile->getProfileId(); }
/** * Update profile role * * @param \XLite\Model\Profile $profile Profile * * @return void */ protected function updateProfileRole(\XLite\Model\Profile $profile) { $rootRole = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneRoot(); if (\XLite\Core\Auth::getInstance()->getAdminAccessLevel() == $profile->getAccessLevel()) { // Add root role if ($rootRole && !$profile->getRoles()->contains($rootRole)) { $profile->addRoles($rootRole); $rootRole->addProfiles($profile); } } else { // Remove root role if ($rootRole && $profile->getRoles()->contains($rootRole)) { $profile->getRoles()->removeElement($rootRole); $rootRole->getProfiles()->removeElement($profile); } } \XLite\Core\Database::getEM()->flush(); }
/** * Merge profile with another profile * * @param \XLite\Model\Profile $profile Profile * @param integer $flag Peration flag OPTIONAL * * @return integer */ public function mergeWithProfile(\XLite\Model\Profile $profile, $flag = self::MERGE_ALL) { $result = 0; // Addresses if ($flag & static::MERGE_ADDRESSES) { foreach ($profile->getAddresses() as $address) { $found = false; foreach ($this->getAddresses() as $a) { if ($a->isEqualAddress($address)) { $found = true; break; } } if (!$found) { $address = $address->cloneEntity(); $this->addAddresses($address); $address->setProfile($this); } } $result |= static::MERGE_ADDRESSES; } // Orders if ($flag & static::MERGE_ORDERS) { $cnd = new \XLite\Core\CommonCell(); $cnd->profile = $profile; foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Order')->search($cnd) as $order) { $order->setOrigProfile($this); } $result |= static::MERGE_ORDERS; } return $result; }
/** * Prepare certain search condition * * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare * @param \XLite\Model\Profile $value Profile * * @return void */ protected function prepareCndProfile(\Doctrine\ORM\QueryBuilder $queryBuilder, \XLite\Model\Profile $value) { if (!empty($value)) { $queryBuilder->andWhere('op.profile_id = :opid')->setParameter('opid', $value->getProfileId()); } }
/** * Set original profile * FIXME: is it really needed? * * @param \XLite\Model\Profile $profile Profile OPTIONAL * * @return void */ public function setOrigProfile(\XLite\Model\Profile $profile = null) { if ($this->getOrigProfile() && $this->getOrigProfile()->getOrder() && (!$profile || $this->getOrigProfile()->getProfileId() != $profile->getProfileId()) && (!$this->getProfile() || $this->getOrigProfile()->getProfileId() != $this->getProfile()->getProfileId())) { $this->getOrigProfile()->setOrder(null); } $this->orig_profile = $profile; }
/** * Get XML block: returner (sender) address * * @param \XLite\Model\Profile $profile Returner profile * * @return string */ protected function getXmlBlockReturnerAddress(\XLite\Model\Profile $profile) { $address = $profile->getShippingAddress(); $addressZipcode = preg_replace('/\\s+/', '', $address->getZipcode()); $xmlData = <<<XML <returner> <name>{$address->getFirstname()} {$address->getLastname()}</name> <domestic-address> <address-line-1>{$address->getStreet()}</address-line-1> <city>{$address->getCity()}</city> <province>{$address->getState()->getCode()}</province> <postal-code>{$addressZipcode}</postal-code> </domestic-address> </returner> XML; return $xmlData; }
/** * Define query for findOneAnonymousByProfile() method * * @param \XLite\Model\Profile $profile Profile * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ protected function defineFindOneAnonymousByProfileQuery(\XLite\Model\Profile $profile) { return $this->createQueryBuilder()->bindAnonymous()->bindAndCondition('p.login', $profile->getLogin()); }
/** * Send notification about updated profile to the user * * @param \XLite\Model\Profile $profile Profile object * @param string $password Profile password OPTIONAL * * @return void */ public static function sendProfileUpdatedCustomer(\XLite\Model\Profile $profile, $password = null) { $interface = $profile->isAdmin() ? \XLite::ADMIN_SELF : \XLite::CART_SELF; $url = \XLite::getInstance()->getShopURL(\XLite\Core\Converter::buildURL('login', '', array(), $interface)); static::register(array('profile' => $profile, 'password' => $password, 'url' => $url)); static::compose(static::TYPE_PROFILE_UPDATED_CUSTOMER, static::getSiteAdministratorMail(), $profile->getLogin(), 'profile_modified', array(), true, \XLite::CUSTOMER_INTERFACE, static::getMailer()->getLanguageCode(\XLite::CUSTOMER_INTERFACE, $profile->getLanguage())); }
/** * Cleanup pending zero-auth data from profile * * @return void */ protected function cleanupZeroAuthPendingData(\XLite\Model\Profile $profile) { $profile->setPendingZeroAuthTxnId(''); $profile->setPendingZeroAuth(''); $profile->setPendingZeroAuthInterface(''); \XLite\Core\Database::getEM()->flush(); }
/** * Import address * * @param \XLite\Model\Profile $model Profile * @param array $address Address * @param integer $index Index * * @return void */ protected function importAddress(\XLite\Model\Profile $model, array $address, $index) { $addr = $model->getAddresses()->get($index); if (!$addr) { $addr = $this->createAddress(); $model->addAddresses($addr); $addr->setProfile($model); } if (isset($address['is_shipping'])) { $address['is_shipping'] = $this->normalizeValueAsBoolean($address['is_shipping']); } if (isset($address['is_billing'])) { $address['is_billing'] = $this->normalizeValueAsBoolean($address['is_billing']); } if (isset($address['state'])) { $address['state'] = $this->normalizeValueAsState($address['state']); } $this->updateAddress($addr, $address); }
/** * Bind only profiles with same login * * @param \XLite\Model\Profile $profile Profile * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ public function bindSameLogin(\XLite\Model\Profile $profile) { return $this->andWhere('p.login = :login')->andWhere('p.profile_id != :profileId')->setParameter('login', $profile->getLogin())->setParameter('profileId', $profile->getProfileId() ?: 0); }
/** * Get "destination" XML data for "Create Non-Contract Shipment" and "Create Shipment" requests * * @param \XLite\Model\Profile $profile Customer profile * * @return string */ protected function getDestinationXmlData(\XLite\Model\Profile $profile) { $destLocation = $profile->getShippingAddress(); $destLocationZipcode = static::strToUpper(preg_replace('/\\s+/', '', $destLocation->getZipcode())); $xmlData = <<<XML <destination> <name>{$destLocation->getFirstname()} {$destLocation->getLastname()}</name> <client-voice-number>{$destLocation->getPhone()}</client-voice-number> <address-details> <address-line-1>{$destLocation->getStreet()}</address-line-1> <city>{$destLocation->getCity()}</city> <prov-state>{$destLocation->getState()->getCode()}</prov-state> <country-code>{$destLocation->getCountry()->getCode()}</country-code> <postal-zip-code>{$destLocationZipcode}</postal-zip-code> </address-details> </destination> XML; return $xmlData; }
/** * Format language for request ("language_country"="en_EN") * * @param \XLite\Model\Profile $profile Profile model * * @return string */ protected function getFormattedLanguage($profile) { return \XLite\Core\Session::getInstance()->getLanguage()->getCode() . '_' . strtoupper($profile->getBillingAddress()->getCountry()->getCode()); }
/** * Preprocess profile * * @param \XLite\Model\Profile $profile Profile * @param array $column Column data * @param \XLite\Model\Order $entity Order * * @return string */ protected function preprocessProfile(\XLite\Model\Profile $profile, array $column, \XLite\Model\Order $entity) { $address = $profile->getBillingAddress() ?: $profile->getShippingAddress(); return $address ? $address->getName() : $profile->getLogin(); }
/** * Preprocess access level * * @param integer $accessLevel Access level * @param array $column Column data * @param \XLite\Model\Profile $entity Profile * * @return string */ protected function preprocessAccessLevel($accessLevel, array $column, \XLite\Model\Profile $entity) { if (0 == $accessLevel) { $result = $entity->getAnonymous() ? static::t('Anonymous') : static::t('Customer'); if ($entity->getMembership() || $entity->getPendingMembership()) { $result .= ' ('; } if ($entity->getMembership()) { $result .= $entity->getMembership()->getName(); } if ($entity->getPendingMembership()) { if ($entity->getMembership()) { $result .= ', '; } $result .= static::t('requested for') . ' ' . $entity->getPendingMembership()->getName(); } if ($entity->getMembership() || $entity->getPendingMembership()) { $result .= ')'; } } else { $result = static::t('Administrator'); } return $result; }
/** * Allow to suppress 'email already exists...' message in some cases (e.g. in user sync process) * * @return void */ protected function addErrorEmailExists() { if (!defined('LC_SUPPRESS_EMAIL_ALREADY_EXISTS_MESSAGE')) { parent::addErrorEmailExists(); } }
/** * Prepare address data * * @param \XLite\Model\Profile $profile Customer's profile * @param $type Address type, billing or shipping * * @return array */ protected function prepareAddress(\XLite\Model\Profile $profile, $type = 'billing') { $result = array(); $addressFields = array('firstname' => 'N/A', 'lastname' => '', 'address' => 'N/A', 'city' => 'N/A', 'state' => 'N/A', 'country' => 'N/A', 'zipcode' => 'N/A', 'phone' => '', 'fax' => '', 'company' => ''); $repo = \XLite\Core\Database::getRepo('\\XLite\\Model\\AddressField'); $type = $type . 'Address'; foreach ($addressFields as $field => $defValue) { $method = 'address' == $field ? 'street' : $field; $address = $profile->{$type}; if ($address && ($repo->findOneBy(array('serviceName' => $method)) || method_exists($address, 'get' . $method)) && $address->{$method}) { $result[$field] = is_object($profile->{$type}->{$method}) ? $profile->{$type}->{$method}->getCode() : $profile->{$type}->{$method}; } if (empty($result[$field])) { $result[$field] = $defValue; } } $result['email'] = $profile->getLogin(); return $result; }
/** * Check - need set root access or not * * @param \XLite\Model\Profile $profile Profile * * @return boolean */ protected function needSetRootAccess(\XLite\Model\Profile $profile) { $onlyOneRootAdmin = false; if ($profile->getProfileId()) { $cnd = new \XLite\Core\CommonCell(); $cnd->permissions = \XLite\Model\Role\Permission::ROOT_ACCESS; $i = 0; foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Profile')->search($cnd) as $p) { $i++; if ($profile->getProfileId() == $p->getProfileId()) { $onlyOneRootAdmin = true; } } if (1 < $i) { $onlyOneRootAdmin = false; } } return 1 == \XLite\Core\Database::getRepo('XLite\\Model\\Role')->count() || $onlyOneRootAdmin; }
/** * Define query for findUserWithSameLogin() method * * @param \XLite\Model\Profile $profile Profile object * * @return \Doctrine\ORM\QueryBuilder */ protected function defineFindUserWithSameLoginQuery(\XLite\Model\Profile $profile) { $queryBuilder = $this->createQueryBuilder()->andWhere('p.login = :login')->andWhere('p.profile_id != :profileId')->setParameter('login', $profile->getLogin())->setParameter('profileId', $profile->getProfileId() ?: 0)->setMaxResults(1); if ($profile->getOrder()) { $queryBuilder->innerJoin('p.order', 'porder')->andWhere('porder.order_id = :orderId')->setParameter('orderId', $profile->getOrder()->getOrderId()); } else { $queryBuilder->andWhere('p.order is null'); } return $queryBuilder; }