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 ? Commented Apr 19, 2016 at 6:30
  • you can check using adding after or before in block tag. Commented Apr 19, 2016 at 6:37
  • @SHPatel Yes I am calling same file. Commented Apr 19, 2016 at 6:39
  • @Rakesh can you please give me an example Commented Apr 19, 2016 at 6:39
  • Do you want your custom template instead of product/view/type/default.phtml ? Commented Apr 19, 2016 at 10:41

3 Answers 3

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. Commented Apr 19, 2016 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 ? Commented Apr 19, 2016 at 11:20
  • Because of catalog_product_view_type_virtual.xml can not call on update cart item. Commented Apr 19, 2016 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. :( Commented Apr 19, 2016 at 11:43
  • Hi @SureshChikani my custom phtml file is not calling in all product view pages Commented Mar 28, 2019 at 7:55
  • Please refer the below link: magento.stackexchange.com/questions/267766/… Commented Mar 28, 2019 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. Commented Apr 19, 2016 at 11:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.