示例#1
0
 public function reorder($where = '')
 {
     $k = $this->_tbl_key;
     $query = new CitruscartQuery();
     $query->select($this->_tbl_key);
     $query->select('ordering');
     $query->from($this->_tbl);
     $query->order('ordering ASC');
     $query->order('country_name ASC');
     $this->_db->setQuery((string) $query);
     if (!($orders = $this->_db->loadObjectList())) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // correct all the ordering numbers
     for ($i = 0, $n = count($orders); $i < $n; $i++) {
         if ($orders[$i]->ordering >= 0) {
             if ($orders[$i]->ordering != $i + 1) {
                 $orders[$i]->ordering = $i + 1;
                 $query = new CitruscartQuery();
                 $query->update($this->_tbl);
                 $query->set('ordering = ' . (int) $orders[$i]->ordering);
                 $query->where($k . ' = ' . $this->_db->Quote($orders[$i]->{$k}));
                 $this->_db->setQuery((string) $query);
                 $this->_db->query();
             }
         }
     }
     return true;
 }
示例#2
0
 /**
  * Method to calculate statistics about manufacturers in an order
  * 
  * @param $items Array of order items
  * 
  * @return	Array with list of manufacturers and their stats
  */
 function calculateStatsOrder($items)
 {
     $db = JFactory::getDbo();
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->select('manufacturer_id');
     $q->from('`#__citruscart_products`');
     $result = array();
     foreach ($items as $item) {
         $q->where('product_id = ' . (int) $item->product_id);
         $db->setQuery($q);
         $res = $db->loadObject();
         if ($res == null) {
             $man_id = 0;
         } else {
             $man_id = $res->manufacturer_id;
         }
         if (!isset($result[$man_id])) {
             $model = JModelLegacy::getInstance('Manufacturers', 'CitruscartModel');
             $model->setId($man_id);
             if (!($man_item = $model->getItem())) {
                 $man_item = new stdClass();
             }
             $result[$man_id] = $man_item;
             $result[$man_id]->subtotal = 0;
             $result[$man_id]->total_tax = 0;
         }
         $result[$man_id]->subtotal += $item->orderitem_final_price;
         $result[$man_id]->total_tax += $item->orderitem_tax;
     }
     return $result;
 }
 /**
  * (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;
     }
 }
示例#4
0
 /**
  * Creates a commission record for an order 
  * if Amigos is installed and the user is a referral
  * 
  * @param int $order_id An order number
  * @return array
  */
 function getCommissions($order_id)
 {
     if (!isset($this->commissions[$order_id])) {
         $return = array();
         Citruscart::load('CitruscartQuery', 'library.query');
         $query = new CitruscartQuery();
         $query->select('tbl.*');
         $query->from('#__amigos_commissions AS tbl');
         $query->where("tbl.orderid = '" . (int) $order_id . "'");
         $query->where("tbl.order_type = 'com_citruscart'");
         $db = JFactory::getDBO();
         $db->setQuery((string) $query);
         $this->commissions[$order_id] = $db->loadObjectList();
     }
     return $this->commissions[$order_id];
 }
