News:

Looking for documentation? Take a look on our wiki

Main Menu

Hide Add to Cart for Parent Product

Started by stargazer1682, August 05, 2020, 04:43:05 AM

Previous topic - Next topic

stargazer1682

I've searched all over for a solution and I can't find one.  I'm building a store in VM 3 and I have a few different products that could be grouped as Parent/Child products.  I've followed the steps for using the Child Variant; and it seems to work for the most part, showing the child items as a drop down selection list on the product page.  However, I have all the products listed using a Category Layout menu item, to display all products; and on that page, the parent item is displayed with the add to cart button and I can't find any option to get rid of it.  Past threads with similar questions have yielded answered suggesting there's supposed to be a box or some setting to make the parent product "unsaleable," but I can't find it.  I'm attaching screen shots from the Generic Child Variant settings, the parent product page child products & custom fields settings tabs, and an example screen shot of how the parent product shows on the category layout page.

In the parent product page, it's presently not showing an add to cart button, but a faded out, barely legible "choose a variant" button.

"Parent orderable" is set to No in the variant settings.  Please tell me what I'm missing?

pinochico

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

stargazer1682

#2
I had already unchecked that option before getting your reply; and the problem is still appearing.
It hadn't actually been checked when I first came across the problem; I tried checking it at one point after looking for any other alternative and still not finding a solution; just to see what it would do - which was to turn on the Add to Cart button on the product page. I hadn't realized it was still marked when I took the screen shot.

Either way, that option is not checked now, as you can see in the updated screen shots, but the add to cart is still appearing in the Category Layout page.

stargazer1682

