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; }
/** * 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; }
/** * 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; }
/** * 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]; }
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); }
/** * 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; }
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); }
/** * 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; }
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; }
/** * 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 }
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; }
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); }
/** * 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; }
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(); }
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(); }
public static function taxratespredecessors($selected, $name = 'level', $tax_class_id = null, $geozone_id = null, $tax_type = null, $attribs = array('class' => 'inputbox'), $idtag = null) { $list = array(); $list[] = self::option(0, JText::_('COM_TIENDA_ROOT')); $db = JFactory::getDbo(); Tienda::load('TiendaQuery', 'library.query'); $q = new TiendaQuery(); $q->select(array('level', 'tax_rate_description')); $q->from('#__tienda_taxrates'); if ($tax_class_id) { $q->where('tax_class_id = ' . (int) $tax_class_id); } if ($geozone_id) { $q->where('geozone_id = ' . (int) $tax_class_id); } $q->order('level ASC, tax_rate_description'); $db->setQuery($q); $items = $db->loadObjectList(); $spaces = ''; $last_level = -1; for ($i = 0, $c = count($items); $i < $c; $i++) { $item = $items[$i]; if ($item->level != $last_level) { $spaces .= '-'; } $list[] = self::option($item->level + 1, $spaces . ' ' . $item->tax_rate_description); $last_level = $item->level; } return self::genericlist($list, $name, $attribs, 'value', 'text', $selected, $idtag); }
/** * * Method to get product categories. * @param int $id - product id * @return string */ function _getCategoryName($id) { Tienda::load('TiendaQuery', 'library.query'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $table = JTable::getInstance('ProductCategories', 'TiendaTable'); $query = new TiendaQuery(); $query->select("c.category_name"); $query->from($table->getTableName() . " AS tbl"); $query->where("tbl.product_id = " . (int) $id); $query->join('LEFT', '#__tienda_categories AS c ON tbl.category_id = c.category_id'); $db = JFactory::getDBO(); $db->setQuery((string) $query); $items = $db->loadResultArray(); $name = ""; if (!empty($items)) { $name = implode(" | ", $items); } return $name; }
/** * 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; }
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]; }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * Method to get if user has multiple user group * @return array */ private function getUserGroups() { $user = JFactory::getUser(); $database = JFactory::getDBO(); Tienda::load('TiendaQuery', 'library.query'); $query = new TiendaQuery(); $query->select('tbl.group_id'); $query->from('#__tienda_usergroupxref AS tbl'); $query->join('INNER', '#__tienda_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->loadResultArray(); }
/** * 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; }
function getCouponProductIds($coupon_id) { Tienda::load('TiendaQuery', 'library.query'); $query = new TiendaQuery(); $query->select('product_id'); $query->from('#__tienda_productcouponxref'); $query->where('coupon_id = ' . (int) $coupon_id); $db = JFactory::getDBO(); $db->setQuery($query); return $db->loadResultArray(); }
/** * * 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; }
/** * 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; }
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; }
public function getDefault() { $query = new TiendaQuery(); $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]; }