Author Topic: Hide Add to Cart for Parent Product  (Read 774 times)

stargazer1682

  • Jr. Member
  • **
  • Posts: 144
Hide Add to Cart for Parent Product
« on: August 05, 2020, 04:43:05 am »
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

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 642
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Hide Add to Cart for Parent Product
« Reply #1 on: August 05, 2020, 10:20:31 am »
wrong setup
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

stargazer1682

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #2 on: August 05, 2020, 15:00:16 pm »
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

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #3 on: August 05, 2020, 20:41:38 pm »
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4362
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Hide Add to Cart for Parent Product
« Reply #4 on: August 05, 2020, 23:04:40 pm »
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

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 642
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Hide Add to Cart for Parent Product
« Reply #5 on: August 06, 2020, 04:28:11 am »
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 from products, orders and database table
Virtuemart Email Manager - customs email templates

stargazer1682

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #6 on: August 08, 2020, 01:46:16 am »
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

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3690
  • using Matomo instead of Google Analytics
Re: Hide Add to Cart for Parent Product
« Reply #7 on: August 08, 2020, 07:58:20 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):
Code: [Select]
<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:
Code: [Select]
<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

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #8 on: August 08, 2020, 15:49:51 pm »
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):
Code: [Select]
<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:
Code: [Select]
<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
Code: [Select]
<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

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3690
  • using Matomo instead of Google Analytics
Re: Hide Add to Cart for Parent Product
« Reply #9 on: August 08, 2020, 21:43:36 pm »
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):
Code: [Select]
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:
Code: [Select]
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$this->product));to
Code: [Select]
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

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #10 on: August 09, 2020, 00:15:02 am »
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

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 642
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Hide Add to Cart for Parent Product
« Reply #11 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? :)
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

stargazer1682

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #12 on: August 09, 2020, 01:18: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.

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

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 642
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Hide Add to Cart for Parent Product
« Reply #13 on: August 09, 2020, 05:35:31 am »
I answered:
http://forum.virtuemart.net/index.php?topic=145293.msg515910#msg515910
wrong setup

Look inside demo.virtuemart.net in admin how product Generic child variant is setuped.

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

stargazer1682

  • Jr. Member
  • **
  • Posts: 144
Re: Hide Add to Cart for Parent Product
« Reply #14 on: August 28, 2020, 05:59:38 am »
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"