/** * Singleton method * * @param null * @return MageBridgeConnectorProduct */ public static function getInstance() { static $instance; if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
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); }
public function display($tpl = null) { // Initialize the view $this->setTitle('Edit product relation'); // Initialize common variables $application = JFactory::getApplication(); $user = JFactory::getUser(); $option = JRequest::getCmd('option'); // Get data from the model $model = $this->getModel(); $item = $this->get('Data'); // Get the item $item = $this->get('data'); $isNew = $item->id < 1; // Fail if checked out not by 'me' if ($model->isCheckedOut($user->get('id'))) { $msg = JText::sprintf('Item locked', $item->name); $application->redirect('index.php?option=' . $option, $msg); } // Edit or Create? if (!$isNew) { $model->checkout($user->get('id')); } else { // initialise new record $item->published = 1; $item->order = 0; } // Initialize parameters $file = JPATH_ADMINISTRATOR . '/components/com_magebridge/models/product.xml'; $params = new JParameter($item->params, $file); // Build the HTML-select list for ordering $query = 'SELECT ordering AS value, label AS text' . ' FROM #__magebridge_products' . ' ORDER BY ordering'; // Build the fields $fields = array(); $fields['product'] = $this->getFieldProduct($item->sku); $fields['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query); $fields['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published); // Clean the object before displaying JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'text'); $this->assignRef('user', JFactory::getUser()); $this->assignRef('connectors', MageBridgeConnectorProduct::getInstance()->getConnectors()); $this->assignRef('fields', $fields); $this->assignRef('params', $params); $this->assignRef('item', $item); parent::display($tpl); }
/** * Handle the event that is generated after an order is completed in Magento (RPC) * * @param array $arguments * * @return bool */ public function mageSalesOrderCompleteAfter($arguments = array()) { // Fetch the arguments $products = $arguments['order']['products']; $customer = $arguments['order']['customer']; $state = $arguments['order']['state']; // Don't continue if this is a guest-only order if (!isset($customer['email'])) { return false; } // Load the corresponding Joomla! user $user = $this->getUser()->loadByEmail($customer['email']); // Loop through the products and run the product connector foreach ($products as $product) { $productQty = isset($product['qty']) ? $product['qty'] : 1; if ($productQty < 1) { $productQty = 1; } MageBridgeConnectorProduct::getInstance()->runOnPurchase($product['sku'], $productQty, $user, $state, $arguments); } return true; }
/** * Method to store the item * * @package MageBridge * @access public * @param array $data * @return bool */ public function store($data) { $row = $this->getTable(); if (empty($data['sku'])) { $this->setError(JText::_('No product was selected')); return false; } if (empty($data['connector'])) { $this->setError(JText::_('No connector was selected')); return false; } $connector = MageBridgeConnectorProduct::getConnector($data['connector']); if ($connector == false) { $this->setError(JText::_('Failed to load connector')); return false; } $data['connector_value'] = $connector->getFormPost($data); if (empty($data['label'])) { $data['label'] = $data['sku']; } // Bind the form fields to the item table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } // Make sure the item table is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Product the item table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Save the ID for later usage $this->_id = $row->id; return true; }
/** * Method to simulate a product purchase * * @param null * * @return null */ public function check_product() { // Validate whether this task is allowed if ($this->_validate() == false) { return false; } // POST values $user_id = $this->_app->input->getInt('user_id'); $product_sku = $this->_app->input->getString('product_sku'); $count = $this->_app->input->getInt('count'); $status = $this->_app->input->getCmd('order_status'); // Validation checks if (!$user_id > 0) { $msgType = 'error'; $msg = JText::_('COM_MAGEBRIDGE_CHECK_PRODUCT_POST_ERROR_NO_USER'); } elseif (empty($product_sku)) { $msgType = 'error'; $msg = JText::_('COM_MAGEBRIDGE_CHECK_PRODUCT_POST_ERROR_NO_PRODUCT'); } else { $user = JFactory::getUser($user_id); MageBridgeConnectorProduct::getInstance()->runOnPurchase($product_sku, $count, $user, $status); $msgType = null; $msg = JText::_('COM_MAGEBRIDGE_CHECK_PRODUCT_POST_SUCCESS'); } $link = 'index.php?option=com_magebridge&view=check&layout=product'; $this->setRedirect($link, $msg, $msgType); }