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 get the categories based on the current view * @return array */ function getCategories() { $items = array(); //filter category found so we display child categories and products inside if (!empty($this->_filter_category) && $this->_params->get('filter_category')) { //get categories with parent_id = filter_category or category_id = filter_category Tienda::load('TiendaQuery', 'library.query'); $query = new TiendaQuery(); $query->select('tbl.*'); $query->where('tbl.parent_id = ' . (int) $this->_filter_category . ' OR tbl.category_id = ' . (int) $this->_filter_category); $query->where('tbl.category_enabled = \'1\''); $query->from('#__tienda_categories AS tbl'); $query->order('tbl.ordering, tbl.category_name'); $this->_db->setQuery((string) $query); $items = $this->_db->loadObjectList(); if (!empty($items)) { $this->_catfound = true; $catids = array(); $total = 0; foreach ($items as $item) { //get current category object if ($item->category_id == $this->_filter_category) { //set the current category $this->category_current = $item; } else { $pmodel = JModel::getInstance('Products', 'TiendaModel'); $pmodel->setState('filter_category', $item->category_id); //make sure that it is enabled $pmodel->setState('filter_enabled', '1'); //make sure the product is available $pmodel->setState('filter_quantity_from', '1'); //add filters from user session $pmodel->setState('filter_attribute_set', $this->_filter_attribute_set); $pmodel->setState('filter_price_from', $this->_filter_price_from); $pmodel->setState('filter_price_to', $this->_filter_price_to); $pmodel->setState('filter_rating', $this->_filter_rating); if ($this->_multi_mode) { $pmodel->setState('filter_manufacturer_set', $this->_filter_manufacturer_set); } else { $pmodel->setState('filter_manufacturer', $this->_filter_manufacturer); } $item->product_total = $pmodel->getTotal(); $item->link = $this->_link . '&filter_category=' . $item->category_id . '&Itemid=' . $this->_itemid; $total = $total + $item->product_total; } } $this->_trackcatcount = $total; } } return $items; }
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; }
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]; }
/** * 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; }
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); }
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 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(); }
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]; }