In a magento2 plugin I would like to get the product custom options title from the option ID, but I do not know what injection to make in the constructor and what functions to use to achieve that...


You can do this with collection, my solution:

protected $_storeManager;
protected $_options;

public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $options,
        \Magento\Store\Model\StoreManagerInterface $_storeManager
    $this->_storeManager = $_storeManager;
    $this->_options = $options;

public function getOption($optionId){
    return $this->appendSelections(
        ->addFieldToFilter('option_id', $optionId)
        ->addFieldToFilter('parent_id', $this->getProduct()->getEntityId())
        ->joinValues($this->_storeManager->getStore()->getId()) // this will append title
protected function appendSelections(\Magento\Bundle\Model\Option $option, $product){
        $typeInstance = $product->getTypeInstance();
        $selections = $typeInstance->getSelectionsCollection([$option->getOptionId()], $product);
        $option->setData('selections', $selections);
    return $option;

With "Repository":


This solution for bundle options but in custom options will be similar...

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.