Show products from subcategories

03.09.2011 13:31
#1
mavik
Joomshopping forum user no avatar
Name: mavik
22.07.2011
Posts: 1
Quote
Show products from subcategories

I need show products from category with all subcategories.
I did it this way:

In file tables/category.php

FIND (about line 173):

$query = "SELECT prod.product_id, categ.category_id, prod.`".$lang->get('name')."` as name, prod.`".$lang->get('short_description')."` as short_description, prod.product_ean, prod.product_thumb_image, prod.product_price, prod.product_tax_id as tax_id, prod.product_old_price, prod.product_weight, prod.average_rating, prod.reviews_count, prod.hits, prod.weight_volume_units, prod.basic_price_unit_id, prod.label_id, prod.product_manufacturer_id, prod.product_weight, prod.min_price, prod.product_quantity, prod.different_prices $adv_result
FROM `#__jshopping_products` AS prod
LEFT JOIN `#__jshopping_products_to_categories` AS categ USING (product_id)
$adv_from
WHERE categ.category_id = '".$this->_db->getEscaped($this->category_id)."' AND prod.product_publish = '1' ".$adv_query;

REPLACE TO:

$categories = $this->getAllSubcatogories($this->category_id);
$query = "SELECT prod.product_id, max(categ.category_id) as category_id, prod.`".$lang->get('name')."` as name, prod.`".$lang->get('short_description')."` as short_description, prod.product_ean, prod.product_thumb_image, prod.product_price, prod.product_tax_id as tax_id, prod.product_old_price, prod.product_weight, prod.average_rating, prod.reviews_count, prod.hits, prod.weight_volume_units, prod.basic_price_unit_id, prod.label_id, prod.product_manufacturer_id, prod.product_weight, prod.min_price, prod.product_quantity, prod.different_prices $adv_result
FROM `#__jshopping_products` AS prod
LEFT JOIN `#__jshopping_products_to_categories` AS categ USING (product_id)
$adv_from
WHERE categ.category_id IN ($categories) AND prod.product_publish = '1' GROUP BY prod.product_id ".$adv_query;

FIND (about line 222):

$query = "SELECT count(pr_cat.product_id) FROM `#__jshopping_products_to_categories` AS pr_cat
INNER JOIN `#__jshopping_products` AS prod ON pr_cat.product_id = prod.product_id
WHERE pr_cat.category_id = '".$this->_db->getEscaped($this->category_id)."' ".$adv_query;

REPLACE TO:

$categories = $this->getAllSubcatogories($this->category_id);
$query = "SELECT count(DISTINCT prod.product_id) FROM `#__jshopping_products_to_categories` AS pr_cat
LEFT JOIN `#__jshopping_products` AS prod ON pr_cat.product_id = prod.product_id
WHERE pr_cat.category_id IN ($categories) ".$adv_query;

BEFORE
}
?>
ADD

/*
* Get category id with all subcategories ids
*/
function getAllSubcatogories($id) {
$categories = array();
$newCategories = array($id);
do {
$categories = array_merge($categories, $newCategories);
$categoriesStr = implode(',', $newCategories);
$query = "SELECT category_id FROM #__jshopping_categories WHERE category_parent_id IN ($categoriesStr)";
$this->_db->setQuery($query);
$newCategories = $this->_db->loadResultArray();
} while (!empty($newCategories));
return implode(',', $categories);
}

In file controller/category.php

FIND

addLinkToProducts($products, $category_id);

REPLACE TO

addLinkToProducts($products);

for links to categories of products.


Can you add showing of products from subcategories in future versions?


Joomla: 1.7
JoomShopping: 3.2.6
 
05.02.2013 11:18
#2
9intro
Joomshopping forum user no avatar
Name: 9intro
08.11.2011
Posts: 9
Quote
Aw: Show products from subcategories

Searching over the net to do the same thing I found this post and also I found a plugin that does the same thing and it does very well. The name of this plugin is "JoomShopping - Product To Parent Category" and I found it on the Joomla Extensions directory. However the links for download it and the author's website are broken, but finally I found it in the next link:
http://www.tsikoliya.ru/internet-kommertsiya-joomla/2200-joomshopping-product-to-parent-category.html

Also I will attach the .zip containing the plugin in this post because I consider that it would be helpful to have this here if someone see this post in the future.
Ah, I forget to say that this extension is for Joomla 2.5. And also I leave here a link if anyone wants to see how is working it on the website that I'm doing now:
http://www.musicpasion.com/
addon_jshopping_product_to_parent_category_v.3.72.1.5.zip


Letzte Änderung: 05.02.2013 11:22
 
27.06.2013 20:51
#3
anderscarlen
Joomshopping forum user no avatar
Name: Anders Carlén
25.06.2013
Posts: 2
Quote
Aw: Show products from subcategories

Thank you! This post helps a lot!

(I still think this feature should be included in JoomShopping from the start, possibly with the option of turning it on/off. )

 


Copyrights MAXXmarketing GmbH. All Rights Reserved
Durch die Nutzung dieser Website stimme ich zu, dass Cookies zur optimalen Gestaltung der Website sowie zur Analyse der Nutzung der Website verwendet werden. Weiterführende Informationen finden Sie hier. OK, einverstanden.