0

I'm reading the documentation here. My goal is to remove the "Customize and Add to Cart" button, for a bundled product

customize-add-to-cart-bundled-button

The path for the layout can be found here /vendor/magento/module-gift-registry/view/frontend/layout/catalog_product_view_type_bundle.xml. I want to remove the first action

<action method="setGiftRegistryTemplate">
    <argument name="blockName" xsi:type="string">customize.button</argument>
    <argument name="template" xsi:type="string">Magento_GiftRegistry::product/customize.phtml</argument>
</action>

which meets the criteria in the documentation for overriding a layout file

Examples of customizations that involve overriding layouts:

  • Suppressing method invocation.

Note there is no method to cancel the prior invocation in the Block class itself. So I have added this file in my custom theme

/app/design/frontend/vendor/theme-name/Magento_GiftRegistry/layout/override/base/catalog_product_view_type_bundle.xml, duplicating the stock layout file and omitting the first action (referenced above).

There is no change on the frontend, the button is still there. I found this thread, however the original question was not answered, and I'm looking for an answer to that very question now.

So what am I doing wrong?

3 Answers 3

2
+100

Briefly, you're overwriting wrong layout :)

  1. "Customize and add to cart" button is originally created in Bundle module:

    vendor/magento/module-bundle/view/frontend/layout/catalog_product_view_type_bundle.xml:76

    <referenceContainer name="product.info.main">
        <block class="Magento\Catalog\Block\Product\View" name="customize.button" as="customize_button" template="Magento_Bundle::catalog/product/view/customize.phtml" after="product.info.price" />
    </referenceContainer>
    

    It shows button text as:

    <span><?= $block->escapeHtml(__('Customize and Add to Cart')) ?></span>
    
  2. GiftRegistry module merely replaces above block template if condition is met

    return $this->getRequest()->getParam('options') == self::FLAG; // flag = "giftregistry"
    

    Replaced template Magento_GiftRegistry::product/customize.phtml has another button text:

    <button id="bundle-slide" class="action primary customize" type="button"><span><?= $block->escapeHtml(__('Customize and Add to Gift Registry')) ?></span></button>
    

So your code actually works, it disables gift registry change, but original Bundle module button is not affected.

Test with such URL: https://example.com/catalog/product/view/id/52?options=giftregistry

As mentioned before, you don't need override in this case, <referenceBlock name="customize.button" remove="true" /> works (tested).

P.S. You can peek at layout merge/override process using debug here:

Source: magento2-exam-notes

5
  • The canonical answer I was looking for, thank you sir. I will award the bounty in a few hours when stack exchange allows it. Commented Sep 14, 2020 at 16:42
  • OMG I botched the bounty assignment!! Commented Sep 14, 2020 at 19:50
  • It happens, never mind 😁 Commented Sep 14, 2020 at 20:40
  • 1
    Hooked you up brother, thanks for your time! Commented Sep 16, 2020 at 16:53
  • WOW you are the best! Thanks again 🙏 Commented Sep 16, 2020 at 17:56
0
+50

You can create an XML file in your theme same as the given path:

app/design/frontend/vendor/theme-name/Magento_Bundle/layout/catalog_product_view_type_bundle.xml

and put below code in that file.

<?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>
        <referenceBlock name="customize.button" remove="true" />
    </body>
</page>
6
  • I tried this, it does not work. Probably, because the block is added as an action, not via layout. Can you stick to the question at hand please? Why is the override not working as the documentation states? Commented Sep 9, 2020 at 12:26
  • That is the path for layout extension, per the documentation Commented Sep 9, 2020 at 13:36
  • Yes, it will extend the layout instead of override. have you try with changing argument blockName to false? Commented Sep 9, 2020 at 13:41
  • I am trying to understand how to override a layout. The question has been asked previously and not answered, hence I am curious for an answer. I am not interested in a workaround. Commented Sep 9, 2020 at 13:56
  • Ok, I have also checked overriding other layouts like customer account edit and cms page view and that works fine. Have you confirmed that the file is not in the blank or luma theme. If your parent theme is blank then do not need to check luma theme. Commented Sep 9, 2020 at 14:01
0

In the end I found that both the layout override and extension were needed. Per both Satish and Roman, the layout extension

<referenceBlock name="customize.button" remove="true" />

is needed in

app/design/frontend/vendor/theme-name/Magento_Bundle/layout/catalog_product_view_type_bundle.xml

However the layout override in

app/design/frontend/vendor/theme-name/Magento_GiftRegistry/layout/override/base/catalog_product_view_type_bundle.xml

is also needed, because without it Magento tries to call setGiftRegistryTemplate on a block that does not exist!

1
  • So finally it has been resolved. It is strange that layout override also needed in your case because in my case it was worked with extended layout only. I did not override it. Commented Sep 15, 2020 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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