1

I am working with the Magento2, in that, I like to add a custom block on product detailed page, next to add to cart button. for that, i wrote the below code on

catalog_product_view.xml

<body>
        <referenceBlock name="product.info.addtocart">
                <block class="Learn\Share\Block\Share" name="share.otherproducts" as="shareother" after="-" template="catalog/product/view/share.phtml" >
                </block>
        </referenceBlock>
        <!-- for config products -->
        <referenceBlock name="product.info.addtocart.additional">
            <block class="XXXX\YYYY\Block\Share" name="share.configproducts" as="share_config" after="-" template="catalog/product/view/share.phtml" >
            </block>
        </referenceBlock>
    </body>

I got the custom block values on simple, download product. but in bundle product detailed page I don't get any custom block values.

Then, the custom block not only for simple, download and bundle product. I want this custom block on all the Magento product types, so give me your solution for support all product type

Then why we need to add the same custom block on product.info.addtocart.additional section.

Thanks in advance for your thoughts and ideas.

  • Bundle products have a more complex schema (I cant remember where it is located) so find and edit that as well – Anthony Jan 29 at 7:06
  • for bundle product it will be product.info.addtocart.bundle. – Pawan Jan 30 at 3:41
  • @Pawan, thanks for your support, I tried as you mentioned way, but there is no luck. I found some other way to achieve the functionality, I posted an answer on the same question. it's working well on all product except the bundle products, is there have any other way to get the custom block on a bundle product page? – senthil Jan 30 at 5:36
1

Give this a try:

Create

app/design/frontend/{Package}/{theme}/Magento_Bundle/layout/catalog_product_view_type_bundle.xml

add following code:

<referenceBlock name="product.info.addtocart.bundle">
    <block class="XXXX\YYYY\Block\Share" name="share.configproducts" as="share_config" after="-" template="catalog/product/view/share.phtml" ></block>
</referenceBlock>

let me know if work

Update I

After a lot work, finally I found a working solution:

don't need to create a separate xml for bundle product. You can add following code to catalog_product_view.xml

<referenceBlock name="product.info.main">
        <block class="Learn\Share\Block\Share" name="share.bundleproducts" as="share_bundle" after="customize.button" template="{Vendor}_{Module}::catalog/product/view/share.phtml" ></block>
</referenceBlock>

If you look at above code, block name is product.info.main but we need to set after element as customize.button which is addtocart for bundle product.

  • I place the catalog_product_view_type_bundle.xml on namespace/modulename/view/layout/catalog_product_view_type_bundle.xml but still no luck, I like to keep all files related to the module within that module, that's why I placed in module view directory – senthil Jan 30 at 15:09
  • could you please share whole code ? – Pawan Jan 31 at 4:11
  • the below code is I am using on catalog_product_view_type_bundle.xml <page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="product.info.addtocart.bundle"> <block class="XXXX\YYYY\Block\Share" name="share.configproducts" as="share_config" after="-" template="catalog/product/view/share.phtml" ></block> </referenceBlock> </body> </page> – senthil Jan 31 at 6:06
  • please see my updated answere – Pawan Feb 3 at 4:46
  • thanks for your effort. the updated answer working well on all the product page. – senthil Feb 4 at 15:02
0

The below code is adding the custom block on next to add to cart button to all the product type except the Bundle product.

catalog_product_view.xml

    <referenceContainer name="product.info.form.content">
        <block class="Learn\Share\Block\Share" name="share.otherproducts" as="shareother" after="-" template="catalog/product/view/share.phtml" ></block>
</referenceContainer>
<!-- config and download product -->
<referenceBlock name="product.info.options.wrapper.bottom">
        <block class="XXXX\YYYY\Block\Share" name="share.configproducts" as="share_config" after="-" template="catalog/product/view/share.phtml" ></block>
</referenceBlock>

I wanted to add a custom block on Bundle product also, so is there any way to do that kindly share your ideas and thoughts.

Thanks in advance for your support.

enter image description here

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.