示例#5
0
 function listRateLevels($selected, $taxrate_id, $tax_class_id)
 {
     $list = array();
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $db = JFactory::getDbo();
     $q->select('max( level ) as `max_level`, min( level ) as `min_level`');
     $q->from('#__citruscart_taxrates');
     $q->where('tax_class_id = ' . $tax_class_id);
     $db->setQuery($q);
     $levels = $db->loadObject();
     if (!strlen($levels->min_level)) {
         $levels->min_level = 0;
     }
     for ($i = $levels->min_level; $i <= $levels->max_level + 1; $i++) {
         $list[] = JHTML::_('select.option', $i, 'Level - ' . $i);
     }
     return JHTML::_('select.genericlist', $list, 'levels[' . $taxrate_id . ']', array('class' => 'inputbox', 'size' => '1'), 'value', 'text', $selected);
 }
 /**
  *  Given the user id and the file id will return the row id on which entry is greate then 0
  *  
  *  @param user id
  *  @param productfile id
  *  @return productdown load id
  */
 function getProductDownloadInfo($productfile_id, $user_id)
 {
     Citruscart::load('CitruscartQuery', 'library.query');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $tableProductDownload = JTable::getInstance('ProductDownloads', 'CitruscartTable');
     $query = new CitruscartQuery();
     $select[] = "productdl.*";
     $query->select($select);
     $query->from($tableProductDownload->getTableName() . " AS productdl");
     $whereClause[] = "productdl.user_id = " . (int) $user_id;
     $whereClause[] = "productdl.productfile_id='" . $productfile_id . "'";
     $whereClause[] = "productdl.productdownload_max > 0";
     // Assumed that 0000-00-00 00:00:00 is the entry for the unlimited Downloads
     // TODO apply the where task for the Date
     $query->where($whereClause, "AND");
     $db = JFactory::getDBO();
     $db->setQuery((string) $query);
     $item = $db->loadObject();
     return $item;
 }
示例#7
0
 protected function _buildQueryFields(&$query)
 {
     $state = $this->getState();
     $filter_date_from = $this->getState('filter_date_from');
     $filter_date_to = $this->getState('filter_date_to');
     $fields = array();
     $fields[] = " tbl.* ";
     // select the total downloads
     $downloads = new CitruscartQuery();
     $downloads->select('SUM(tbl_downloads_tmp.`productdownload_max`)');
     $downloads->from('#__citruscart_productdownloads AS tbl_downloads_tmp');
     $downloads->where('tbl_downloads_tmp.productfile_id = tbl.productfile_id');
     if (strlen($filter_date_from)) {
         $downloads->where("tbl_downloads_tmp.productdownload_startdate >= '" . $filter_date_from . "'");
     }
     if (strlen($filter_date_to)) {
         $downloads->where("tbl_downloads_tmp.productdownload_startdate <= '" . $filter_date_to . "'");
     }
     $fields[] = "\n            ABS( (" . $downloads . ") ) \n        AS `file_downloads` ";
     // select the product name
     $fields[] = "tbl_products.product_name";
     $query->select($fields);
 }
示例#8
0
 /**
  * First stores the record
  * Then checks if it should be the default
  *
  * @see Citruscart/admin/tables/CitruscartTable#store($updateNulls)
  */
 function store($updateNulls = false)
 {
     if ($return = parent::store($updateNulls)) {
         if ($this->is_default_shipping == '1' || $this->is_default_billing == '1') {
             // update the defaults
             $query = new CitruscartQuery();
             $query->update("#__citruscart_addresses");
             $query->where("`user_id` = '{$this->user_id}'");
             $query->where("`address_id` != '{$this->address_id}'");
             if ($this->is_default_shipping == '1') {
                 $query->set("`is_default_shipping` = '0'");
             }
             if ($this->is_default_billing == '1') {
                 $query->set("`is_default_billing` = '0'");
             }
             $this->_db->setQuery((string) $query);
             if (!$this->_db->query()) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
         }
     }
     return $return;
 }
