Role-based Access Control in payload CMS

Role-based Access Control It is also possible to allow multiple user types into the Admin Panel with limited permissions, known as role-based access control (RBAC). For example, you may wish to have two roles within the admins Collection: super-admin – full access to the Admin Panel to perform any action editor – limited access to the Admin Panel to… Continue reading Role-based Access Control in payload CMS

Data Fields in Payload CMS

Data Fields are used to store data in the Database. All Data Fields have a name property. This is the key that will be used to store the field’s value. Here are the available Data Fields: Array – for repeating content, supports nested fields Blocks – for block-based content, supports nested fields Checkbox – saves boolean true / false values Code –… Continue reading Data Fields in Payload CMS

Creating a PostgreSQL database on a server terminal

Access the PostgreSQL Terminal Log in to the PostgreSQL command-line interface using the following command: sudo -u postgres psql This assumes you’re logged in as a user with sudo privileges and postgres is the PostgreSQL administrative user. Create a Database In the psql terminal, run: CREATE DATABASE database_name; Verify the Database Creation You can list… Continue reading Creating a PostgreSQL database on a server terminal

ObjectManager usage directly

Should not use Object manager directly! For instance: MagentoFrameworkAppObjectManager::getInstance(); also if you are working with event observers or plugins, you should never use it directly. You could use it in Factories, but except that you should inject the Object Manager in the Constructor first then you can use its object in your method Preferred to… Continue reading ObjectManager usage directly

How do you create a custom cron job in Magento 2 and ensure it executes only once per cycle?

Here crontab.xml file <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:module:Magento_Cron:etc/crontab.xsd”> <group id=”default”> <job name=”vendor_module_cronjob” instance=”VendorModuleCronCustomJob” method=”execute”> <schedule>* * * * *</schedule> </job> </group> </config> <schedule>0 3 * * *</schedule> 0 – Minute (0th minute, or the beginning of the hour) 3 – Hour (3 AM) * – Day of the month (every day) * – Month (every month) * – Day… Continue reading How do you create a custom cron job in Magento 2 and ensure it executes only once per cycle?

After Upgrade Magento version from 2.3.5 to 2.4.7, an error in the Admin Grid(Custom module) started to appear

In Magento 2.4.x, there were some changes in the constructor signatures and how collections are handled, particularly with UiComponentDataProviderSearchResult used for grids. Steps to Fix the Issue: Step 1: Update the Collection Class Your Collection class extends MagentoFrameworkViewElementUiComponentDataProviderSearchResult, which means that the constructor parameters need to match the updated signature in Magento 2.4.x. Here’s how you can update your Collection class constructor: namespace G4AMainSliderModelResourceModelMainSliderGrid;… Continue reading After Upgrade Magento version from 2.3.5 to 2.4.7, an error in the Admin Grid(Custom module) started to appear

Error “Your session has expired” when click on add to cart in magento 2

when clicking on product’s add to cart then it’s giving me error–> Your session has expired. Solution UPDATE `core_config_data` SET `value` = ‘http://127.0.0.1/zain/accessories/’ WHERE `core_config_data`.`path` = ‘web/unsecure/base_url’; UPDATE `core_config_data` SET `value` = ‘http://127.0.0.1/zain/accessories/’ WHERE `core_config_data`.`path` = ‘web/secure/base_url’; http://127.0.0.1/zain/accessories/ in this write your frontend url (home page url) what you have after that run command in your… Continue reading Error “Your session has expired” when click on add to cart in magento 2

Magento 2: How to validate phone number by their country?

alidation rules are written in validation.js (lib/web/mage/validation.js), so you need override it. requirejs-config.js var config = { map: { ‘*’: { “Magento_Ui/js/lib/validation/rules”: “Vendor_Module/js/lib/validation/rules” } } }; rules.js: add rule like this but for countries you want to check. ‘phoneUK’: [ function (value) { return utils.isEmpty(value) || value.length > 9 && value.match(/^((?(0|+44)[1-9]{1}d{1,4}?)?s?d{3,4}s?d{3,4})$/); }, $.mage.__(‘Please specify a valid phone number’)… Continue reading Magento 2: How to validate phone number by their country?

Magento phone number should accept special character like (-) and should limit to 15 characters but currently it is accepting 10 characters only

In checkout_index_index.xml <item name=”validation” xsi:type=”array”> <item name=”min_text_length” xsi:type=”number”>10</item> <item name=”max_text_length_phone” xsi:type=”number”>15</item> <item name=”validate-number” xsi:type=”number”>0</item> </item> and then in vendor/magento/module_ui/view/base/web/js/lib/validation/rules.js “max_text_length_phone”: [ function (value, params) { return !_.isUndefined(value) && value.length <= +params; }, $.mage.__(‘Phone number cannot exceed 15 characters.’) ], the above code is for validation text and for adding regex as we require, so in… Continue reading Magento phone number should accept special character like (-) and should limit to 15 characters but currently it is accepting 10 characters only

magento 2 restrict phone number field in admin panel

You want to restrict phone number field and it should accept only 10 digits number then need to create custom validator addRule. I have created custom module with custom validator rule for make custom Phone Number validation. File path: magento/app/code/Vendor/PhonenumverValidation/registration.php <?php use MagentoFrameworkComponentComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, ‘Vendor_PhonenumverValidation’, __DIR__); File path: magento/app/code/Vendor/PhonenumverValidation/etc/module.xml <?xml version=”1.0″?> <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”> <module… Continue reading magento 2 restrict phone number field in admin panel