0

I am using Magento 2.3.1

I have created one bundle product and in this product, I have added all types(Radio, checkbox, dropdown and multiple select) of bundle options.

I have displayed SKU for each bundle items of radio button and checkbox type using below code.

app/design/frontend/vendor_name/theme/Magento_Bundle/templates/catalog/product/view/type/bundle/option/checkbox.phtml

<?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox */ ?>
<?php $_option = $block->getOption() ?>
<?php $_selections = $_option->getSelections() ?>
<div class="field option <?= ($_option->getRequired()) ? ' required': '' ?>">
    <label class="label">
        <span><?= $block->escapeHtml($_option->getTitle()) ?></span>
    </label>
    <div class="control">
        <div class="nested options-list">
            <?php if ($block->showSingle()): ?>
                <?= /* @escapeNotVerified */ $block->getSelectionQtyTitlePrice($_selections[0]) ?>
                <input type="hidden"
                       class="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>  product bundle option"
                       name="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>]"
                       value="<?= /* @escapeNotVerified */ $_selections[0]->getSelectionId() ?>"/>
            <?php else:?>
                <?php foreach($_selections as $_selection): ?>
                    <div class="field choice">
                        <input class="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?> checkbox product bundle option change-container-classname"
                               id="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>"
                               type="checkbox"
                               <?php if ($_option->getRequired()) /* @escapeNotVerified */ echo 'data-validate="{\'validate-one-required-by-name\':\'input[name^=&quot;bundle_option[' . $_option->getId() . ']&quot;]:checked\'}"'?>
                               name="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>][<?= /* @escapeNotVerified */ $_selection->getId() ?>]"
                               data-selector="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>][<?= /* @escapeNotVerified */ $_selection->getId() ?>]"
                               <?php if ($block->isSelected($_selection)) echo ' checked="checked"' ?>
                               <?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>
                               value="<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>"/>
                        <label class="label"
                               for="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>">
                            <span><?= /* @escapeNotVerified */ $block->getSelectionQtyTitlePrice($_selection) ?></span>

                            <?php echo $_selection->getSku(); ?>//I have added this line to display SKU

                        </label>
                    </div>
                <?php endforeach; ?>
                <div id="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-container"></div>
            <?php endif; ?>
        </div>
    </div>
</div>

app/design/frontend/vendor_name/theme/Magento_Bundle/templates/catalog/product/view/type/bundle/option/radio.phtml

<?php $_option = $block->getOption(); ?>
<?php $_selections  = $_option->getSelections(); ?>
<?php $_default     = $_option->getDefaultSelection(); ?>
<?php list($_defaultQty, $_canChangeQty) = $block->getDefaultValues(); ?>

<div class="field option clearfix"> 

    <div class="control">
        <div class="nested options-list">
            <?php if ($block->showSingle()): ?>
                <?php  echo $block->getSelectionTitlePrice($_selections[0]) ?>
                <input type="hidden"
                    class="bundle-option-<?php echo (int)$_option->getId() ?>  product bundle option"
                    name="bundle_option[<?php echo (int)$_option->getId() ?>]"
                    value="<?php echo (int)$_selections[0]->getSelectionId() ?>"
                    id="bundle-option-<?php echo (int)$_option->getId() ?>-<?php echo (int)$_selections[0]->getSelectionId() ?>"
                    checked="checked"
                />
            <?php else:?>
                <?php if (!$_option->getRequired()): ?>
                    <div class="field choice">
                        <input type="radio"
                               class="radio product bundle option"
                               id="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>"
                               name="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>]"
                               data-selector="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>]"
                               <?= ($_default && $_default->isSalable())?'':' checked="checked" ' ?>
                               value=""/>
                        <label class="label" for="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>">
                            <span><?= /* @escapeNotVerified */ __('None') ?></span>
                        </label>
                    </div>
                <?php endif; ?>
                <?php foreach ($_selections as $_selection): ?>
                    <div class="field choice">
                        <input type="radio"
                               class="radio product bundle option change-container-classname"
                               id="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>"
                               <?php if ($_option->getRequired()) echo 'data-validate="{\'validate-one-required-by-name\':true}"'?>
                               name="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>]"
                               data-selector="bundle_option[<?= /* @escapeNotVerified */ $_option->getId() ?>]"
                               <?php if ($block->isSelected($_selection)) echo ' checked="checked"' ?>
                               <?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>
                               value="<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>"/>
                        <label class="bundle-pro-label"
                               for="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>">
                             <div class="">
                                <span class=""><?php /* @escapeNotVerified */ echo $_selection->getName() ?></span>
                                <div class="">#<?php /* @escapeNotVerified */ echo $_selection->getSku() ?>
                                </div>
                            </div>

                            <span><?=  $block->getSelectionTitlePrice($_selection) ?></span>
                        </label>
                    </div>
                <?php endforeach; ?>
                <?php /*?><div id="bundle-option-<?=  $_option->getId() ?>-container"></div><?php */?>
            <?php endif; ?>
            <div class="field qty qty-holder">
                <label class="label" for="bundle-option-<?php echo $_option->getId() ?>-qty-input">
                    <span><?php echo __('Qty') ?></span>
                </label>
                <div class="control">
                    <?php /*?><input id="minusQty<?php echo $_option->getId() ?>" type="button" value="-" class="qtyminus" field="qty" /><?php */?><input 
                           id="bundle-option-<?php /* @escapeNotVerified */ echo $_option->getId() ?>-qty-input"
                           class="input-text qty"
                           type="number"
                           name="bundle_option_qty[<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                           data-selector="bundle_option_qty[<?php /* @escapeNotVerified */ echo $_option->getId() ?>]"
                           value="<?php /* @escapeNotVerified */ echo $_defaultQty ?>" disabled="disabled"/>
                </div>
            </div>
        </div>
    </div>
</div>

How can I display the SKU for the bundle items of type dropdown and multiple select?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.