示例#9
0
 /**
  * Method to get the attributes with options of the current products
  * @return array
  */
 function getAttributes()
 {
     $finalAttributes = array();
     if ($this->_view != 'products' || empty($this->_products) || !$this->_params->get('filter_attributes')) {
         return $finalAttributes;
     }
     Citruscart::load('CitruscartHelperProduct', 'helpers.product');
     //check if we have pids
     //else get the pids from $this->_products
     if (empty($this->_pids)) {
         $pids = array();
         foreach ($this->_products as $item) {
             $pids[] = $item->product_id;
         }
         $this->_pids = $pids;
     }
     //retun if we dont have pids
     if (empty($this->_pids)) {
         return $finalAttributes;
     }
     //check if we CitruscartQuery class exist
     if (!class_exists('CitruscartQuery')) {
         Citruscart::load('CitruscartQuery', 'library.query');
     }
     //get the attributes of the current products
     $query = new CitruscartQuery();
     $query->select('tbl.product_id');
     $query->select('tbl.productattribute_name');
     $query->select('tbl.productattribute_id');
     $query->from('#__citruscart_productattributes AS tbl');
     //explode first because mysql needs the attribute ids inside a quote
     $excluded_attributes = explode(',', $this->_params->get('excluded_attributes'));
     $query->where("tbl.productattribute_id NOT IN ('" . implode("', '", $excluded_attributes) . "')");
     $query->where("tbl.product_id IN ('" . implode("', '", $this->_pids) . "')");
     $this->_db->setQuery((string) $query);
     $attributes = $this->_db->loadObjectList();
     //return if no available attributes
     if (empty($attributes)) {
         return $finalAttributes;
     }
     $newAttributes = array();
     //loop to get the available options of the attribute
     foreach ($attributes as $attribute) {
         $options = CitruscartHelperProduct::getAttributeOptionsObjects($attribute->productattribute_id);
         foreach ($options as $option) {
             $option->product_id = $attribute->product_id;
             $option->attributename = $attribute->productattribute_name;
             $this->_options[$option->productattributeoption_id] = $option;
         }
         $attr_name = $attribute->productattribute_name;
         if ($this->_params->get('attributes_case_insensitive', 1)) {
             $attr_name = strtolower($attribute->productattribute_name);
         }
         if (isset($newAttributes[$attr_name])) {
             $newAttributes[$attr_name] = array_merge($newAttributes[$attr_name], $options);
         } else {
             $newAttributes[$attr_name] = $options;
         }
     }
     $link = $this->_link . '&filter_category=' . $this->_filter_category;
     if (empty($this->_filter_attribute_set)) {
         $session = JFactory::getSession();
         $cleanO = array();
         $cleanO[$this->_filter_category] = $this->_options;
         $session->set('options', $cleanO, 'Citruscart_layered_nav');
     }
     $options_ids = !empty($this->_filter_option_set) ? explode(',', $this->_filter_option_set) : array();
     $finalAttributes = array();
     foreach ($newAttributes as $key => $options) {
         foreach ($options as $option) {
             $addoptionset = '';
             if (!in_array($option->productattributeoption_id, $options_ids)) {
                 if (isset($finalAttributes[$key][$option->productattributeoption_name])) {
                     $addoptionset = ',' . $option->productattributeoption_id;
                     $finalAttributes[$key][$option->productattributeoption_name]->products[] = $option->product_id;
                     $finalAttributes[$key][$option->productattributeoption_name]->attributes[] = $option->productattribute_id;
                 } else {
                     $finalAttributes[$key][$option->productattributeoption_name] = new stdClass();
                     $newoption_set = count($options_ids) ? $this->_filter_option_set . ',' . $option->productattributeoption_id : $option->productattributeoption_id;
                     $finalAttributes[$key][$option->productattributeoption_name]->products = array($option->product_id);
                     $finalAttributes[$key][$option->productattributeoption_name]->attributes = array($option->productattribute_id);
                 }
                 $finalAttributes[$key][$option->productattributeoption_name]->link = $link . '&filter_option_set=' . $newoption_set . $addoptionset;
             }
         }
     }
     return $finalAttributes;
 }
示例#10
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;
 }
示例#11
0
 /**
  * Method to get if user has multiple user group
  * @return array
  */
 private function getUserGroups()
 {
     $user = JFactory::getUser();
     $database = JFactory::getDBO();
     Citruscart::load('CitruscartQuery', 'library.query');
     $query = new CitruscartQuery();
     $query->select('tbl.group_id');
     $query->from('#__citruscart_usergroupxref AS tbl');
     $query->join('INNER', '#__citruscart_groups AS g ON g.group_id = tbl.group_id');
     $query->where("tbl.user_id = " . (int) $user->id);
     $query->order('g.ordering ASC');
     $database->setQuery((string) $query);
     return $database->loadColumn();
 }
