0

I want to hide Bundle product option price if it is 0.00 on checkout page.

I have created a after plugin as following.

etc/frontend/di.xml:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Bundle\Helper\Catalog\Product\Configuration">
        <plugin name="removeZeroPriceFromBundleItemOptions" type="Meta\Checkout\Plugin\Magento\Bundle\Helper\Catalog\Product\Configuration"/>
    </type>
</config>





<?php
namespace Meta\Checkout\Plugin\Magento\Bundle\Helper\Catalog\Product;

class Configuration
{
    /**
     * remove zero price of bundle product item options 
     * from cart, minicart and order summary on checkout page
     *
     * @param \Magento\Bundle\Helper\Catalog\Product\Configuration $options
     * @param $result
     */
    public function afterGetBundleOptions(\Magento\Bundle\Helper\Catalog\Product\Configuration $options, array $result)
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/trackorder.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info("startting-------");
        $logger->info($result);
        //$logger->info($this->getCurrentCurrencySymbol());  

        $count= 0;
        foreach($result as $option)
        {
            $logger->info($option['value'][0]);
            if ( is_array($option['value']) ){  // if is array
                if($option['value'][0] != strip_tags($option['value'][0]) ) // if contains html tag
                {
                    preg_match('/<span class="price">(.*?)<\/span>/s', $option['value'][0], $match);
                    $extractPrice = trim(strip_tags($match[0]));
                    $logger->info($extractPrice);
                    $logger->info(filter_var($extractPrice, FILTER_SANITIZE_NUMBER_INT));
                    if(filter_var($extractPrice, FILTER_SANITIZE_NUMBER_INT) == 0)
                    {
                        $optionText = substr($option['value'][0] ,0,strpos($option['value'][0],'<span'));
                        $result[$count]['value'][0] = trim($optionText);
                    }

                }
            }
            $count++;
        }

        $logger->info($result);
        $logger->info("endingg-------");
        return $result;
    }

}

But it works only on cart page and in minicart, but does not work on checkout page order summary.

enter image description here

Additional findings:

What I noticed is, this plugin seems to work only on page load duration, it means when checkout page keeps loading then product option prices don't come but after page load below ajax is fired and then it reload order summary section and then option prices begin to display.

rest/en/V1/carts/mine/totals-information 

but since I already have applied plugin so this time prices should not come up with options.and I checked logs in plugin files are being printed when above ajax run.

So I am not sure why it is happening and why plugin output not being shown at frontend.

Any help/suggestion would be appreciated.

1 Answer 1

0

It worked.

actually I need to defined plugin in di.xml file in etc folder, not in etc/frontend/di.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.