/** * Event onAfterInitialise */ public function onAfterInitialise() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Perform actions on the frontend $application = JFactory::getApplication(); // Check for postlogin-cookie if (isset($_COOKIE['mb_postlogin']) && !empty($_COOKIE['mb_postlogin'])) { // If the user is already logged in, remove the cookie if (JFactory::getUser()->id > 0) { setcookie('mb_postlogin', '', time() - 3600, '/', '.' . JURI::getInstance()->toString(array('host'))); } // Otherwise decrypt the cookie and use it here $data = MageBridgeEncryptionHelper::decrypt($_COOKIE['mb_postlogin']); if (!empty($data)) { $customer_email = $data; } } // Perform a postlogin if needed $post = $application->input->post->getArray(); if (empty($post)) { $postlogin_userevents = $this->params->get('postlogin_userevents', 0) == 1 ? true : false; if (empty($customer_email)) { $customer_email = MageBridgeModelBridge::getInstance()->getSessionData('customer/email'); } if (!empty($customer_email)) { MageBridge::getUser()->postlogin($customer_email, null, $postlogin_userevents); } } }
/** * Helper-method to determine whether an user is a backend user * * @param mixed $user User object or identifier * @param string $type Either object, email or username * @return boolean */ public static function isBackendUser($user = null, $type = 'object') { // Check for empty user if (empty($user)) { return false; } // Get the right instance if ($user instanceof JUser == false) { if ($type == 'email') { $user = MageBridge::getUser()->loadByEmail($user); } if ($type == 'username') { $user = MageBridge::getUser()->loadByUsername($user); } } // Check the legacy usertype parameter if (!empty($user->usertype) && (stristr($user->usertype, 'administrator') || stristr($user->usertype, 'manager'))) { return false; } // Check for ACL access if (method_exists($user, 'authorise') && $user->authorise('core.admin')) { return true; } return false; }
/** * Method to make login an user */ public function login() { // Fetch the user-email $user_email = MageBridgeEncryptionHelper::decrypt(JFactory::getApplication()->input->getString('token')); $application = JFactory::getApplication(); // Perform a post-login $rt = MageBridge::getUser()->postlogin($user_email, null, true); // Determine the redirect URL $redirectUrl = base64_decode(JFactory::getApplication()->input->getString('redirect')); if (empty($redirectUrl)) { $redirectUrl = MageBridgeModelBridge::getMagentoUrl(); } // Redirect $application->redirect($redirectUrl); $application->close(); }
/** * Return the MageBridge user-object * * @access private * @param string $name * @return mixed $value */ private function getUser() { return MageBridge::getUser(); }
/** * Method to execute when the profile is saved * * @param int $user_id * @return bool */ public function synchronize($user_id = 0) { // Exit if there is no user_id if (empty($user_id)) { return false; } // Get a general user-array from Joomla! itself $db = JFactory::getDBO(); $query = "SELECT `name`,`username`,`email` FROM `#__users` WHERE `id`=" . (int) $user_id; $db->setQuery($query); $user = $db->loadAssoc(); // Exit if this is giving us no result if (empty($user)) { return false; } // Sync this user-record with the bridge MageBridgeModelDebug::getInstance()->trace('Synchronizing user', $user); MageBridge::getUser()->synchronize($user); $session = JFactory::getSession(); $session->set('com_magebridge.task_queue', array()); return true; }
/** * Handle the event that is generated after a customer logs in (passed into the bridge-response) * * @param array $arguments * * @return bool */ public function mageCustomerLoginAfter($arguments = array()) { // Abort if the input is invalid if (empty($arguments) || empty($arguments['customer']['email'])) { return false; } // Joomla! expects more parameters, so we need to fetch those first $customer = $arguments['customer']; $user = $this->getUser()->loadByEmail($customer['email']); // We had a succesfull login in Magento, but the user does not exist in Joomla! yet if (empty($user)) { $customer['username'] = $customer['email']; $customer['fullname'] = $customer['name']; $this->getUser()->create($customer, true); $user = $this->getUser()->loadByEmail($customer['email']); } else { $customer['fullname'] = $user->get('name'); $customer['email'] = $user->get('email'); $customer['username'] = $user->get('username'); } // Check for the right user-ID if ($user->id > 0) { $customer['id'] = $user->id; } else { return false; } // Do a post-login MageBridge::getUser()->postlogin(null, $user->id, false); return true; }
/** * Helper method to sync the user * * @access private * @param object JUser * @return bool */ private function syncUser($user = null) { // Check if we can run this event or not if (MageBridgePluginHelper::allowEvent('onUserDetailsUpdate') == false) { return; } // Copy the username to the email address if (JFactory::getApplication()->isSite() == true && $this->getUserParams()->get('username_from_email', 1) == 1 && $user->username != $user->email) { if ($this->getUser()->allowSynchronization($user, 'save') == true) { MageBridgeModelDebug::getInstance()->notice("onUserDetailsUpdate::bind on user " . $user->username); // Change the record in the database $user->email = $user->username; $user->save(); } } // Synchronize this user-record with Magento if ($this->getUserParams()->get('user_sync', 1) == 1) { MageBridgeModelDebug::getInstance()->notice("onUserDetailsUpdate::usersync on user " . $user->username); // Convert this object to an array if (!is_array($user)) { jimport('joomla.utilities.arrayhelper'); $user = JArrayHelper::fromObject($user, false); } // Sync this user-record with the bridge MageBridge::getUser()->synchronize($user); } return true; }
/** * Perform a delayed login * * @access private * @param null * @return null */ private function doDelayedLogin() { $bridge = MageBridge::getBridge(); $user_email = $bridge->getMageConfig('customer/email'); $user_id = $bridge->getMageConfig('customer/joomla_id'); return MageBridge::getUser()->postlogin($user_email, $user_id); }
public function runOnPurchase($sku = null, $qty = 1, $user = null, $status = null, $arguments = null) { // Get the conditions $conditions = $this->getConditions($sku); if (empty($conditions)) { return null; } // Foreach of these conditions, run the appropriate connector method foreach ($conditions as $condition) { $connector = $this->getConnector($condition->connector); if (!empty($condition->connector_value) && !empty($connector)) { if (!empty($condition->params)) { jimport('joomla.html.parameter'); $params = new JParameter($condition->params); $only_completed = $params->get('only_completed', false); $expire_amount = $params->get('expire_amount', 0); $expire_unit = $params->get('expire_unit', 'day'); } else { $only_completed = false; $expire_amount = 0; $expire_unit = null; } // Do not continue if we are only supposed to run on completed orders if ($status != 'complete' && $only_completed == true) { continue; } // Try to call the connector-method $rt = false; if (method_exists($connector, 'onPurchase')) { try { if ($qty < 1) { $qty = 1; } for ($i = 0; $i < $qty; $i++) { $rt = $connector->onPurchase($condition->connector_value, $user, $status); } } catch (Exception $e) { MageBridgeModelDebug::getInstance()->trace('Product Connector failed', $e->getMessage()); } $this->saveLog($user->id, $sku, $expire_unit, $expire_amount); } // If this result is false (read: an error), do not continue with other product relations //if ($rt == false) break; } } // Refresh the user session, just in case MageBridge::getUser()->updateSession(JFactory::getUser()); }
/** * Event onAfterInitialise * * @access public * @param null * @return null */ public function onAfterInitialise() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Perform actions on the frontend $application = JFactory::getApplication(); if ($application->isSite()) { // Import the custom module helper - this is needed to make it possible to flush certain positions if ($this->getParam('override_modulehelper', 1) == 1 && class_exists('JModuleHelper') == false) { $component_path = JPATH_SITE . '/components/com_magebridge/'; if (MageBridgeHelper::isJoomla15()) { @(include_once $component_path . 'rewrite/joomla/application/module/helper.php'); } else { if (MageBridgeHelper::isJoomla16()) { @(include_once $component_path . 'rewrite-16/joomla/application/module/helper.php'); } else { if (MageBridgeHelper::isJoomla17()) { @(include_once $component_path . 'rewrite-17/joomla/application/module/helper.php'); } else { @(include_once $component_path . 'rewrite-25/joomla/application/module/helper.php'); } } } } } // Check for postlogin-cookie if (isset($_COOKIE['mb_postlogin']) && !empty($_COOKIE['mb_postlogin'])) { // If the user is already logged in, remove the cookie if (JFactory::getUser()->id > 0) { setcookie('mb_postlogin', '', time() - 3600, '/', '.' . JURI::getInstance()->toString(array('host'))); } // Otherwise decrypt the cookie and use it here $data = MageBridgeEncryptionHelper::decrypt($_COOKIE['mb_postlogin']); if (!empty($data)) { $customer_email = $data; } } // Perform a postlogin if needed $post = JRequest::get('post'); if (empty($post)) { $postlogin_userevents = $this->getParams()->get('postlogin_userevents', 0) == 1 ? true : false; if (empty($customer_email)) { $customer_email = MageBridgeModelBridge::getInstance()->getMageConfig('customer/email'); } if (!empty($customer_email)) { MageBridge::getUser()->postlogin($customer_email, null, $postlogin_userevents); } } }