示例#12
0
 /**
  * Builds a generic SELECT COUNT(*) query
  */
 protected function _buildResultQuery()
 {
     $grouped_query = new CitruscartQuery();
     $grouped_query->select($this->getState('select', 'COUNT(*)'));
     $this->_buildQueryFrom($grouped_query);
     $this->_buildQueryJoins($grouped_query);
     $this->_buildQueryWhere($grouped_query);
     $this->_buildQueryGroup($grouped_query);
     $this->_buildQueryHaving($grouped_query);
     $query = new CitruscartQuery();
     $query->select('COUNT(*)');
     $query->from('(' . $grouped_query . ') as grouped_count');
     // Allow plugins to edit the query object
     $suffix = ucfirst($this->getName());
     JFactory::getApplication()->triggerEvent('onAfterBuildResultQuery' . $suffix, array(&$query));
     return $query;
 }
示例#13
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');
 }
示例#14
0
 /**
  * Dedicated function for eav fields filtering
  * @param CitruscartQuery $query
  */
 protected function _buildQueryEav(&$query)
 {
     $eavStates = $this->getEavState()->getProperties();
     // If there are eav states set
     if (count($eavStates)) {
         // Loop through the filters
         foreach ($eavStates as $k => $v) {
             $filter_prefix = 'filter_';
             // Is it a filter?
             if (strpos($k, $filter_prefix) === 0) {
                 // Different table name for different joins!
                 // alias on which we want to filter
                 $attribute_alias = substr($k, strlen($filter_prefix));
                 $tbl_key = $this->getTable()->getKeyName();
                 $eav_tbl_name = 'eav_' . $attribute_alias;
                 $value_tbl_name = 'value_' . $attribute_alias;
                 // Join the table based on the type of the value
                 Citruscart::load("CitruscartHelperBase", 'helpers._base');
                 $eav_helper = CitruscartHelperBase::getInstance('Eav');
                 $table_type = $eav_helper->getType($attribute_alias);
                 // Join the tables
                 $query->join('LEFT', '#__citruscart_eavattributes AS ' . $eav_tbl_name . ' ON tbl.' . $tbl_key . ' = ' . $eav_tbl_name . '.eaventity_id');
                 $query->join('LEFT', '#__citruscart_eavvalues' . $table_type . ' AS ' . $value_tbl_name . ' ON ' . $eav_tbl_name . '.eavattribute_id = ' . $value_tbl_name . '.eavattribute_id');
                 // Filter using '='
                 $query->where($eav_tbl_name . ".eavattribute_alias = '{$attribute_alias}'");
                 $query->where($value_tbl_name . ".eavvalue_value = '{$v}'");
             }
         }
     }
 }
示例#15
0
 /**
  * Method which returns the next guest user account ID in the system
  * (starts off with -11 => reserve 0 ... -10 for later use)
  *
  * @return Guest user account ID
  */
 public function getNextGuestUserId()
 {
     $db = JFactory::getDbo();
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $start_id = Citruscart::getGuestIdStart();
     $q->select('min( tbl.user_id)');
     $q->from('#__citruscart_userinfo tbl');
     $q->where('tbl.user_id < ' . $start_id);
     $db->setQuery((string) $q);
     $res = $db->loadResult();
     if ($res === null) {
         // no guest account in system
         return $start_id - 1;
     } else {
         return $res - 1;
     }
     // the last guest account id -1
 }
 /**
  * Returns the tax rate for an item
  *
  * @param int $shipping_method_id
  * @param int $geozone_id
  * @return int
  */
 protected function getTaxRate($shipping_method_id, $geozone_id)
 {
     Citruscart::load('CitruscartQuery', 'library.query');
     $taxrate = "0.00000";
     $db = JFactory::getDBO();
     $query = new CitruscartQuery();
     $query->select('tbl.*');
     $query->from('#__citruscart_taxrates AS tbl');
     $query->join('LEFT', '#__citruscart_shippingmethods AS shippingmethod ON shippingmethod.tax_class_id = tbl.tax_class_id');
     $query->where('shippingmethod.shipping_method_id = ' . $shipping_method_id);
     $query->where('tbl.geozone_id = ' . $geozone_id);
     $db->setQuery((string) $query);
     if ($data = $db->loadObject()) {
         $taxrate = $data->tax_rate;
     }
     return $taxrate;
 }
