I try to override getSelectionTitlePrice()
- function.
(vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
)
if i have understood right the best way to do it is use preference. Have been following lot of answers from everywhere but could not solve the problem. How to Override Core Block, Model and controller in Magento2
when i override getProduct()
- function (/Block/Product/View.php
) everything work but with getSelectionTitlePrice()
- function it doesn't
I tried to solve problem using Plugin but it just extend function not override it?!?
app/code/MySpace/MyModule/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option" type="MySpace\MyModule\Block\Catalog\Product\View\Type\Bundle\Option" />
</config>
app/code/MySpace/MyModule/Block/Catalog/Product/View/Type/Bundle/Option.php
<?php
namespace MySpace\MyModule\Block\Catalog\Product\View\Type\Bundle;
/**
* Bundle option renderer
*/
class Option extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option
{
public function getSelectionTitlePrice($selection, $includeContainer = true)
{
/** will be removed **/
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface');
$logger->debug('Block Override Test');
/** will be removed **/
$priceTitle = '<span class="product-name">' . $this->escapeHtml($selection->getName()) . '</span>';
$priceTitle .= ' ' . ($includeContainer ? '<span class="price-notice">' : '')
. $this->renderPriceString($selection, $includeContainer) . ($includeContainer ? '</span>' : '')
.'<span> xxx->getTaxPercent(fromSomewhere)</span>';
return $priceTitle;
}
}