public function display($tpl = null) { // Initialize the view $this->setTitle('Connectors'); // Set buttons in the toolbar MageBridgeToolBarHelper::help('magebridge.connectors'); JToolBarHelper::publishList(); JToolBarHelper::unpublishList(); JToolBarHelper::editListX(); // Initialize common variables $application = JFactory::getApplication(); $option = JRequest::getCmd('option') . '-connectors'; // Handle the filters $filter_type = $application->getUserStateFromRequest($option . 'filter_type', 'filter_type', '', 'word'); $filter_state = $application->getUserStateFromRequest($option . 'filter_state', 'filter_state', '', 'word'); $filter_order = $application->getUserStateFromRequest($option . 'filter_order', 'filter_order', 'p.ordering', 'cmd'); $filter_order_Dir = $application->getUserStateFromRequest($option . 'filter_order_Dir', 'filter_order_Dir', '', 'word'); // Get data from the model $items = $this->get('Data'); $total = $this->get('Total'); $pagination = $this->get('Pagination'); // filters $options = array(array('value' => '', 'text' => '- Select Type -'), array('value' => 'store', 'text' => 'Store Connectors'), array('value' => 'product', 'text' => 'Product Connectors'), array('value' => 'profile', 'text' => 'Profile Connectors')); $javascript = 'onchange="document.adminForm.submit();"'; $lists['type'] = JHTML::_('select.genericlist', $options, 'filter_type', $javascript, 'value', 'text', $filter_type); $lists['state'] = JHTML::_('grid.state', $filter_state); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // Prepare the items for display if (!empty($items)) { foreach ($items as $index => $item) { if ($item->type == 'product') { $object = MageBridgeConnectorProduct::getInstance()->getConnectorObject($item); } else { if ($item->type == 'profile') { $object = MageBridgeConnectorProfile::getInstance()->getConnectorObject($item); } else { $object = MageBridgeConnectorStore::getInstance()->getConnectorObject($item); } } if (is_object($object)) { $item->enabled = $object->isEnabled(); } else { $item->enabled = false; } $item->edit_link = 'index.php?option=com_magebridge&view=connector&task=edit&cid[]=' . $item->id; $items[$index] = $item; } } $user = JFactory::getUser(); $this->assignRef('user', $user); $this->assignRef('lists', $lists); $this->assignRef('items', $items); $this->assignRef('pagination', $pagination); parent::display($tpl); }
/** * Method to synchronize the user account with Magento * * @param array $user * @return array $data Data as returned by Magento */ public function synchronize($user) { // Disable at user events if (isset($user['disable_events']) && $user['disable_events'] == 1) { return null; } MageBridgeModelDebug::getInstance()->notice("MageBridgeModelUser::synchronize() on user " . $user['email']); // Use the email if no username is set if (empty($user['username'])) { $user['username'] = $user['email']; } // Check on the users email if ($this->isValidEmail($user['email']) == false) { return false; } // Set the right ID $user['joomla_id'] = isset($user['id']) ? $user['id'] : 0; // Find some logic to divide the "name" into a "firstname" and "lastname" $user = MageBridgeUserHelper::convert($user); // Only set the password, when the password does not appear to be the encrypted version if (empty($user['password_clear'])) { if (isset($user['password']) && !preg_match('/^\\$/', $user['password']) && !preg_match('/^\\{SHA256\\}/', $user['password']) && !preg_match('/([a-z0-9]{32}):([a-zA-Z0-9]+)/', $user['password'])) { $user['password_clear'] = $user['password']; } } // Try to detect the password in this POST if (empty($user['password_clear'])) { $fields = array('password_clear', 'password', 'passwd'); $jform = JFactory::getApplication()->input->get('jform', array(), 'post'); foreach ($fields as $field) { $password = JFactory::getApplication()->input->getString($field, '', 'post'); if (empty($password) && is_array($jform) && !empty($jform[$field])) { $password = $jform[$field]; } if (!empty($password)) { $user['password_clear'] = $password; break; } } } // Delete unusable fields unset($user['id']); unset($user['password']); unset($user['params']); unset($user['userType']); unset($user['sendEmail']); unset($user['option']); unset($user['task']); // Delete unusable empty fields foreach ($user as $name => $value) { if (empty($value)) { unset($user[$name]); } } // Encrypt the user-password for transfer through the MageBridge API if (isset($user['password_clear'])) { if (empty($user['password_clear']) || !is_string($user['password_clear'])) { unset($user['password_clear']); } else { $user['password_clear'] = MageBridgeEncryptionHelper::encrypt($user['password_clear']); } } // Add the Website ID to this user $user['website_id'] = MagebridgeModelConfig::load('website'); // Add the default customer-group ID to this user (in case we need to create a new user) $user['default_customer_group'] = MagebridgeModelConfig::load('customer_group'); // Add the customer-group ID to this user (based upon groups configured in #__magebridge_usergroups) $user['customer_group'] = MageBridgeUserHelper::getMagentoGroupId($user); // Make sure events are disabled on the Magento side $user['disable_events'] = 1; // Add the profile-connector data to this user $user = MageBridgeConnectorProfile::getInstance()->modifyUserFields($user); // Initalize the needed objects $bridge = MageBridgeModelBridge::getInstance(); $register = MageBridgeModelRegister::getInstance(); // Build the bridge and fetch the result $id = $register->add('api', 'magebridge_user.save', $user); $bridge->build(); $data = $register->getDataById($id); return $data; }