0

I 've created the following plugin to override a method located at vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle/Option.php but it still does not seem to sort the desired effect. Any ideas on how this could work as desired?

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">
    <type name="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option">
        <plugin name="bundle-product-option-radio" type="MySpace\MyModule\Plugin\RadioPlugin" />
    </type>
</config>

app/code/MySpace/MyModule/Plugin/RadioPlugin.php

<?php

namespace MySpace\MyModule\Plugin;

class RadioPlugin
{

     public function aroundGetSelectionQtyTitlePrice(
        \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option $subject,
        \Closure $proceed,
        $selection,
        $includeContainer = true)
    {
        $this->setFormatProduct($selection);
        $priceTitle = '<span class="product-name">'
            . $this->escapeHtml($selection->getName())
            . '</span>';
        return $priceTitle;
    }
}

The method to override is located at vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle/Option.php:

/**
 * Get bundle option price title.
 *
 * @param \Magento\Catalog\Model\Product $selection
 * @param bool $includeContainer
 * @return string
 */
public function getSelectionQtyTitlePrice($selection, $includeContainer = true)
{
    $this->setFormatProduct($selection);
    $priceTitle = '<span class="product-name">'
        . $selection->getSelectionQty() * 1
        . ' x '
        . $this->escapeHtml($selection->getName())
        . '</span>';

    $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '') .
        '+' .
        $this->renderPriceString($selection, $includeContainer) . ($includeContainer ? '</span>' : '');

    return $priceTitle;
}
0

I think you should use $subject instead of $this in function block to refer Core class object.

 public function aroundGetSelectionQtyTitlePrice(
    \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option $subject,
    \Closure $proceed,
    $selection,
    $includeContainer = true)
{
    $subject->setFormatProduct($selection);
    $priceTitle = '<span class="product-name">'
        . $subject->escapeHtml($selection->getName())
        . '</span>';
    return $priceTitle;
}

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.