Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top