News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to hide child products

Started by Georgios Kolomvos, June 08, 2012, 18:31:30 PM

Previous topic - Next topic

Florentp

Quote from: cloudti on August 31, 2012, 20:17:34 PM

Please, could someone have a solution for child count result in the search result page?

Thanks

Same needs for me :)

I think there is no way to fix that directly on the template.
Someone know which file return products ?
We just have to add a condition to the sql query, something like "WHERE product_parent_id LIKE '0'"
Web programmer. Passionate.
PHP, SQL, Javascript, JQuery, css.
Skype : florent.indienboutique

klattr1

I am too having this problem. I cannot think of any reason why child products would need to be displayed on the category browse page/layout. The should only be searchable and viewable from the product details page drop-down.

The only way to eliminate child products from being viewable from the category page is to not select a category for which they belong to. But doing that screws up the SEO URL associated for the child products.


PabloArias

Thank you very much gkolomvos! It works perfectly for me in Joomla 2.5.9 and Virtuemart 2.0.18a.

Is there another solution for mod_virtuemart_product that no requires to modify Virtuemart's core files?

Thank you and best regards!
Pablo Arias
www.pabloarias.eu

adamjakab

#19
As for the modification of the category/default.php file it would be cleaner to do this right inside the loop:
if ($product->product_parent_id !== "0") {
//this is a child product
continue;
}


As for the modification of the products module, and hence the modifications of the core VM files, I am against doing that - it is not a good practice and either you will be stuck with current VM version or worse if you by accident update the component you will have all mods gone (with the obvious results).

So, I would suggest to do this(it is even simpler):
mod_virtuemart_product uses template files inside /modules/mod_virtuemart_product/tmpl - and you cannot bring this into your template directory(if you check on the mod_virtuemart_product.xml file you will see why). But you can duplicate the dafault.php file into let's say: mylisting.php
1) open it
NOTE: inside there are two loops: one for the div based and one for the ul/li based visualization. So to make sure let's mod both of them
2) find line "<?php foreach ($products as $product) { ?>" ~@line:25
and insert right after the same break out as before so your code will look like this:

<?php foreach ($products as $product) {
if ($product->product_parent_id !== "0") {continue;}//NO CHILD PRODUCTS
?>


3) find line "<?php foreach ($products as $product) :?>" ~@line:79
and do ita again so your code will look like this:

<?php foreach ($products as $product) :
if ($product->product_parent_id !== "0") {continue;}//NO CHILD PRODUCTS
?>


4) save
5) check
6) enjoy

bunglehaze

#20
Quote from: adamjakab on June 15, 2013, 15:17:33 PM
As for the modification of the category/default.php file it would be cleaner to do this right inside the loop:
if ($product->product_parent_id !== "0") {
//this is a child product
continue;
}




That works perfectly for me. Only a short piece of code to add inside the override - I like K.I.S.S


*** Edited *** Actually there is a problem remaining with items per page displaying incorrectly as it would seem despite being hidden the page is still counting child products on the page - any ideas how to get around this?

for example. I have a category with 4 parent products, in each are 3 child products. if the page is set to display 10 items per page you are shown 3 of them and then have to click next page for the fourth




nmihos

Hello,

I have the same problem. I hide child products but in category view appear only parent products, bun with an issue. The category must show 18 product per page, but sometimes shows 2, sometimes 4, in next page 3, and it seems to count the child products in navigation, but without showing them. Is there a solution for that?

bunglehaze

The only way I have found around this is not to assign child products to a category so the parent still shows in the correct place and it pulls through the child product information. It does make administering child products a little more irritating and less logical for instance you drill down in the backend to a category, find the product(s) you want to edit, click where is says "x number of child products" and the page shows nothing because now you are trying to find child products that are not in that category anymore. To get round this you go back to the category dropdown and just go back to filtering all categories - THEN they show up.

It works, it works well but takes a few more steps to deal with and isn't ideal - but it does work at least.

Jumbo!

#23
In that case, you will have to hack core product model.

Open administrator\components\com_virtuemart\models\product.php

Find the following codes between lines 334 to 336:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}

Replace above by:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
else {
$where[] = ' p.`product_parent_id` = 0';
}

Now this should ignore all child products in all products listing areas including category page.

merlyno79

Quote from: Jumbo! on November 05, 2013, 14:18:03 PM
In that case, you will have to hack core product model.

Open administrator\components\com_virtuemart\models\product.php

Find the following codes between lines 334 to 336:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}

Replace above by:
if ($this->product_parent_id) {
$where[] = ' p.`product_parent_id` = ' . $this->product_parent_id;
}
else {
$where[] = ' p.`product_parent_id` = 0';
}

Now this should ignore all child products in all products listing areas including category page.

ok, but in this way... don't child products disappear from admin products list in VM backend too?

munyiva

Hello,

Thanks alot. I am using Stockable Custom Fields with Custom fields for all and Custom Fields Pro and I  managed to tinker with the various product scripts  to ensure that the child products are counted in each category but are not returned in search and category pages only the parent products are returned.

Files I tinkered with are:
templates\MY_TEMPLATE\html\com_virtuemart\category\default.php
components\com_virtuemart\models\product.php
components\com_customfilters\models\products.php

Thanks again