public function getRelatedProduct($product_id = 0, $related_id = 0) { $helper = new redhelper(); $and = ""; $orderby = "ORDER BY p.product_id ASC "; $orderby_related = ""; if (DEFAULT_RELATED_ORDERING_METHOD) { $orderby = "ORDER BY " . DEFAULT_RELATED_ORDERING_METHOD; $orderby_related = ""; } if ($product_id != 0) { // Sanitize ids $productIds = explode(',', $product_id); JArrayHelper::toInteger($productIds); if ($helper->isredProductfinder()) { $q = "SELECT extrafield FROM #__redproductfinder_types where type_select='Productfinder datepicker'"; $this->_db->setQuery($q); $finaltypetype_result = $this->_db->loadObject(); } else { $finaltypetype_result = array(); } $and .= "AND r.product_id IN (" . implode(',', $productIds) . ") "; if (TWOWAY_RELATED_PRODUCT) { if (DEFAULT_RELATED_ORDERING_METHOD == "r.ordering ASC" || DEFAULT_RELATED_ORDERING_METHOD == "r.ordering DESC") { $orderby = ""; $orderby_related = "ORDER BY " . DEFAULT_RELATED_ORDERING_METHOD; } $InProduct = ""; $query = "SELECT * FROM " . $this->_table_prefix . "product_related AS r " . "WHERE r.product_id IN (" . implode(',', $productIds) . ") OR r.related_id IN (" . implode(',', $productIds) . ")" . $orderby_related . ""; $this->_db->setQuery($query); $list = $this->_db->loadObjectlist(); $relatedArr = array(); for ($i = 0; $i < count($list); $i++) { if ($list[$i]->product_id == $product_id) { $relatedArr[] = $list[$i]->related_id; } else { $relatedArr[] = $list[$i]->product_id; } } if (empty($relatedArr)) { return array(); } // Sanitize ids JArrayHelper::toInteger($relatedArr); $relatedArr = array_unique($relatedArr); $query = "SELECT " . $product_id . " AS mainproduct_id,p.* " . "FROM " . $this->_table_prefix . "product AS p " . "WHERE p.published = 1 "; $query .= ' AND p.product_id IN (' . implode(", ", $relatedArr) . ') '; $query .= $orderby; $this->_db->setQuery($query); $list = $this->_db->loadObjectlist(); return $list; } } if ($related_id != 0) { $and .= "AND r.related_id = " . (int) $related_id . " "; } if (count($finaltypetype_result) > 0 && $finaltypetype_result->extrafield != '' && (DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt ASC' || DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt DESC')) { $add_e = ",e.*"; } else { $add_e = " "; } $query = "SELECT r.product_id AS mainproduct_id,p.* " . $add_e . " " . "FROM " . $this->_table_prefix . "product_related AS r " . "LEFT JOIN " . $this->_table_prefix . "product AS p ON p.product_id = r.related_id "; if (count($finaltypetype_result) > 0 && $finaltypetype_result->extrafield != '' && (DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt ASC' || DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt DESC')) { $query .= " LEFT JOIN " . $this->_table_prefix . "fields_data AS e ON p.product_id = e.itemid "; } $query .= " WHERE p.published = 1 "; if (count($finaltypetype_result) > 0 && $finaltypetype_result->extrafield != '' && (DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt ASC' || DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt DESC')) { $query .= " AND e.fieldid = " . (int) $finaltypetype_result->extrafield . " AND e.section=17 "; } $query .= " {$and} GROUP BY r.related_id "; if (DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt ASC' || DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt DESC') { if (DEFAULT_RELATED_ORDERING_METHOD == 'e.data_txt ASC') { $s = "STR_TO_DATE( e.data_txt, '%d-%m-%Y' ) ASC"; } else { $s = "STR_TO_DATE( e.data_txt, '%d-%m-%Y' ) DESC"; } $query .= " ORDER BY " . $s; } else { $query .= " {$orderby} "; } $this->_db->setQuery($query); $list = $this->_db->loadObjectlist(); return $list; }
public function getredproductfindertags() { global $context; $app = JFactory::getApplication(); $setproductfinderobj = new redhelper(); $setproductfinder = $setproductfinderobj->isredProductfinder(); $finder_condition = ""; if ($setproductfinder) { $query = "SELECT id FROM #__redproductfinder_filters WHERE published=1"; $this->_db->setQuery($query); $rs_filters = $this->_db->loadResultArray(); if (count($rs_filters) > 0) { $this->_is_filter_enable = true; } $tag = ''; for ($f = 0; $f < count($rs_filters); $f++) { $tmp_tag = $app->getUserStateFromRequest($context . 'tag' . $rs_filters[$f], 'tag' . $rs_filters[$f], ''); if (is_array($tmp_tag)) { $tag = $tmp_tag; } elseif ($tmp_tag != "" && $tmp_tag != "0") { $tag[] = $tmp_tag; } } $finder_where = ""; $finder_query = ""; $finder_condition = ""; $findercomponent = JComponentHelper::getComponent('com_redproductfinder'); $productfinderconfig = new JRegistry($findercomponent->params); $finder_filter_option = $productfinderconfig->get('redshop_filter_option'); if ($tag) { if (is_array($tag)) { if (count($tag) > 1 || $tag[0] != 0) { $finder_query = "SELECT product_id FROM #__redproductfinder_associations AS a,#__redproductfinder_association_tag AS at "; $finder_where = ""; if (count($tag) > 1) { $i = 1; for ($t = 1; $t < count($tag); $t++) { $finder_query .= " LEFT JOIN #__redproductfinder_association_tag AS at" . $t . " ON at" . $t . ".association_id=at.association_id"; $finder_where[] = " at" . $t . ".tag_id = " . (int) $tag[$t] . " "; $i++; } } $finder_query .= " WHERE a.id = at.association_id AND at.tag_id = " . (int) $tag[0] . " "; if (is_array($finder_where)) { $finder_where = " AND " . implode(" AND ", $finder_where); } $finder_query .= $finder_where; $this->_db->setQuery($finder_query); $rs = $this->_db->loadResultArray(); $finder_products = ""; if (!empty($rs)) { // Sanitise ids JArrayHelper::toInteger($rs); $finder_products = implode("','", $rs); } $finder_condition = " AND p.product_id IN('" . $finder_products . "')"; $this->_is_filter_enable = true; } if (count($tag) == 1 && $tag[0] == 0) { $finder_condition = ""; } } $finder_condition; } } return $finder_condition; }