Create db_schema_whitelist.json file using CLI in Magento 2.

In Magento 2, Magento Version 2.3 and higher version contains the declarative schema approach for database tables history.

You can create db_schema_whitelist.json using the command line with a single command,

The generated file location is the <Vendorname>/<Modulename>/etc/db_schema_whitelist.json in your module. Continue reading “Create db_schema_whitelist.json file using CLI in Magento 2.”

Magento 2 truncate string to specific limit.

Magento 2 You can truncate the string using Magento best practice.

By default, You can truncate the string using substr() PHP method.

Magento gives Out of the box feature for a truncate string using Magento\Framework\Stdlib\StringUtils class. Continue reading “Magento 2 truncate string to specific limit.”

Magento 2 Disable Payment method for frontend only.

Magento 2 You can disable payment method for frontend only using programmatically.

You can show the payment method in the admin area only and disable in the frontend area.

You need to create a simple module for the disable payment method in frontend. We disable the Cash on a delivery payment method from the frontend and enable the payment method in admin only.

Magento contain Magento\Payment\Model\MethodList class and Class used getAvailableMethods() function to check available method on frontend. Continue reading “Magento 2 Disable Payment method for frontend only.”