Exemplo n.º 1
0
 public function reorder($where = '')
 {
     $k = $this->_tbl_key;
     $query = new TiendaQuery();
     $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 TiendaQuery();
                 $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;
 }
Exemplo n.º 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();
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $q->select('manufacturer_id');
     $q->from('`#__tienda_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 = JModel::getInstance('Manufacturers', 'TiendaModel');
             $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;
 }
Exemplo n.º 3
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.º 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();
         Tienda::load('TiendaQuery', 'library.query');
         $query = new TiendaQuery();
         $query->select('tbl.*');
         $query->from('#__amigos_commissions AS tbl');
         $query->where("tbl.orderid = '" . (int) $order_id . "'");
         $query->where("tbl.order_type = 'com_tienda'");
         $db = JFactory::getDBO();
         $db->setQuery((string) $query);
         $this->commissions[$order_id] = $db->loadObjectList();
     }
     return $this->commissions[$order_id];
 }
Exemplo n.º 5
0
 function listRateLevels($selected, $taxrate_id, $tax_class_id)
 {
     $list = array();
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $db = JFactory::getDbo();
     $q->select('max( level ) as `max_level`, min( level ) as `min_level`');
     $q->from('#__tienda_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);
 }
Exemplo n.º 6
0
 /**
  *  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)
 {
     Tienda::load('TiendaQuery', 'library.query');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $tableProductDownload = JTable::getInstance('ProductDownloads', 'TiendaTable');
     $query = new TiendaQuery();
     $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;
 }
Exemplo n.º 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 TiendaQuery();
     $downloads->select('SUM(tbl_downloads_tmp.`productdownload_max`)');
     $downloads->from('#__tienda_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);
 }
Exemplo n.º 8
0
 /**
  * Override parent::_getData() to insert groupBy and orderBy clauses into query
  *  
  * @return unknown_type
  */
 function _getData()
 {
     $state = $this->_getState();
     $order_states = array('3', '5', '17');
     $filter_date_from = $state['filter_date_from'];
     $filter_date_to = $state['filter_date_to'];
     if (empty($filter_date_to) and empty($filter_date_from)) {
         $date = JFactory::getDate();
         $today = $date->toFormat("%Y-%m-%d 00:00:00");
         $filter_date_to = $today;
         $database = JFactory::getDBO();
         $query = " SELECT DATE_SUB('" . $today . "', INTERVAL 1 MONTH) ";
         $database->setQuery($query);
         $filter_date_from = $database->loadResult();
     } else {
         if (empty($filter_date_to) and !empty($filter_date_from)) {
             $filter_date_to = $filter_date_from;
         } else {
             if (!empty($filter_date_to) and empty($filter_date_from)) {
                 $filter_date_from = $filter_date_to;
             }
         }
     }
     $date_tmp = date_create($filter_date_to);
     date_modify($date_tmp, '24 hour');
     $database = JFactory::getDBO();
     $curdate = TiendaHelperBase::local_to_GMT_data($filter_date_from);
     $enddate = TiendaHelperBase::local_to_GMT_data(date_format($date_tmp, 'Y-m-d H:i:s'));
     while ($curdate < $enddate) {
         // set working variables
         $variables = TiendaHelperBase::setDateVariables($curdate, $enddate, 'daily');
         $thisdate = $variables->thisdate;
         $nextdate = $variables->nextdate;
         $query = new TiendaQuery();
         $query->select('COUNT(tbl.order_id) AS num, SUM(order_total) AS amount');
         $query->from('#__tienda_orders AS tbl');
         $query->where("tbl.order_state_id IN (" . $this->getStatesCSV() . ")");
         $query->where("tbl.modified_date >= '" . $curdate . "'");
         $query->where("tbl.modified_date <= '" . $nextdate . "'");
         $database->setQuery((string) $query);
         $return_daily_report = $database->loadObject();
         $date_tmp = date_create(TiendaHelperBase::GMT_to_local_data($curdate));
         $data_print = date_format($date_tmp, 'd-m-Y');
         $return_range_report->{$data_print} = $return_daily_report;
         // increase curdate to the next value
         $curdate = $nextdate;
     }
     return $return_range_report;
 }
Exemplo n.º 9
0
 /**
  * First stores the record
  * Then checks if it should be the default
  *
  * @see tienda/admin/tables/TiendaTable#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 TiendaQuery();
             $query->update("#__tienda_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;
 }
Exemplo n.º 10
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 TiendaQuery();
     $query->select("tbl.wishlistitem_id");
     $query->from('#__tienda_wishlistitems AS tbl');
     $query->where("tbl.product_id = " . (int) $product_id);
     if (strtolower($xref_type) == 'session') {
         $query->where("tbl.session_id = " . $this->_db->Quote($xref_id));
     } else {
         $query->where("tbl.user_id = " . (int) $xref_id);
     }
     if (!empty($attributes)) {
         $query->where("tbl.product_attributes = " . $this->_db->Quote($attributes));
     }
     $db = $this->getDBO();
     $db->setQuery((string) $query);
     if ($result = $db->loadResult()) {
         return $result;
     }
     return false;
 }
Exemplo n.º 11
0
 /**
  * Builds a generic SELECT COUNT(*) query
  */
 protected function _buildResultQuery()
 {
     $grouped_query = new TiendaQuery();
     $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 TiendaQuery();
     $query->select('COUNT(*)');
     $query->from('(' . $grouped_query . ') as grouped_count');
     // Allow plugins to edit the query object
     $suffix = ucfirst($this->getName());
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterBuildResultQuery' . $suffix, array(&$query));
     return $query;
 }
Exemplo n.º 12
0
 /**
  * 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)
 {
     Tienda::load('TiendaQuery', 'library.query');
     $taxrate = "0.00000";
     $db = JFactory::getDBO();
     $query = new TiendaQuery();
     $query->select('tbl.*');
     $query->from('#__tienda_taxrates AS tbl');
     $query->join('LEFT', '#__tienda_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;
 }
Exemplo n.º 13
0
 /**
  * Dedicated function for eav fields filtering
  * @param TiendaQuery $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
                 Tienda::load("TiendaHelperBase", 'helpers._base');
                 $eav_helper = TiendaHelperBase::getInstance('Eav');
                 $table_type = $eav_helper->getType($attribute_alias);
                 // Join the tables
                 $query->join('LEFT', '#__tienda_eavattributes AS ' . $eav_tbl_name . ' ON tbl.' . $tbl_key . ' = ' . $eav_tbl_name . '.eaventity_id');
                 $query->join('LEFT', '#__tienda_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}'");
             }
         }
     }
 }
Exemplo n.º 14
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.º 15
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();
     $date->setOffset(-JFactory::getConfig()->getValue('config.offset'));
     $today = $date->toFormat("%Y-%m-%d");
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $q->select('s.*');
     $q->from('`#__tienda_productissues` tbl');
     $q->join('left', '`#__tienda_subscriptions` s ON s.`product_id` = tbl.`product_id`');
     $q->join('left', '`#__tienda_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();
 }
Exemplo n.º 16
0
 static function getNumberIssues($product_id, $start_date = null, $end_date = null)
 {
     $db = JFactory::getDbo();
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $q->select('count( tbl.`product_issue_id` ) ');
     $q->from('`#__tienda_productissues` tbl');
     $q->where('tbl.`product_id`=' . $product_id);
     if ($start_date === null) {
         $date = JFactory::getDate();
         $date->setOffset(-JFactory::getConfig()->getValue('config.offset'));
         $start_date = $date->toFormat("%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();
 }
Exemplo n.º 17
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];
     }
     Tienda::load('TiendaQuery', 'library.query');
     $db = JFactory::getDbo();
     $q = new TiendaQuery();
     $q->select(array('tax_rate_id', 'geozone_id', 'tax_class_id', 'tax_rate', 'tax_rate_description', 'level'));
     $q->from('#__tienda_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];
 }
Exemplo n.º 18
0
 /**
  * Returns the tax rate for an item
  * @param int $geozone_id
  * @return int
  */
 protected function getTaxRate($geozone_id)
 {
     $tax_class_id = $this->params->get('taxclass');
     $taxrate = "0.00000";
     $db = JFactory::getDBO();
     Tienda::load('TiendaQuery', 'library.query');
     $query = new TiendaQuery();
     $query->select('tbl.tax_rate');
     $query->from('#__tienda_taxrates AS tbl');
     $query->where('tbl.tax_class_id = ' . $tax_class_id);
     $query->where('tbl.geozone_id = ' . $geozone_id);
     $db->setQuery((string) $query);
     if ($data = $db->loadResult()) {
         $taxrate = $data;
     }
     return $taxrate;
 }
Exemplo n.º 19
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 = TiendaHelperBase::getToday();
     $q = new TiendaQuery();
     $q->select('tbl.created_date AS date');
     $q->from('#__tienda_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;
 }
Exemplo n.º 20
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.º 21
0
 /**
  * Processes the response from Unex
  * @param $response
  * @return boolean 
  */
 protected function processResponse($response)
 {
     if (property_exists($response, 'ShipmentResponse')) {
         $response = $response->ShipmentResponse->RatedShipment;
     } else {
         return false;
     }
     if (!is_array($response)) {
         $temp = $response;
         $reply_details = array();
         $reply_details[] = $temp;
     } else {
         $reply_details = $response;
     }
     $i = 0;
     foreach ($reply_details as $details) {
         $serviceType = $details->Service->Code;
         $rate_details = $details->EstimatedCharges;
         $model = JModel::getInstance('UnexServices', 'TiendaModel');
         $model->setState('filter_code', (string) $serviceType);
         $service = $model->getList();
         $service = $service[0];
         $rateName = JText::_($service->service_name);
         // Tax rate
         $tax_class_id = Tienda::getInstance()->get('shipping_tax_class', '1');
         $geozone_id = $this->geozone_id;
         Tienda::load('TiendaQuery', 'library.query');
         $taxrate = "0.00000";
         $db = JFactory::getDBO();
         $query = new TiendaQuery();
         $query->select('tbl.*');
         $query->from('#__tienda_taxrates AS tbl');
         $query->where("tbl.tax_class_id = '" . $tax_class_id . "'");
         $query->where("tbl.geozone_id = '" . $geozone_id . "'");
         $db->setQuery((string) $query);
         if ($data = $db->loadObject()) {
             $taxrate = $data->tax_rate;
         }
         $summary = array();
         $summary['name'] = $rateName;
         $summary['code'] = $serviceType;
         $summary['price'] = (double) $rate_details->BaseCharge;
         $summary['extra'] = (double) $rate_details->OptionsCharges + (double) $rate_details->SupplementsCharges;
         $summary['tax'] = (double) $rate_details->TotalCharges * ($taxrate / 100);
         $summary['total'] = (double) $rate_details->TotalCharges + $summary['tax'];
         $this->rates[] = $summary;
     }
     return true;
 }
Exemplo n.º 22
0
 function _getDateDb($start_date, $end_date, $restrict_start = false, $restrict_end = false, $count_days = true)
 {
     $db = JFactory::getDbo();
     $q = new TiendaQuery();
     $q->select('COUNT(*) AS num');
     $q->select('SUM(order_total) AS amount');
     $q->select('AVG(order_total) AS average');
     if ($count_days) {
         $q->select("DATEDIFF('{$end_date}','{$start_date}') AS days_in_business");
     }
     $q->from('#__tienda_orders AS tbl');
     $q->where("tbl.order_state_id IN (" . $this->getStatesCSV() . ")");
     if ($restrict_end) {
         $q->where("tbl.created_date < '{$end_date}'");
     }
     if ($restrict_start) {
         $q->where("tbl.created_date >= '{$start_date}'");
     }
     $db->setQuery((string) $q);
     return $db->loadObject();
 }
Exemplo n.º 23
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.º 24
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;
     }
     Tienda::load('TiendaHelperProduct', '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 TiendaQuery class exist
     if (!class_exists('TiendaQuery')) {
         Tienda::load('TiendaQuery', 'library.query');
     }
     //get the attributes of the current products
     $query = new TiendaQuery();
     $query->select('tbl.product_id');
     $query->select('tbl.productattribute_name');
     $query->select('tbl.productattribute_id');
     $query->from('#__tienda_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 = TiendaHelperProduct::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, 'tienda_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;
 }
Exemplo n.º 25
0
 function view($cachable = false, $urlparams = false)
 {
     $model = $this->getModel($this->get('suffix'));
     $model->getId();
     $row = $model->getItem();
     $view = $this->getView($this->get('suffix'), 'html');
     $view->setModel($model, true);
     $view->assign('row', $row);
     $view->setLayout('view');
     $orderstates_csv = Tienda::getInstance()->get('orderstates_csv', '2, 3, 5, 17');
     $orderstates_array = explode(',', $orderstates_csv);
     //Get Data From OrdersItems Model
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $modelOrders = JModel::getInstance('Orders', 'TiendaModel');
     $modelOrders->setState('filter_userid', $row->id);
     $modelOrders->setState('order', 'tbl.created_date');
     $modelOrders->setState('direction', 'DESC');
     $modelOrders->setState('filter_orderstates', $orderstates_array);
     $allorders = $modelOrders->getList();
     $modelOrders->setState('limit', '5');
     $lastfiveorders = $modelOrders->getList(true);
     $view->assign('orders', $lastfiveorders);
     $spent = 0;
     foreach ($allorders as $orderitem) {
         $spent += $orderitem->order_total;
     }
     $view->assign('spent', $spent);
     //Get Data From Carts Model
     $modelCarts = JModel::getInstance('Carts', 'TiendaModel');
     $modelCarts->setState('filter_user', $row->id);
     $carts = $modelCarts->getList();
     $view->assign('carts', $carts);
     $total_cart = 0;
     foreach (@$carts as $cart) {
         $cart->total_price = $cart->product_price * $cart->product_qty;
         $total_cart += $cart->total_price;
     }
     $view->assign('total_cart', $total_cart);
     //Subcription Data
     $modelSubs = JModel::getInstance('subscriptions', 'TiendaModel');
     $modelSubs->setState('filter_userid', $row->id);
     $modelSubs->setState('filter_enabled', 1);
     $modelOrders->setState('limit', '5');
     $subs = $modelSubs->getList();
     $view->assign('subs', $subs);
     //Get Data from Productcomments Model and left join to products
     $database = $model->getDbo();
     Tienda::load('TiendaQuery', 'library.query');
     $query = new TiendaQuery();
     $query->select('tbl.*');
     $query->select('substring(tbl.productcomment_text, 1, 250) AS trimcom');
     $query->from('#__tienda_productcomments AS tbl');
     $query->select('p.product_name AS p_name');
     $query->join('LEFT', '#__tienda_products AS p ON p.product_id = tbl.product_id');
     $query->where("tbl.user_id='{$row->id}'");
     $database->setQuery((string) $query);
     $procoms = $database->loadObjectList();
     $view->assign('procoms', $procoms);
     $model->emptyState();
     $this->_setModelState();
     $surrounding = $model->getSurrounding($model->getId());
     $view->assign('surrounding', $surrounding);
     $view->setTask(true);
     $view->display();
     $this->footer();
     return;
 }
Exemplo n.º 26
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();
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $start_id = Tienda::getGuestIdStart();
     $q->select('min( tbl.user_id)');
     $q->from('#__tienda_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
 }
Exemplo n.º 27
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.º 28
0
 function getNewCustomFieldsID()
 {
     $return = false;
     Tienda::load('TiendaQuery', 'library.query');
     $query = new TiendaQuery();
     $query->select('max(tbl.cartitem_customfields_id) as customfields_id');
     $query->from('#__tienda_carts AS tbl');
     $db = JFactory::getDBO();
     $db->setQuery((string) $query);
     $cart = $db->loadObject();
     if (empty($cart->customfields_id)) {
         return 1;
     }
     if ($cart->customfields_id >= 0) {
         $return = $cart->customfields_id + 1;
     }
     return $return;
 }
Exemplo n.º 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;
     Tienda::load('TiendaQuery', 'library.query');
     $db = JFactory::getDBO();
     if ($tax_class_id === null) {
         $q = new TiendaQuery();
         $q->select('tax_class_id');
         $q->from('#__tienda_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 TiendaQuery();
         $q->select('tax_class_id, tax_rate_id, tax_rate, tax_rate_description, level ');
         $q->from('#__tienda_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;
 }
Exemplo n.º 30
0
 public static function calculateProductAttributeProperty(&$product, $attributes, $product_price, $product_weight)
 {
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper_product = TiendaHelperBase::getInstance('Product');
     // first we get rid off phantom attributes (the ones that should be hidden because their parent attribute was just unselected)
     $attr_base = TiendaHelperProduct::getAttributes($product->product_id, array_merge($attributes, array('0')));
     $attr_final = TiendaHelperProduct::getDefaultAttributeOptions($attr_base);
     foreach ($attr_final as $key => $value) {
         if (isset($attributes['attribute_' . $key])) {
             $attr_final[$key] = $attributes['attribute_' . $key];
         }
     }
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $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('`#__tienda_productattributeoptions` tbl');
     $q->join('left', '`#__tienda_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);
 }