4

I would like to remove the price from the bundle product options in the entire site. The place I have noticed that get displayed are:

  • Shopping Cart
  • Review Your Cart Page
  • Mini Cart
  • Confirmation Emails

enter image description here

Things I have tried: I created a new module and overrode \Magento\Bundle\Helper\Catalog\Product\Configuration:

ZEndertech\BundleExtended\Helper\Catalog\Product\Configuration.php

    <?php

namespace ZEndertech\BundleExtended\Helper\Catalog\Product;

use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Framework\App\Helper\AbstractHelper;

use \Magento\Bundle\Helper\Catalog\Product\Configuration as BaseConfiguration;

class Configuration extends BaseConfiguration
{
    /**
     * Get bundled selections (slections-products collection)
     *
     * Returns array of options objects.
     * Each option object will contain array of selections objects
     *
     * @param ItemInterface $item
     * @return array
     */
    public function getBundleOptions(ItemInterface $item)
    {
        $options = [];
        $product = $item->getProduct();

        /** @var \Magento\Bundle\Model\Product\Type $typeInstance */
        $typeInstance = $product->getTypeInstance();

        // get bundle options
        $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
        $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : [];
        if ($bundleOptionsIds) {
            /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
            $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);

            // get and add bundle selections collection
            $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');

            $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());

            if (!empty($bundleSelectionIds)) {
                $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product);

                $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
                foreach ($bundleOptions as $bundleOption) {
                    if ($bundleOption->getSelections()) {
                        $option = ['label' => $bundleOption->getTitle(), 'value' => []];

                        $bundleSelections = $bundleOption->getSelections();

                        foreach ($bundleSelections as $bundleSelection) {
                            $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
                            if ($qty) {
                                $option['value'][] = $qty . ' x '
                                    . $this->escaper->escapeHtml($bundleSelection->getName());
                            }
                        }

                        if ($option['value']) {
                            $options[] = $option;
                        }
                    }
                }
            }
        }

        return $options;
    }

}

I cleared the cache, but the price still appears next to the bundle options.

1
  • Could you add the code you used to override the file? Also, can you post it's path and any other di.xml files in your module?
    – tjons
    Commented Jan 3, 2017 at 0:28

1 Answer 1

3

In alignment with what @tjons pointed out, in my di.xml for the module I created I needed to add a new entry to list the preference to pick up my Configuration.php file over the core one. After that I ran php bin/magento setup:upgrade command, reloaded the page and voila!

The di.xml file is the one below:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Bundle\Helper\Catalog\Product\Configuration" type="ZEndertech\BundleExtended\Helper\Catalog\Product\Configuration"/>
</config>

enter image description here

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.