Question

I want to change the message.phtml template file which renders a pop up message below on product page.

Current message when options not selected

Im not sure where in the KO.js binding message html to change "My new message"

Here is the message.phtml

<?php

<div data-bind="scope: 'messages'">
    <div data-bind="foreach: { data: cookieMessages, as: 'message' }" class="messages">
        <div data-bind="attr: {
            class: 'message-' + message.type + ' ' + message.type + ' message',
            'data-ui-id': 'message-' + message.type
        }">
            <div data-bind="html: message.text"></div>
        </div>
    </div>
    <div data-bind="foreach: { data: messages().messages, as: 'message' }" class="messages">
        <div data-bind="attr: {
            class: 'message-' + message.type + ' ' + message.type + ' message',
            'data-ui-id': 'message-' + message.type
        }">
            <div data-bind="html: message.text"></div>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                        "messages": {
                            "component": "Magento_Theme/js/view/messages"
                        }
                    }
                }
            }
    }
</script>

snippet of chrome browsers knockoutjs context extension

knockoutjs context, chrome extension

UPDATE AFTER CHANGES

Thanks for the help...I added this to my di.xml

<?php

namespace  {{Vendor}}\{{Module}}\Plugin;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable; {

    class MagentoCaptchaValidation
    {
        public function afterGetSpecifyOptionMessage(Configurable $subject)
        {
            return __('Please select a size in order to place your order');
        }
    }
}

Error message received during the compile, why do i need this class MagentoCaptchaValidation

In PhpScanner.php line 183:
                                                                           
  Class {{Vendor}}\{{Module}}\Plugin\MagentoCaptchaValidation does not exist```
Was it helpful?

Solution

I just did a quick search for that string, and this is the only place it's showing up: vendor/magento/module-configurable-product/Model/Product/Type/Configurable::getSpecifyOptionMessage(). That seems to be where the text is ultimately coming from, and you could use a plugin to change it.

---Update---

For the plugin, you would just create an after plugin for getSpecifyOptionMessage(). So, in your custom module, you'd drop this in di.xml:

<type name="Magento\ConfigurableProduct\Model\Product\Type\Configurable">
   <plugin name="updateOptionMessageText" type="{{Vendor}}\{{Module}}\Plugin\UpdateOptionMessage"/>
</type>

And this into {{Vendor}}\{{Module}}\Plugin\UpdateOptionMessage:

<?php

namespace {{Vendor}}\{{Module}}\Plugin;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable

class UpdateOptionMessage
{
    public function afterGetSpecifyOptionMessage(Configurable $subject)
    {
        return __('{{Whatever text you want}}');
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top