Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see Citruscart/admin/tables/CitruscartTable#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_CITRUSCART_CANNOT_DELETE_WITH_EMPTY_KEY'));
             return false;
         }
     }
     if (!is_array($oid)) {
         $keyName = $this->getKeyName();
         $arr = array();
         $arr[$keyName] = $oid;
         $oid = $arr;
     }
     $before = JFactory::getApplication()->triggerEvent('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new CitruscartQuery();
     $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->q($db->escape(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         JFactory::getApplication()->triggerEvent('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Esempio n. 2
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();
     Citruscart::load('CitruscartQuery', 'library.query');
     $query = new CitruscartQuery();
     $query->from("#__citruscart_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();
     for ($i = 0, $c = count($items); $i < $c; $i++) {
         JFactory::getApplication()->triggerEvent('onRemoveFromCart', array($items[$i]));
     }
     return null;
 }
Esempio n. 3
0
 /**
  *
  * Enter description here ...
  * @return unknown_type
  */
 public function deleteExpiredSessionCarts()
 {
     $db = JFactory::getDBO();
     Citruscart::load('CitruscartQuery', 'library.query');
     Citruscart::load("CitruscartHelperBase", 'helpers._base');
     $helper = new CitruscartHelperBase();
     $query = new CitruscartQuery();
     $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 CitruscartQuery();
     $query->delete();
     $query->from("#__citruscart_carts");
     $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->toSql();
     // Update config to say this has been done already
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $config = JTable::getInstance('Config', 'CitruscartTable');
     $config->load(array('config_name' => 'last_deleted_expired_sessioncarts'));
     $config->config_name = 'last_deleted_expired_sessioncarts';
     $config->value = $now;
     $config->save();
     return true;
 }
Esempio n. 4
0
 function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if ($return = parent::delete($oid)) {
         $query = new CitruscartQuery();
         $query->delete();
         $query->from('#__citruscart_productdownloads');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
         $query = new CitruscartQuery();
         $query->delete();
         $query->from('#__citruscart_productdownloadlogs');
         $query->where('productfile_id = ' . $this->{$k});
         $this->_db->setQuery((string) $query);
         $this->_db->query();
     }
     return parent::check();
 }
Esempio n. 5
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();
     Citruscart::load('CitruscartQuery', 'library.query');
     $query = new CitruscartQuery();
     $query->delete();
     $query->from("#__citruscart_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;
 }
Esempio n. 6
0
 function deleteRequests()
 {
     $hours = Citruscart::getInstance()->get('pos_request_clean_hours', 24);
     Citruscart::getClass('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->delete();
     $q->from('#__citruscart_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_CITRUSCART_POS_REQUESTS_DELETED_SUCCESS', $rec));
     } else {
         $this->setMessage(JText::_('COM_CITRUSCART_POS_REQUESTS_DELETED_FAILED', 'error'));
     }
     $this->setRedirect('index.php?option=com_citruscart&view=config&task=orders');
 }
Esempio n. 7
0
 public function deleteItemsXref($type, $oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     $query = new CitruscartQuery();
     $query->delete();
     $query->from('#__citruscart_product' . $type . 'xref');
     $query->where('product_id = ' . $this->{$k});
     $this->_db->setQuery((string) $query);
     $this->_db->query();
     return true;
 }
Esempio n. 8
0
 /**
  * Adds an item to a User's Product Compare
  * whether in the session or the db
  *
  */
 function addProductToCompare()
 {
     $input = JFactory::getApplication()->input;
     // 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 = $input->getInt('product_id');
     $add = $input->getInt('add', 1);
     //deleting product to compare
     if (!$add) {
         $db = JFactory::getDBO();
         Citruscart::load('CitruscartQuery', 'library.query');
         $query = new CitruscartQuery();
         $query->delete();
         $query->from("#__citruscart_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 {
         Citruscart::load('CitruscartHelperProductCompare', 'helpers.productcompare');
         $compare_helper = new CitruscartHelperProductCompare();
         //check limit
         $compareLimit = $compare_helper->checkLimit();
         if (!$compareLimit) {
             Citruscart::load('CitruscartHelperBase', 'helpers._base');
             $helper = CitruscartHelperBase::getInstance();
             $limit = Citruscart::getInstance()->get('compared_products', '5');
             $response['msg'] = $helper->generateMessage(JText::sprintf("COM_CITRUSCART_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', 'CitruscartTable');
         $table->load(array('product_id' => $item->product_id));
         $response['msg'] .= '<li>';
         $response['msg'] .= '<a href="' . JRoute::_('index.php?option=com_citruscart&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;
 }