2

I'd like to hide actions block on the single product page (only certain products):

enter image description here

I thought magento managed to show this information with a single phtml so I'd overrided entirely and insert an if block to show/hide this section.

But I see it uses a lot of templates and don't know how to do it to take control on it.

I did a similar question only for add a block Add block on single product page, but in this case I need to control the existing block.

I'm trying to solve the problem like @chirag said but I can't figure out why it's not working, so I'll put the names and paths:

\app\code\GSP\Mto\view\frontend\layout\catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="page.main.title">
        <block class="GSP\Mto\Block\Product\View\MtoSingle"
               name="product.view.mto"
               template="GSP_Mto::product/view/mto_single.phtml"
               after="-">
        </block>
    </referenceContainer>

    <referenceBlock name="product.info" template="GSP_Mto::product/view/form.phtml" />
</body>
</page>

app\code\GSP\Mto\view\frontend\templates\product\view\form.phtml

<p> test </p>

expected result: paragraph test instead of form qty and add to cart.

actual result: default magento template.


UPDATE: I'm looking around and I don't see nothing wrong, seems it has to be something about priorities. Magento just uses his template as default. If I write

<referenceBlock name="product.info" template="GSP_Mto::product/view/form.phtml" remove="true" />

It works, the addtocart and qty disappears. But when I only indicate to use my template, magento just show it as default.

The only way it 'works out' is writing a line on di.xml:

<preference for="Magento\Catalog\Block\Product\View" type="GSP\Mto\Block\Product\View" />

And copy the entire class on my module. But this is just ridiculous. And then messies the button addtocart not showing it, seems breaks something

It has to be a silly thing but it kept me an entirely day and I couldn't fix it.


UPDATE2: Tried to write directly on vendor\magento\module-catalog\view\frontend\layout\catalog_product_view.xml

<block class="Magento\Catalog\Block\Product\View" name="product.info" template="GSP_Mto::product/view/form.phtml" after="alert.urls">

My template. This is the only way that works everything but completely wrong way to do it.

I think I'm going to lose my head.

1

You can write your condition in three files for hiding this block.

1. product/view/addto.phtml

2. product/view/mailto.phtml

3. product/view/form.phtml

[NOTE] Copy content of this files in your custom files and then you can write your required condition.

Your catalog_product_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
    <referenceBlock name="product.info" template="{YourVendor}_{Your_Module}::product/view/form.phtml"></referenceBlock>
    <referenceBlock name="product.info.addto" template="{YourVendor}_{Your_Module}::product/view/addto.phtml"></referenceBlock>
    <referenceBlock name="product.info.mailto" template="{YourVendor}_{Your_Module}::product/view/mailto.phtml"></referenceBlock>
  </body>
</page>
  • Looks nice, I thought there will be so many blocks to override. But I have a silly problem, don't know why magento still uses his template instead of mine. If I write <referenceBlock name="product.info.addto" remove="true" /> I see that block disappears but when I write like you did indicating my template doesn't work. Need to do anything else? Paths are correct. I tried to write: vendor_module::product/view/form.phtml and vendor_module/product/view/form.phtml – slayerbleast Dec 12 '16 at 11:46
  • uppss, you have to use vendor_module::product/view/form.phtml. – chirag Dec 12 '16 at 11:48
  • I've already tried, and not working. I hate magento for this things, how I know what is happening? – slayerbleast Dec 12 '16 at 11:51
  • Have you check the path of your template file? – chirag Dec 12 '16 at 11:54
  • Yes, also I tried to use another template that I know is working fine and nothing. There aren't something about priorities? seems it has to be that. – slayerbleast Dec 12 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.