I am writing a custom module for magento 2 i.e "call for price" and I want to override price html on product list page.
I have follow the following scenario:
1.etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Mymodule\Callforprice\Block\Callforprice" />
</config>
2.Block/Callforprice.php
<?php
namespace Mymodule\Callforprice\Block;
/**
* Product price block
*/
class Callforprice extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
/**
* Wrap with standard required container
*
* @param string $html
* @return string
*/
protected function wrapResult($html)
{
if($this->getSaleableItem()->getCallforprice()): // getCallforprice() is product attribute
return '<div class="price-box "><span>Call For Price</span></div>';
else :
return '<div class="price-box ' . $this->getData('css_classes') . '" ' .
'data-role="priceBox" ' .
'data-product-id="' . $this->getSaleableItem()->getId() . '"' .
'>' . $html . '</div>';
endif;
}
}
Any suggestion would be appreciated.
Thanks
call for price
extension then this link will help you github.com/emizentech/magento2-call-for-price – Keyur Shah Dec 11 '17 at 14:32