示例#17
0
 /**
  * Method to get date of the first or the last order
  *
  * @access private
  * @return void
  */
 public static function getDateMarginalOrder($states, $order = 'ASC')
 {
     $db = JFactory::getDBO();
     $today = CitruscartHelperBase::getToday();
     $q = new CitruscartQuery();
     $q->select('tbl.created_date AS date');
     $q->from('#__citruscart_orders AS tbl');
     $q->where(" tbl.order_state_id IN ( " . $states . " ) ");
     $q->order(" tbl.created_date " . $order);
     $db->setQuery((string) $q);
     $return = $db->loadObject();
     if ($return) {
         $return = $return->date;
     } else {
         $return = $today;
     }
     return $return;
 }
示例#18
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;
 }
示例#19
0
 /**
  * Determines if a product is in a visitor's wishlist,
  * whether they are logged in or not
  *
  * xref_type = 'user' and xref_id = user_id OR
  * xref_type = 'session' anx xref_id = session_id
  *
  * @param unknown_type $product_id
  * @param unknown_type $xref_id
  * @param unknown_type $xref_type
  */
 public function isInWishlist($product_id, $xref_id, $xref_type = 'user', $attributes = '')
 {
     $query = new CitruscartQuery();
     $query->select("tbl.wishlistitem_id");
     $query->from('#__citruscart_wishlistitems AS tbl');
     $query->where("tbl.product_id = " . (int) $product_id);
     if (strtolower($xref_type) == 'session') {
         $query->where("tbl.session_id = " . $this->_db->q($xref_id));
     } else {
         $query->where("tbl.user_id = " . (int) $xref_id);
     }
     if (!empty($attributes)) {
         $query->where("tbl.product_attributes = " . $this->_db->q($attributes));
     }
     $db = $this->getDBO();
     $db->setQuery((string) $query);
     if ($result = $db->loadResult()) {
         return $result;
     }
     return false;
 }
示例#20
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;
 }
示例#21
0
 public function getDefault()
 {
     $query = new CitruscartQuery();
     $query->select('tbl.*');
     $query->from($this->getTable()->getTableName() . " AS tbl");
     $query->where("tbl.country_enabled = '1'");
     $query->order("tbl.ordering ASC");
     $db = $this->getDBO();
     $db->setQuery((string) $query, 0, 1);
     if (!($results = $db->loadObjectList())) {
         return false;
     }
     return $results[0];
 }
示例#22
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;
 }
