0

How to create a js widget that will add the current date on the product page to the description on the <p id="lol"></p> element?

Or which will insert a p tag with a date at the end of each product. maybe there is an easier way?

app/design/frontend/Qwe/qwerty/Magento_Catalog/requirejs-config.js

var config = {
    map: {
        '*': {
            nowDateDescription: 'Magento_Catalog/js/qwe_now_date_description'
        }
    }
};

app/design/frontend/Qwe/qwerty/Magento_Catalog/web/js/qwe_now_date_description.js

define([
    'jquery'
], function ($) {
    'use strict';

    return function (config, element) {
        function setCurrentYear() {
            return new Date().getFullYear();
        }
    }
});

app/design/frontend/Qwe/qwerty/Magento_Catalog/templates/product/qwe_now_date_description.phtml

<script type="text/javascript">
    require(['jquery', 'nowDateDescription'], function ($) {
            $('#lol').text(getCurrentYear())
        )
    })
</script>

app/design/frontend/Qwe/qwerty/Magento_Catalog/layout/catalog_product_view.xml

        <referenceContainer name="product.info.description">
            <block class="Magento\Framework\View\Element\Template"
                   name="qwe.now.date.description" template="Magento_Catalog::product/qwe_now_date_description.phtml"/>
        </referenceContainer>
1
  • What happens with your solution? – Ben Crook Jan 11 at 14:47

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.