/** * Dedicated function for eav fields filtering * @param CitruscartQuery $query */ protected function _buildQueryEav(&$query) { $eavStates = $this->getEavState()->getProperties(); // If there are eav states set if (count($eavStates)) { // Loop through the filters foreach ($eavStates as $k => $v) { $filter_prefix = 'filter_'; // Is it a filter? if (strpos($k, $filter_prefix) === 0) { // Different table name for different joins! // alias on which we want to filter $attribute_alias = substr($k, strlen($filter_prefix)); $tbl_key = $this->getTable()->getKeyName(); $eav_tbl_name = 'eav_' . $attribute_alias; $value_tbl_name = 'value_' . $attribute_alias; // Join the table based on the type of the value Citruscart::load("CitruscartHelperBase", 'helpers._base'); $eav_helper = CitruscartHelperBase::getInstance('Eav'); $table_type = $eav_helper->getType($attribute_alias); // Join the tables $query->join('LEFT', '#__citruscart_eavattributes AS ' . $eav_tbl_name . ' ON tbl.' . $tbl_key . ' = ' . $eav_tbl_name . '.eaventity_id'); $query->join('LEFT', '#__citruscart_eavvalues' . $table_type . ' AS ' . $value_tbl_name . ' ON ' . $eav_tbl_name . '.eavattribute_id = ' . $value_tbl_name . '.eavattribute_id'); // Filter using '=' $query->where($eav_tbl_name . ".eavattribute_alias = '{$attribute_alias}'"); $query->where($value_tbl_name . ".eavvalue_value = '{$v}'"); } } } }
/** * Gets list of all subscriptions by issue x-days before expiring * * @$days Number of days before expiring (0 stands for expired now) * * @return List of subscriptions by issue */ public function getListByIssues($days = 0) { $db = $this->getDBO(); $date = JFactory::getDate(); $tz = JFactory::getConfig()->get('offset'); $date->setTimezone(new DateTimeZone($tz)); //here! $today = $date->format("%Y-%m-%d"); Citruscart::load('CitruscartQuery', 'library.query'); $q = new CitruscartQuery(); $q->select('s.*'); $q->from('`#__citruscart_productissues` tbl'); $q->join('left', '`#__citruscart_subscriptions` s ON s.`product_id` = tbl.`product_id`'); $q->join('left', '`#__citruscart_orderitems` oi ON s.`orderitem_id` = oi.`orderitem_id`'); $q->where('s.`subscription_enabled` = 1'); $q->where('oi.`subscription_period_unit` = \'I\''); if ($days) { $query = " SELECT DATE_ADD('" . $today . "', INTERVAL '.{$days}.' DAY) "; $db->setQuery($query); $date = Date('Y-m-d', strtotime($db->loadResult())); } else { $date = $today; } $q->where('DATE_FORMAT( tbl.`publishing_date`, \'%Y-%m-%d\' ) = \'' . $date . '\''); $db->setQuery((string) $q); return $db->loadObjectList(); }
/** * Returns the tax rate for an item * * @param int $shipping_method_id * @param int $geozone_id * @return int */ protected function getTaxRate($shipping_method_id, $geozone_id) { Citruscart::load('CitruscartQuery', 'library.query'); $taxrate = "0.00000"; $db = JFactory::getDBO(); $query = new CitruscartQuery(); $query->select('tbl.*'); $query->from('#__citruscart_taxrates AS tbl'); $query->join('LEFT', '#__citruscart_shippingmethods AS shippingmethod ON shippingmethod.tax_class_id = tbl.tax_class_id'); $query->where('shippingmethod.shipping_method_id = ' . $shipping_method_id); $query->where('tbl.geozone_id = ' . $geozone_id); $db->setQuery((string) $query); if ($data = $db->loadObject()) { $taxrate = $data->tax_rate; } return $taxrate; }
/** * Method to get if user has multiple user group * @return array */ private function getUserGroups() { $user = JFactory::getUser(); $database = JFactory::getDBO(); Citruscart::load('CitruscartQuery', 'library.query'); $query = new CitruscartQuery(); $query->select('tbl.group_id'); $query->from('#__citruscart_usergroupxref AS tbl'); $query->join('INNER', '#__citruscart_groups AS g ON g.group_id = tbl.group_id'); $query->where("tbl.user_id = " . (int) $user->id); $query->order('g.ordering ASC'); $database->setQuery((string) $query); return $database->loadColumn(); }
public static function calculateProductAttributeProperty(&$product, $attributes, $product_price, $product_weight) { Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper_product = CitruscartHelperBase::getInstance('Product'); // first we get rid off phantom attributes (the ones that should be hidden because their parent attribute was just unselected) $attr_base = CitruscartHelperProduct::getAttributes($product->product_id, array_merge($attributes, array('0'))); $attr_final = CitruscartHelperProduct::getDefaultAttributeOptions($attr_base); foreach ($attr_final as $key => $value) { if (isset($attributes['attribute_' . $key])) { $attr_final[$key] = $attributes['attribute_' . $key]; } } Citruscart::load('CitruscartQuery', 'library.query'); $q = new CitruscartQuery(); $q->select('tbl.`productattributeoption_price` , tbl.`productattributeoption_prefix`, tbl.`productattributeoption_id` '); $q->select('tbl.`productattributeoption_code`, tbl.`productattributeoption_weight`, tbl.`productattributeoption_prefix_weight`'); $q->from('`#__citruscart_productattributeoptions` tbl'); $q->join('left', '`#__citruscart_productattributes` atr ON tbl. productattribute_id = atr.productattribute_id'); $q->where("tbl.productattributeoption_id IN ('" . implode("', '", $attr_final) . "')"); $q->order('atr.ordering ASC'); $db = JFactory::getDbo(); $db->setQuery($q); $res = $db->loadObjectList(); $attributes = array(); for ($i = 0, $c = count($res); $i < $c; $i++) { // update product price // is not + or - if ($res[$i]->productattributeoption_prefix == '=') { $product->{$product_price} = floatval($res[$i]->productattributeoption_price); } else { $product->{$product_price} = $product->{$product_price} + floatval($res[$i]->productattributeoption_prefix . $res[$i]->productattributeoption_price); } // update product weight if ($res[$i]->productattributeoption_prefix_weight == '=') { $product->{$product_weight} = floatval($res[$i]->productattributeoption_weight); } else { $product->{$product_weight} = $product->{$product_weight} + floatval($res[$i]->productattributeoption_prefix_weight . $res[$i]->productattributeoption_weight); } $attributes[] = $res[$i]->productattributeoption_id; } $product->sku = self::getProductSKU($product, $attributes); }