Would an override of the components\com_virtuemart\sublayouts\prices.php also be an option to modify the add to cart button on those pages?
In my question here (http://forum.virtuemart.net/index.php?topic=145286.0) a developer referred me to that one of the files that might modified to edit how the pricing is displayed on category layout page.  Since the product page works correctly, by substituting the add to cart button with a unresponsive quasi-button that says to make a selection; I was wondering if it would be possible to copy the code that generates the button from the product page and use that to replace the code for the button on the category layout.  That way it would use the same condition of what to generate, depending on whether it was a parent or regular product.

Of course it would be preferable if it was just a setting I could change in the backend; to ensure I don't screw something up in the code.

Studio 42

My plugin should do what you need.
See https://shop.st42.fr/en/products/product-child-variants.htm
If it need a little change,(render or feature) i do it for no extra cost.

pinochico

We use plugin from breakdesign: https://breakdesigns.net/extensions/joomla/custom-fields-for-all

and for parent don't have "Add to Cart", we have button "Select Variant":

https://www.archivbox.cz/archivni-krabice-cz-prior-r007

Because we use everytime together with filtering: https://breakdesigns.net/extensions/joomla/custom-filters
then we don't use core VM solution or solution from some another third party developers.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

stargazer1682

Are there no built in options to address this?  Like I mentioned, the Parent Orderable box was only checked when I was taking the screenshot; and only turned on the Add to Cart button in the product page.  It's unchecked, the button's not shown, but it's always displayed on the Category Layout page; which seems really odd. 
I've come across PHP conditioning to determine whether to show the Add to Cart button or the "Choose a variant" message, which presumably works in the product description page, but apparently whatever code that points to that conditioning on the product page wasn't used for the Category layout.

Is that the long and the short of it?  Are the only two options here third-party plugins or modify the code to hide all of the carts completely in the Category View?

jjk

#7
Quote from: stargazer1682 on August 08, 2020, 01:46:16 AM
Are the only two options here third-party plugins or modify the code to hide all of the carts completely in the Category View?

That's pretty easy by creating a category sublayout with the add-to-cart button commented out:

Find your-root-folder\components\com_virtuemart\sublayouts\products.php and load the file products.php into an editor (Notepad++ for example)
Find these lines (at or near line 126):
<div class="vm3pr-<?php echo $rowsHeight[$row]['customfields'?>"> <?php
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop''addtocart'))); ?>

            
Comment out the button by adding // as in the two lines below:
<div class="vm3pr-<?php// echo $rowsHeight[$row]['customfields'] ?>"> <?php
//echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop', 'addtocart'))); ?>


Save the changed file as products_less-cat-cart-btn.php or a similar filename. Note: The word products_ including the underscore at the begining of the file name is mandatory!

After that you can select this sublayout in the category menu settings > 'Virtuemart category view settings' tab > 'Sublayout for products in category'.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

stargazer1682

Quote from: jjk on August 08, 2020, 07:58:20 AM
Quote from: stargazer1682 on August 08, 2020, 01:46:16 AM
Are the only two options here third-party plugins or modify the code to hide all of the carts completely in the Category View?
That's pretty easy by creating a category sublayout with the add-to-cart button commented out:

Find your-root-folder\components\com_virtuemart\sublayouts\products.php and load the file products.php into an editor (Notepad++ for example)
Find these lines (at or near line 126):
<div class="vm3pr-<?php echo $rowsHeight[$row]['customfields'?>"> <?php
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop''addtocart'))); ?>

            
Comment out the button by adding // as in the two lines below:
<div class="vm3pr-<?php// echo $rowsHeight[$row]['customfields'] ?>"> <?php
//echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop', 'addtocart'))); ?>


Save the changed file as products_less-cat-cart-btn.php or a similar filename. Note: The word products_ including the underscore at the begining of the file name is mandatory!

After that you can select this sublayout in the category menu settings > 'Virtuemart category view settings' tab > 'Sublayout for products in category'.
I had already found the code to hide the add to cart button, but thank you (and also, excellent suggestion on Notepad++. I've only recently heard about it and already love that program)

Hiding the Add to Cart button is more of a last resort (and only if my client doesn't mind it not being there in the Category Layout).  My main question is, isn't there anyway of conditioning the Add to Cart button for the Category Layout page so it doesn't appear for Parent products that aren't set as orderable?  It's a setting in the product description page, why wouldn't that conditioning be used anywhere else for parent items?

Ideally it would be some configurable option in the backend, but I'm not finding anything. (Again, the only option related to this, the box labeled "Parent Orderable", only affects how the button displays (or not displays) on the product description page.

I'd even be happy to identify what line of code the product description page uses to call up the conditioning to either show the Add to Cart button or the "Select a Variant" faux-button; and figure out how to incorporate that into the Category Layout page.  I would assume the change would still be made to sublayouts\products.php, replacing the <div class="vm3pr-<?php echo $rowsHeight[$row]['customfields'?>"> <?php
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop''addtocart'))); ?>
with whatever line of code is used for the product page, but I don't know which file, or for that matter, which line of code defines what to display on the product page.  Since the two pages generate that button differently, I'm assuming the code to get that button (or else, not get that button) is different for the product description page; and if I could use whatever method is used on the Product Page on the Category Layout page, I would again, assume both pages would derive the conditions for if and when to include an Add to Cart button the same way.

jjk

You could experiment with a similar approach as above.

Find your-root-folder\components\com_virtuemart\sublayouts\addtocart.php
and comment out this line (at or near line 60):
echo shopFunctionsF::renderVmSubLayout('addtocartbar',array('product'=>$product));

Then save the file into the same folder as noaddtocart.php

Next find your-root-folder\components\com_virtuemart\views\productdetails\tmpl\default.php
and change (at or near line 175) from:
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$this->product));
to
echo shopFunctionsF::renderVmSubLayout('noaddtocart',array('product'=>$this->product));
and save the file into the same folder as not-available.php   
   
Afterwards you should be able to choose the 'not-available' product template on the product page for the parent product.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

stargazer1682

A few questions about this.  First, are the "noaddtocart.php" and "not-available.php" files two different files?  Initially when I read it, I thought you were saying to put the modified default.php into the same folder as the modified and renamed addtocart.php file, but now I'm not clear if not-available.php is some separate, existing file somewhere.

Would saving the modified default.php in the same folder as the noaddtocart.php create a sort of... special type of override that wouldn't automatically be applied to a product, unless the not-available template is applied?

Where would the not-available template be applied?  Is that something that has to be turned on first in configuration or somewhere?  Maybe something to do with the "Stockhandling" option?  I just found an older thread you replied to, that looks like something similar was done, redirecting specific products to an alternate product page.

The only thing is here though, is that the product page isn't the problem.  The product page is working like it should; instead of the Add to Cart button, it's showing a faux button that says "Choose a Variant".  It's the Category Layout page, where all of the products are listed initially, that any Parent Products are displaying with an Add to Cart button; rather than any type of instruction to proceed to the product page to select one of the options.

pinochico

#11
On the demo I see on category list the Generic Child Product (parent) without Add to Cart button:

http://demo.virtuemart.net/product-variants

Why don't do you setup as the demo?
Is it wrong?

And why don't do you use plugin from breakdesign?
How much time did you waste writing questions on this forum, with setup, testing...?
And how much an hour of your time costs - isn't it more expensive than buying a functional solution right away?

P.S.
Sorry you send a lot of pictures from admin setup, but don't send picture from your eshop from category list and picture how you want...
Maybe we still have to wait for a lot of text posts before that? :)
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

stargazer1682

Quote from: pinochico on August 09, 2020, 01:05:03 AM
On the demo I see on category list the Generic Child Product (parent) without Add to Cart button:

http://demo.virtuemart.net/product-variants

Why don't do you setup as the demo?
Is it wrong?

And why don't do you use plugin from breakdesign?
How much time did you waste writing questions on this forum, with setup, testing...?
And how much an hour of your time costs - isn't it more expensive than buying a functional solution right away?

P.S.
Sorry you send a lot of pictures from admin setup, but don't send picture from your eshop from category list and picture how you want...
Maybe we still have to wait for a lot of text posts before that? :)
That is what I am I asking, what could be turned off that needs to be turned on in order for it not to display in the Category Layout?

I'm not discounting the possibility of buying a plugin, I'm just asking the simple question of whether or not it's necessary, before spending any money to do something that might already be built into Virtuemart. 

Also, I've posted several photos from the category view, of an example of one of the parents products.

QuoteWhy don't do you setup as the demo?
Is it wrong?
I have no idea what you mean by this.

pinochico

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

stargazer1682

The answer would appear to be enabling the setting "Show product customfields in browse views" in Configuration under the Shopfront tab.  Once enabled, parent products cease to have the Add to Cart button in the category view, and instead show the variant drop down box, along with the faux button labeled "Choose a Variant"