0

I want to call my custom phtml file in virtual product's view page. That file will call within form of that page so my data are post on add to cart.

I already develop a code for this purpose and working fine on add to cart page.But when I am on update cart page of this product that time file is not calling.

Please have a look :

namespace/mymodule/view/frontend/layout/catalog_product_view_type_virtual.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceContainer name="product.info.main">
           <block class="Namespace\Modulename\Block\Product\View\Type\Virtual" template="Namespace_Modulename::product/view/type/virtual.phtml"/>
      </referenceContainer>
   </body>
</page>
6
  • Have you same file call in cart page ? Apr 19 '16 at 6:30
  • you can check using adding after or before in block tag. Apr 19 '16 at 6:37
  • @SHPatel Yes I am calling same file.
    – Krupali
    Apr 19 '16 at 6:39
  • @Rakesh can you please give me an example
    – Krupali
    Apr 19 '16 at 6:39
  • Do you want your custom template instead of product/view/type/default.phtml ? Apr 19 '16 at 10:41
0

you can try using, you can set blockname as your position name like ,product.info.price

<block class="Namespace\Modulename\Block\Product\View\Type\Virtual" template="Namespace_Modulename::product/view/type/virtual.phtml" after="{blockname}" />

Or

<block class="Namespace\Modulename\Block\Product\View\Type\Virtual" template="Namespace_Modulename::product/view/type/virtual.phtml" before="{blockname}" />
1
  • Do you know which block name I have to used here ? Because I tried many blocks by their reference name but can not get success.
    – Krupali
    Apr 19 '16 at 7:05
0

Add below code to your theme defaul.xml

<referenceContainer name="product.info.main">
    <block class="Namespace\Modulename\Block\Product\View\Type\Virtual" template="Namespace_Modulename::product/view/type/virtual.phtml"/>
</referenceContainer> 

Let me know if you have any issue.

5
  • Is it not possible to put in catalog_product_view_type_virtual instead of default.xml ? why ?
    – Krupali
    Apr 19 '16 at 11:20
  • Because of catalog_product_view_type_virtual.xml can not call on update cart item. Apr 19 '16 at 11:36
  • I tried this and my file is called in both case.But as I said it is calling out of Form passed to cart.So my data will not pass. :(
    – Krupali
    Apr 19 '16 at 11:43
  • Hi @SureshChikani my custom phtml file is not calling in all product view pages Mar 28 '19 at 7:55
  • Please refer the below link: magento.stackexchange.com/questions/267766/… Mar 28 '19 at 7:58
0

Use below code in file Namespace/Mymodule/view/frontend/layout/catalog_product_view_type_virtual.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="product.info.type">
                <block class="Namespace\Modulename\Block\Product\View\Type\Virtual" after="product.info.virtual" template="Namespace_Modulename::product/view/type/virtual.phtml"/>             
         </referenceContainer>      
    </body>
</page>
1
  • This will add out of form of product view page.So my data will not post on add to cart.
    – Krupali
    Apr 19 '16 at 11:36

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.