Exemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see tienda/admin/tables/TiendaTable#delete($oid)
  */
 function delete($oid = '')
 {
     if (empty($oid)) {
         // if empty, use the values of the current keys
         $keynames = $this->getKeyNames();
         foreach ($keynames as $key => $value) {
             $oid[$key] = $this->{$key};
         }
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_('COM_TIENDA_CANNOT_DELETE_WITH_EMPTY_KEY'));
             return false;
         }
     }
     if (!is_array($oid)) {
         $keyName = $this->getKeyName();
         $arr = array();
         $arr[$keyName] = $oid;
         $oid = $arr;
     }
     $dispatcher = JDispatcher::getInstance();
     $before = $dispatcher->trigger('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new TiendaQuery();
     $query->delete();
     $query->from($this->getTableName());
     foreach ($oid as $key => $value) {
         // Check that $key is field in table
         if (!in_array($key, array_keys($this->getProperties()))) {
             $this->setError(get_class($this) . ' does not have the field ' . $key);
             return false;
         }
         // add the key=>value pair to the query
         $value = $db->Quote($db->getEscaped(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * Enter description here ...
  * @return unknown_type
  */
 public function deleteExpiredSessionProductCompared()
 {
     $db = JFactory::getDBO();
     Tienda::load('TiendaQuery', 'library.query');
     Tienda::load("TiendaHelperBase", 'helpers._base');
     $helper = new TiendaHelperBase();
     $query = new TiendaQuery();
     $query->select("tbl.session_id");
     $query->from("#__session AS tbl");
     $db->setQuery((string) $query);
     $results = $db->loadAssocList();
     $session_ids = $helper->getColumn($results, 'session_id');
     $query = new TiendaQuery();
     $query->delete();
     $query->from("#__tienda_productcompare");
     $query->where("`user_id` = '0'");
     $query->where("`session_id` NOT IN('" . implode("', '", $session_ids) . "')");
     $db->setQuery((string) $query);
     if (!$db->query()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     $date = JFactory::getDate();
     $now = $date->toMySQL();
     // Update config to say this has been done already
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $config = JTable::getInstance('Config', 'TiendaTable');
     $config->load(array('config_name' => 'last_deleted_expired_sessionproductscompared'));
     $config->config_name = 'last_deleted_expired_sessionproductscompared';
     $config->value = $now;
     $config->save();
     return true;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public function deleteItemsXref($type, $oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     $query = new TiendaQuery();
     $query->delete();
     $query->from('#__tienda_product' . $type . 'xref');
     $query->where('product_id = ' . $this->{$k});
     $this->_db->setQuery((string) $query);
     $this->_db->query();
     return true;
 }
Exemplo n.º 5
0
 function deleteRequests()
 {
     $hours = Tienda::getInstance()->get('pos_request_clean_hours', 24);
     Tienda::getClass('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $q->delete();
     $q->from('#__tienda_posrequests');
     $q->where('created_date < (NOW() - INTERVAL ' . $hours . ' HOUR)');
     $db = JFactory::getDbo();
     $db->setQuery($q);
     if ($db->query()) {
         $rec = $db->getAffectedRows();
         $this->setMessage(JText::sprintf('COM_TIENDA_POS_REQUESTS_DELETED_SUCCESS', $rec));
     } else {
         $this->setMessage(JText::_('COM_TIENDA_POS_REQUESTS_DELETED_FAILED', 'error'));
     }
     $this->setRedirect('index.php?option=com_tienda&view=config&task=orders');
 }
Exemplo n.º 6
0
 /**
  * Remove the Item from the cart
  *
  * @param  session id
  * @param  user id
  * @param  product id
  * @return null
  */
 function removeCartItem($session_id, $user_id = 0, $product_id)
 {
     $db = JFactory::getDBO();
     Tienda::load('TiendaQuery', 'library.query');
     $query = new TiendaQuery();
     $query->from("#__tienda_carts");
     if (empty($user_id)) {
         $query->where("`session_id` = '{$session_id}' ");
     }
     $query->where("`user_id` = '" . $user_id . "'");
     $query->where("`product_id` = '" . $product_id . "'");
     $q_select = clone $query;
     $q_select->select('cart_id, product_id');
     $db->setQuery((string) $q_select);
     $items = $db->loadObjectList();
     $query->delete();
     $db->setQuery((string) $query);
     // TODO Make this report errors and return boolean
     $db->query();
     $dispatcher = JDispatcher::getInstance();
     for ($i = 0, $c = count($items); $i < $c; $i++) {
         $dispatcher->trigger('onRemoveFromCart', array($items[$i]));
     }
     return null;
 }
Exemplo n.º 7
0
 function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if ($return = parent::delete($oid)) {
         $query = new TiendaQuery();
         $query->delete();
         $query->from('#__tienda_productdownloads');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
         $query = new TiendaQuery();
         $query->delete();
         $query->from('#__tienda_productdownloadlogs');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
     }
     return parent::check();
 }
Exemplo n.º 8
0
 /**
  * Remove the Item from product compare  
  *
  * @param  session id
  * @param  user id
  * @param  product id
  * @return null
  */
 function removeComparedItem($session_id, $user_id = 0, $product_id)
 {
     $db = JFactory::getDBO();
     Tienda::load('TiendaQuery', 'library.query');
     $query = new TiendaQuery();
     $query->delete();
     $query->from("#__tienda_productcompare");
     if (empty($user_id)) {
         $query->where("`session_id` = '{$session_id}' ");
     }
     $query->where("`user_id` = '" . $user_id . "'");
     $query->where("`product_id` = '" . $product_id . "'");
     $db->setQuery((string) $query);
     // TODO Make this report errors and return boolean
     $db->query();
     return null;
 }