示例#1
0
 /**
  * Adds an item to a User's Product Compare
  * whether in the session or the db
  *
  */
 function addProductToCompare()
 {
     // saving the session id which will use to update the cart
     $session = JFactory::getSession();
     $userid = JFactory::getUser()->id;
     // After login, session_id is changed by Joomla, so store this for reference
     $session->set('old_sessionid', $session->getId());
     $response = array();
     $response['msg'] = '';
     $response['error'] = '';
     $product_id = JRequest::getVar('product_id');
     $add = JRequest::getVar('add', 1);
     //deleting product to compare
     if (!$add) {
         $db = JFactory::getDBO();
         Tienda::load('TiendaQuery', 'library.query');
         $query = new TiendaQuery();
         $query->delete();
         $query->from("#__tienda_productcompare");
         $query->where("`product_id` = '{$product_id}' ");
         $query->where("`session_id` = '" . $session->getId() . "' ");
         $query->where("`user_id` = '{$userid}'");
         $db->setQuery((string) $query);
         if (!$db->query()) {
             $response['msg'] = $helper->generateMessage($db->getErrorMsg());
             $response['error'] = '1';
             return false;
         }
     } else {
         Tienda::load('TiendaHelperProductCompare', 'helpers.productcompare');
         $compare_helper = new TiendaHelperProductCompare();
         //check limit
         $compareLimit = $compare_helper->checkLimit();
         if (!$compareLimit) {
             Tienda::load('TiendaHelperBase', 'helpers._base');
             $helper = TiendaHelperBase::getInstance();
             $limit = Tienda::getInstance()->get('compared_products', '5');
             $response['msg'] = $helper->generateMessage(JText::sprintf("COM_TIENDA_ONLY_N_PRODUCTS_CAN_BE_ADDED_TO_COMPARE", $limit));
             $response['error'] = '1';
             echo json_encode($response);
             return;
         }
         // create cart object out of item properties
         $item = new JObject();
         $item->user_id = $userid;
         $item->product_id = (int) $product_id;
         // add the item to the product comparison
         $compare_item = $compare_helper->addItem($item);
     }
     //load user compared items
     $model = $this->getModel($this->get('suffix'));
     $model->setState('filter_user', $userid);
     if (empty($user->id)) {
         $model->setState('filter_session', $session->getId());
     }
     $items = $model->getList();
     //TODO: make it to call a view
     $response['msg'] .= '<ul>';
     foreach ($items as $item) {
         $table = JTable::getInstance('Products', 'TiendaTable');
         $table->load(array('product_id' => $item->product_id));
         $response['msg'] .= '<li>';
         $response['msg'] .= '<a href="' . JRoute::_('index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id) . '">';
         $response['msg'] .= $table->product_name;
         $response['msg'] .= '</a>';
         $response['msg'] .= '</li>';
     }
     $response['msg'] .= '</ul>';
     echo json_encode($response);
     return;
 }
示例#2
0
 /**
  * Displays a product category
  *
  * (non-PHPdoc)
  * @see tienda/admin/TiendaController#display($cachable)
  */
 function display($cachable = false, $urlparams = false)
 {
     JRequest::setVar('view', $this->get('suffix'));
     JRequest::setVar('search', false);
     $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType());
     $model = $this->getModel($this->get('suffix'));
     $state = $this->_setModelState();
     $session = JFactory::getSession();
     $app = JFactory::getApplication();
     $ns = $app->getName() . '::' . 'com.tienda.products.state.' . $this->itemid;
     $session->set($ns, $state);
     $app = JFactory::getApplication();
     $ns_general = $app->getName() . '::' . 'com.tienda.products.state';
     $session->set($ns_general, $state);
     // get the category we're looking at
     $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category'));
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $cmodel = JModel::getInstance('Categories', 'TiendaModel');
     $cat = $cmodel->getTable();
     $cat->load($filter_category);
     // set the title based on the selected category
     $title = empty($cat->category_name) ? JText::_('COM_TIENDA_ALL_CATEGORIES') : JText::_($cat->category_name);
     $level = !empty($filter_category) ? $filter_category : '1';
     // breadcrumb support
     $app = JFactory::getApplication();
     $pathway = $app->getPathway();
     // does this item have its own itemid?  if so, let joomla handle the breadcrumb,
     // otherwise, help it out a little bit
     $category_itemid = $this->router->category($filter_category, true);
     if (!$category_itemid) {
         $category_itemid = JRequest::getInt('Itemid');
         $items = Tienda::getClass("TiendaHelperCategory", 'helpers.category')->getPathName($filter_category, 'array');
         if (!empty($items)) {
             // add the categories to the pathway
             Tienda::getClass("TiendaHelperPathway", 'helpers.pathway')->insertCategories($items, $category_itemid);
         }
         // add the item being viewed to the pathway
         $pathway_values = $pathway->getPathway();
         $pathway_names = Tienda::getClass("TiendaHelperBase", 'helpers._base')->getColumn($pathway_values, 'name');
         $pathway_links = Tienda::getClass("TiendaHelperBase", 'helpers._base')->getColumn($pathway_values, 'link');
         $cat_url = "index.php?Itemid={$category_itemid}";
         if (!in_array($cat->category_name, $pathway_names)) {
             $pathway->addItem($title);
         }
     }
     $cat->itemid = $category_itemid;
     // get the category's sub categories
     $cmodel->setState('filter_level', $level);
     $cmodel->setState('filter_enabled', '1');
     $cmodel->setState('order', 'tbl.lft');
     $cmodel->setState('direction', 'ASC');
     if ($citems = $cmodel->getList()) {
         foreach ($citems as $item) {
             $item->itemid_string = null;
             $item->itemid = Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($item->category_id, true);
             if (!empty($item->itemid)) {
                 $item->itemid_string = "&Itemid=" . $item->itemid;
             }
         }
     }
     $this->_list = true;
     // if you want to display a slightly differen add-to-cart area for list view, check this boolean
     // get the products to be displayed in this category
     if ($items = $model->getList()) {
         JRequest::setVar('page', 'category');
         // for "getCartButton"
         $this->display_cartbutton = Tienda::getInstance()->get('display_category_cartbuttons', '1');
         foreach ($items as $item) {
             $item->itemid_string = null;
             $item->itemid = (int) Tienda::getClass("TiendaHelperRoute", 'helpers.route')->product($item->product_id, null, true);
             if (!empty($item->itemid)) {
                 $item->itemid_string = "&Itemid=" . $item->itemid;
             }
         }
     }
     if ($model->getState('filter_price_from') > '0' || $model->getState('filter_price_to') > '0') {
         $url = "index.php?option=com_tienda&view=products&filter_category={$filter_category}&filter_price_from=&filter_price_to=";
         $from = TiendaHelperBase::currency($model->getState('filter_price_from'));
         $to = $model->getState('filter_price_to') > 0 ? TiendaHelperBase::currency($model->getState('filter_price_to')) : JText::_('COM_TIENDA_MAXIMUM_PRICE');
         $view->assign('remove_pricefilter_url', $url);
         $view->assign('pricefilter_applied', true);
         $view->assign('filterprice_from', $from);
         $view->assign('filterprice_to', $to);
     }
     if (Tienda::getInstance()->get('enable_product_compare', '1')) {
         Tienda::load("TiendaHelperProductCompare", 'helpers.productcompare');
         $compareitems = TiendaHelperProductCompare::getComparedProducts();
         $view->assign('compareitems', $compareitems);
     }
     $view->assign('level', $level);
     $view->assign('title', $title);
     $view->assign('cat', $cat);
     $view->assign('citems', $citems);
     $view->assign('items', $items);
     $view->set('_doTask', true);
     $view->setModel($model, true);
     // add the media/templates folder as a valid path for templates
     $view->addTemplatePath(Tienda::getPath('categories_templates'));
     // but add back the template overrides folder to give it priority
     $template_overrides = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_tienda/' . $view->getName();
     $view->addTemplatePath($template_overrides);
     // using a helper file, we determine the category's layout
     $layout = Tienda::getClass('TiendaHelperCategory', 'helpers.category')->getLayout($cat->category_id);
     $view->setLayout($layout);
     $view->display();
     $this->footer();
     return;
 }