Skip to main content

Posts

Mangento2: add custom validation to the UI Form Field

Here are the steps to add a custom validation to the UI Form field: Add the following code to your field in xml file: <item name="validation" xsi:type="array">     <item name="custom_auth_validation" xsi:type="boolean">true</item> </item>  Then add the following code to your js while which is loading on that page: validator.addRule(         'custom_validation',         function (value) {             if (jQuery( "input[name='authorization_required']" ).val() == 1                  && jQuery( "input[name='auth_code']" ).val() == "") {                 return false;             }             return true;         }         ,$.mage.__('Custom validation message...')     ); 

Mangento2: Knockout: add multiple events to data-bind attribute of one element

We can add multiple events to single data-bind attribute of one element using comma. Example is given below: <div data-bind =" submit: navigateToNextStep, click: callanotherFunc "></div> in this example we have added 2 events to the data-bind attribute: First is:  submit: navigateToNextStep Second is:   click: callanotherFunc

Magento2: Some useful commands

 Some useful commands for Magento 2: php bin/magento c:f php bin/magento c:c php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento enable:maintenace php bin/magento queue:consumers:list php bin/magento queue:consumers:start consumer_name php bin/magento enable:module vendorname_modulename php bin/magento disable:module vendorname_modulename php bin/magento store:list php bin/magento store:website:list php bin/magento maintenance:enable php bin/magento maintenance:disable php bin/magento maintenance:status php bin/magento indexer:status php bin/magento indexer:reindex php bin/magento cron:run php bin/magento deploy:mode:show php bin/magento deploy:mode:set mode_name php bin/magento catalog:images:resize

Magento2: Widget (Catalog Category Link) not visible on frontend

 If you have added a WIDGET to any cms static block or cms Page and it is not visible on front-end, Don't worry just check your url_rewrite table in database, the Category or Product ID you have passed with the WIDGET it must exist in the url_rewrite table,  if category or product id doesn't exist in table you can regenerate that category or product URL, once url will be regenerated and entry will added to the url_rewrite table, your widget will be visible on frontend.

Magento 2: How to add menu to the admin grid?

To add new menu in admin grid, first create an menu.xml file to your module on following location: Packagename/Modulename/etc/adminhtml/menu.xml then place the following code in menu.xml: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Backend/etc/menu.xsd">     <menu>          <add id="Packagename_Modulename::urlkey" title="Menu Title" module="Packagename_Modulename"  sortOrder="10" resource="Packagename_Modulename::urlkey"/>        <add id="Packagename_Modulename::urlkey_controller_action" title="Sub Menu Title" module="Packagename_Modulename"  sortOrder="10" action="urlkey/controller/action" resource="Packagename_Modulename::urlkey_controller_action" parent="Packagename_Modulename::urlkey" />     </menu> </config> ...

Magento 2: Set default cron

To set default cron in magento 2 just login your project using ssh and go to root directory of project and type following command: crontab -e after that an editor will open just paste the following code there: * * * * * php project server root directory path/bin/magento cron:run * * * * * php project server root directory path/update/cron.php * * * * * php project server root directory path/bin/magento setup:cron:run and replace project server root directory path   with your project root directory path.