Пример #1
0
 /**
  * Load the WP User associated with the current logged in Customer
  *
  * @param Fishpig_Wordpress_Model_User $user
  * @return bool
  */
 public function loadCurrentLoggedInUser(Fishpig_Wordpress_Model_User $user)
 {
     $session = Mage::getSingleton('customer/session');
     if ($session->isLoggedIn()) {
         $user->loadByEmail($session->getCustomer()->getEmail());
         return $user->getId() > 0 ? true : false;
     }
     return false;
 }
 /**
  * Push a WordPress user model to Magento
  *
  * @param Fishpig_Wordpress_Model_User $user
  * @return bool
  */
 public function synchroniseUser(Fishpig_Wordpress_Model_User $user)
 {
     $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsite()->getId())->loadByEmail($user->getUserEmail());
     if (!$customer->getId() && !$user->getMagentoPassword()) {
         return false;
     }
     $customer->setEmail($user->getUserEmail())->setFirstname($user->getFirstName())->setLastname($user->getLastName())->setStoreId(Mage::app()->getStore()->getId());
     if ($user->getMagentoPassword()) {
         $customer->setPassword($user->getMagentoPassword());
     }
     try {
         $customer->save();
         $customer->setWordpressUser($user);
     } catch (Exception $e) {
         Mage::helper('wordpress')->log($e);
     }
     return false;
 }