/** * 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; }
/** * 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(); }
/** * 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}'"); } } } }
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); }
/** * * 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; }
/** * 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(); }