In order to override the function getBundleOptions
from magento2/vendor/magento/module-bundle/Helper/Catalog/Product/Configuration.php
i have implemented the following module:
MySpace/MyModule3/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\Helper\Catalog\Product\Configuration" type="MySpace\MyModule3\Helper\Bundle\Catalog\Product\Configuration\Configuration" />
</config>
MySpace/MyModule3/Helper/Bundle/Catalog/Product/Configuration/Configuration.php
<?php
namespace MySpace\MyModule3\Helper\Bundle\Catalog\Product\Configuration;
class Configuration extends Magento\Bundle\Helper\Catalog\Product\Configuration
{
/**
* 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
? $this->serializer->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 = $this->serializer->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'][] = $this->escaper->escapeHtml($bundleSelection->getName());
$option['has_html'] = true;
}
}
if ($option['value']) {
$options[] = $option;
}
}
}
}
}
return $options;
}
}
However, the module is not working, and still returns the following:
Fatal error: Class 'MySpace\MyModule3\Helper\Bundle\Catalog\Product\Configuration\Magento\Bundle\Helper\Catalog\Product\Configuration' not found in /data/web/magento2/app/code/MySpace/MyModule3/Helper/Bundle/Catalog/Product/Configuration/Configuration.php on line 3
Any ideas of how to correct for this error, and make the module work?