示例#23
0
 public static function calculateProductAttributeProperty(&$product, $attributes, $product_price, $product_weight)
 {
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $helper_product = CitruscartHelperBase::getInstance('Product');
     // first we get rid off phantom attributes (the ones that should be hidden because their parent attribute was just unselected)
     $attr_base = CitruscartHelperProduct::getAttributes($product->product_id, array_merge($attributes, array('0')));
     $attr_final = CitruscartHelperProduct::getDefaultAttributeOptions($attr_base);
     foreach ($attr_final as $key => $value) {
         if (isset($attributes['attribute_' . $key])) {
             $attr_final[$key] = $attributes['attribute_' . $key];
         }
     }
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->select('tbl.`productattributeoption_price` , tbl.`productattributeoption_prefix`, tbl.`productattributeoption_id` ');
     $q->select('tbl.`productattributeoption_code`, tbl.`productattributeoption_weight`, tbl.`productattributeoption_prefix_weight`');
     $q->from('`#__citruscart_productattributeoptions` tbl');
     $q->join('left', '`#__citruscart_productattributes` atr ON tbl.	productattribute_id = atr.productattribute_id');
     $q->where("tbl.productattributeoption_id IN ('" . implode("', '", $attr_final) . "')");
     $q->order('atr.ordering ASC');
     $db = JFactory::getDbo();
     $db->setQuery($q);
     $res = $db->loadObjectList();
     $attributes = array();
     for ($i = 0, $c = count($res); $i < $c; $i++) {
         // update product price
         // is not + or -
         if ($res[$i]->productattributeoption_prefix == '=') {
             $product->{$product_price} = floatval($res[$i]->productattributeoption_price);
         } else {
             $product->{$product_price} = $product->{$product_price} + floatval($res[$i]->productattributeoption_prefix . $res[$i]->productattributeoption_price);
         }
         // update product weight
         if ($res[$i]->productattributeoption_prefix_weight == '=') {
             $product->{$product_weight} = floatval($res[$i]->productattributeoption_weight);
         } else {
             $product->{$product_weight} = $product->{$product_weight} + floatval($res[$i]->productattributeoption_prefix_weight . $res[$i]->productattributeoption_weight);
         }
         $attributes[] = $res[$i]->productattributeoption_id;
     }
     $product->sku = self::getProductSKU($product, $attributes);
 }
示例#24
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();
 }
示例#25
0
 /**
  * Gets list of all subscriptions by issue x-days before expiring
  *
  * @$days Number of days before expiring (0 stands for expired now)
  *
  * @return List of subscriptions by issue
  */
 public function getListByIssues($days = 0)
 {
     $db = $this->getDBO();
     $date = JFactory::getDate();
     $tz = JFactory::getConfig()->get('offset');
     $date->setTimezone(new DateTimeZone($tz));
     //here!
     $today = $date->format("%Y-%m-%d");
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->select('s.*');
     $q->from('`#__citruscart_productissues` tbl');
     $q->join('left', '`#__citruscart_subscriptions` s ON s.`product_id` = tbl.`product_id`');
     $q->join('left', '`#__citruscart_orderitems` oi ON s.`orderitem_id` = oi.`orderitem_id`');
     $q->where('s.`subscription_enabled` = 1');
     $q->where('oi.`subscription_period_unit` = \'I\'');
     if ($days) {
         $query = " SELECT DATE_ADD('" . $today . "', INTERVAL '.{$days}.' DAY) ";
         $db->setQuery($query);
         $date = Date('Y-m-d', strtotime($db->loadResult()));
     } else {
         $date = $today;
     }
     $q->where('DATE_FORMAT( tbl.`publishing_date`, \'%Y-%m-%d\' ) = \'' . $date . '\'');
     $db->setQuery((string) $q);
     return $db->loadObjectList();
 }
示例#26
0
 static function getNumberIssues($product_id, $start_date = null, $end_date = null)
 {
     $db = JFactory::getDbo();
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->select('count( tbl.`product_issue_id` ) ');
     $q->from('`#__citruscart_productissues` tbl');
     $q->where('tbl.`product_id`=' . $product_id);
     if ($start_date === null) {
         $date = JFactory::getDate();
         $date->setTimezone(new DateTimeZone(JFactory::getConfig()->get('offset')));
         $start_date = $date->format("Y-m-d 00:00:00");
     }
     $q->where('tbl.`publishing_date` >= \'' . $start_date . '\'');
     if ($end_date !== null) {
         $q->where('tbl.`publishing_date` <= \'' . $end_date . '\'');
     }
     $db->setQuery((string) $q);
     return $db->loadResult();
 }
示例#27
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;
 }
