1

i want add phtml page block before additional block on product detail page

i want to do it vai catalog > catagory > custom design update (apply to products) i am able to add some custom block which show content from some file like path/abc.phtml

i am able to override block using code like below there

<reference name="product.info.media">
      <action method="setTemplate">
            <template>smartwave/zoom/product/view/media_bundled.phtml</template>
      </action>
</reference>

can u guide me xml code needed to do that

2 Answers 2

0

Issue: You cannot set product details page layout from Category >custom design tab.

For show a static block at product detail and want to set this cms block from admin .Then you need to goto admin>Catalog>Manage Product > select any product and Goto if it design tab and put this code

<reference name="product.info">
<block type="cms/block" name="mystaticblock" >
<action method="setBlockId"><block_id>YOUR_BLOCK_ID</block_id></action>
</block>
</reference>

As product detail page main layout template is view.phtml, and it doesn't render it child block automatically, so on catalog/product/view.phtml add those code block by <?php echo $this->getChildHtml('mystaticblock')?> for render te block.

Note: from admin manage you can only set cms block for one page.
Answer Link:

1

If you want create custom block on product detail page, then following can be helpful.

Add layout in your custom module.

/app/code/Custom/Module/view/frontend/layout/catalog_product_view.xml

Add following lines in catalog_product_view.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.main">
     <block class="Custom\Module\Block\Product\Sizechart" name="size.chart" after="-" template="sizechart.phtml" />
   </referenceContainer>
</body>
</page>

Then create block in Block folder like,

/app/code/Custom/Module/Block/Product/Sizechart.php

Add following in Sizechart.php

<?php
namespace Custom\Module\Block\Product;
class Sizechart extends \Magento\Framework\View\Element\Template
{
    protected $_coreRegistry;
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry
    ){
        $this->_coreRegistry = $registry;
        parent::__construct($context);
    }

    public function getProduct()
    {
        return $this->_coreRegistry->registry('current_product');
    }
}

Then create phtml file in view/templates path like,

/app/code/Custom/Module/view/frontend/templates/sizechart.phtml

Add your custom code there,

.......
<?php $_product = $block->getProduct(); ?>
.......

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.