示例#28
0
 function getTaxRatesAtLevel($level, $geozone_id = null, $tax_class_id = null, $tax_type = null, $update = false)
 {
     static $taxrates = null;
     // static array for caching results
     if ($taxrates === null) {
         $taxrates = array();
     }
     if (!$geozone_id) {
         $geozone_id = -1;
     }
     if (!$tax_class_id) {
         $tax_class_id = -1;
     }
     if (isset($taxrates[$tax_class_id][$geozone_id][$level]) && !$update) {
         return $taxrates[$tax_class_id][$geozone_id][$level];
     }
     Citruscart::load('CitruscartQuery', 'library.query');
     $db = JFactory::getDbo();
     $q = new CitruscartQuery();
     $q->select(array('tax_rate_id', 'geozone_id', 'tax_class_id', 'tax_rate', 'tax_rate_description', 'level'));
     $q->from('#__citruscart_taxrates');
     $q->where('level = ' . (int) $level);
     if ($geozone_id > 0) {
         $q->where('geozone_id = ' . (int) $geozone_id);
     }
     if ($tax_class_id > 0) {
         $q->where('tax_class_id = ' . (int) $tax_class_id);
     }
     $q->order('tax_rate_description');
     $db->setQuery($q);
     $items = $db->loadObjectList();
     $taxrates[$tax_class_id][$geozone_id][$level] = $items;
     return $taxrates[$tax_class_id][$geozone_id][$level];
 }
示例#29
0
 public static function calculateTaxSingleProductGeozone($product_id, $product_price, $geozone_id = null, $tax_class_id = null, $tax_type = null, $update_rates = false)
 {
     static $taxes = null;
     static $taxes_rates = null;
     if ($taxes === null) {
         $taxes = array();
     }
     if ($taxes_rates === null) {
         $taxes_rates = array();
     }
     $result = new stdClass();
     $result->rates = array();
     $result->amount = 0;
     Citruscart::load('CitruscartQuery', 'library.query');
     $db = JFactory::getDBO();
     if ($tax_class_id === null) {
         $q = new CitruscartQuery();
         $q->select('tax_class_id');
         $q->from('#__citruscart_products');
         $q->where('product_id = ' . (int) $product_id);
         $db->setQuery($q);
         $tax_class_id = $db->loadResult();
     }
     if (isset($tax_rates[$geozone_id][$tax_class_id]) && !$update_rates) {
         $data = $tax_rates[$geozone_id][$tax_class_id];
     } else {
         $q = new CitruscartQuery();
         $q->select('tax_class_id, tax_rate_id, tax_rate, tax_rate_description, level ');
         $q->from('#__citruscart_taxrates');
         if ($geozone_id !== null) {
             $q->where("geozone_id = " . (int) $geozone_id);
         }
         $q->where('tax_class_id = ' . (int) $tax_class_id);
         $q->order('level');
         $db->setQuery((string) $q);
         $data = $db->loadObjectList();
         $tax_rates[$geozone_id][$tax_class_id] = $data;
     }
     $taxes_list = array();
     if ($c = count($data)) {
         $prev_level = 0;
         $subtotal = $product_price;
         $tax_amount = 0;
         for ($i = 0; $i < $c; $i++) {
             $tax = $data[$i];
             if ($tax->level != $prev_level) {
                 $subtotal += $tax_amount;
                 $result->amount += $tax_amount;
                 $tax_amount = 0;
                 $prev_level = $tax->level;
             }
             $tax->applied_tax = $tax->tax_rate / 100 * $subtotal;
             $tax_amount += $tax->applied_tax;
             $taxes_list[] = $tax;
         }
         $result->amount += $tax_amount;
         $result->rates = $taxes_list;
     }
     return $result;
 }
示例#30
0
 public static function getCouponProductIds($coupon_id)
 {
     Citruscart::load('CitruscartQuery', 'library.query');
     $query = new CitruscartQuery();
     $query->select('product_id');
     $query->from('#__citruscart_productcouponxref');
     $query->where('coupon_id = ' . (int) $coupon_id);
     $db = JFactory::getDBO();
     $db->setQuery($query);
     return $db->loadColumn();
 }