Categories
Magento 2

Magento 2 system config field dependent on previous field

In this post we will learn how to create a dependent field in Magento 2 admin system configuration field by XML.

So, now please open etc\adminhtml\system.xml file where this file is located in a custom module and define your configuration dropdown with a custom source model is the our first field.

Above xml code in which, on select field (custom_option_field) option with value “2” from a drop-down list a text field (dependant_field) will appear.

And if you want to create a field dependent on two or more values, use the follow code.

In above code if you select options with values “1” or “2” from (custom_option_field) dropdown list then the text field (dependant_field) will be appeared in the admin configuration.

After then, we need to create that source model for CustomOption:

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 adding breadcrumb via layout XML or Controller

How we can add breadcrumb in page layout or controller? In this post I have added two different example how to added custom breadcrumb via XML or PHP Controller.

Added breadcrumb by layout XML file:

Add new Block on body tag like referenceBlock name=”breadcrumbs”

Added breadcrumb by PHP Controller:

Open your page controller and find public function execute() method and add $breadcrumbs->addCrumb what you want.

After added any one method for breadcrumbs just run following command via cli and check breadcrumbs is working fine.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 admin error: Product does not exists

After migrating Magento to version I am facing below issues while navigating to Product page.

Error: Class Magento\Catalog\Model\Product\Attribute\Backend\LayoutUpdate does not exist

Also I am going to editing product in admin panel getting the below error

Error: Product does not exists

Product does not exists

In Magento 2 some version Magento created the LayoutUpdate file with the attributes custom_layout_update_file, When we revert back version, the attribute calling the file and cause the issue.

Solution:

Go to your Database and search in table eav_attribute table like below sql. If you will find two records and just remove them.

Find or Select query:

Delete query:

After delete two records from database run following command via cli

If you have redis, you will need to flush the cache from it.

redis-cli flushdb – Delete all the keys of the currently selected DB.
redis-cli flushall – Delete all the keys of all the existing databases, not just the currently selected one.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Getting exception: Missing required argument $options, when edit customer details from magento 2 admin.

Getting exception missing required argument $options, when edit customer details from magento 2 admin.

Exception:

Solution:

Open vendor\magento\module-eav\Model\Entity\Attribute\Source\Config.php file form Magento 2 project and update __construct method in very beginning of file.

To

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 module dependency – hard and soft dependencies

In this article today I will disuse about Magento 2 module dependency. In Magento 2 we can use two types of Magento module dependencies “Hard Dependency” and “Soft Dependency

Magento 2 dependencies of modules are defined in composer.json. Hard in section require, soft in section suggest

Magento 2 HARD dependency

Module with a hard dependency on another module cannot function without the module it depends on. In app/code/Vendor/Module/composer.json require section contains hard dependency definitions for the module.

For example:

Magento 2 SOFT dependency

We can set SOFT dependency by two way – One is make dependency on suggest section on Vendor/Module/composer.json, another one is sequence node of Vendor/Module/etc/module.xml file.

Module with a SOFT dependency on another module can function properly without the other module, even if it has a dependency on the other module. In app/code/Vendor/Module/composer.json suggest section contains soft dependency definitions for the module.

For example:

The sequence node of app/code/Vendor/Module/etc/module.xml file file also contains soft dependency definitions for the module.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 – Admin form UI Component ImageUploader Field.

In this article today I will disuse about Magento 2 – admin form UI Component imageUploader field. This article is include all steps UI Components tutorial for image upload from your custom module. UI Component imageUploader xml form field, Show image in edit form, Save image info in database.

Below example code is based on a custom module “Extendfeature_RequestQuote” this is my custom module.

Best article for frontend custom form image uploader
Magento 2 – File or image upload via frontend custom module form and Controller

Step 1: Add UI Component imageUploader field

Please add/create following UI component imageUploader code in your UI form located in Extendfeature/RequestQuote/view/adminhtml/ui_component/form.xml file. My image uploader field name is “filesubmission” show field as “File Attachment” in admin form.

Step 2: Create image-preview.html template file

Please add/create image preview template with following code located in Extendfeature/RequestQuote/view/adminhtml/web/template/image-preview.html file.

Step 3: Crate image upload admin Controller file

Now create a adminhtml image upload Controller Filesubmission.php for image upload in Extendfeature\RequestQuote\Controller\Adminhtml\Requestquote\Filesubmission.php file with following code.

Step 4: Crate image upload Model

Now we create a image upload Model ImageUploader.php, in this we added more methods related upload image into pub/media/requestaquote directory, here “requestaquote” is IMAGE_UPLOAD_DIRECTORY name. Please create a model file with following code.

Step 5: Define Image Uploader configuration in di.xml file

Define Image Uploader configuration in your module di di.xml file with following code, File located in Extendfeature/RequestQuote/etc/di.xml.

Magento 2 - Admin form UI Component ImageUploader Field

Step 6: Image name save into the database field

To save image name into the database field please add follow below code into Save controller Extendfeature/RequestQuote/Controller/Adminhtml/Requestquote/Save.php file inside execute method.

Step 7: Display image after save records in edit form

Now add following code into DataProvider like Extendfeature/RequestQuote/Model/Requestquote/DataProvider.php File to display image after save records inside public function getData() method.

Now, Execute below commands via SHELL and enjoy image uploader function in your UI form.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
Magento 2

Magento 2 – File or image upload via frontend custom module form and Controller

Today I will discuse how to File or image upload via frontend custom module form and Controller. Open your module form.phtml file and make sure that the form attribute method to post method=”post” and also make sure that the form attribute enctype like enctype=”multipart/form-data”.

Also make sure that INPUT field type attribute type=”file”, I have use file field name “filesubmission”.

Now open you costom module Controller php file VENDOR\MODULE\Controller\Index\Post.php and use some library class for DirectoryList, UploaderFactory and Filesystem in top of file below namespace.

Now add some protected on top of Controller class before __construct() method.

Now update your Controller method public function __construct() like below.

Now add code for fileupload in your Controller method public function execute(). You can see I do not use $_FILES Global Variable in Magento because it does not meet with Magento standards. Instead of $_FILES Variable please use $this->getRequest()->getFiles();

Here filesubmission is the input name and also the field name of database table.
Upload image file will be saved at pub/media/requestaquote directory.
And $data[‘filesubmission’] = $imagePath; the value of $imagePath; that will be saved in the database field.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to validate at least one checkbox in custom module form?

Today I will discuses, How to validate at least one checkbox in custom module form? Open your module form .phtml file and add the validation component on form tag, as a attribute like data-mage-init.

How to validate at least one checkbox in custom module form?

Add attribute on the form tag: data-mage-init='{“validation”:{}}’

Add some validation rules to your custom module form checkbox fields like data-validate=”{required:true, ‘validate-one-required-by-name’:true}”, Please see example checkbox form html code with validate-one-required-by-name below.

After form validate screen.

List of Magento 2 form validation rules

List of some Magento 2 validation rules you can use and their error message. You can find all methods yourself by looking in lib/web/prototype/validation.js on line 415

List of Magento 2 supported all form validation rules, jQuery validation rules

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE

Categories
Magento 2

Magento 2 – How to enable/disable WYSIWYG Editor?

In Magento 2 WYSIWYG Editor is an useful feature that allows users to directly see the appearence of the end result, helps users save a lot of time and produce greater results. In this tutorial, I will show you, How to enable/disable WYSIWYG Editor?

How to enable/disable WYSIWYG Editor?

Please follow this tutorial step by step how to enable/disable WYSIWYG Editor.

Step 1: Login into store admin and go to: STORES => Configuration page.

STORES => Configuration

Step 2: In the Configuration page go to General => Content Management to view WYSIWYG Options section.

Step 3: Enable WYSIWYG Editor is set to enable by default. Uncheck box “Use system value” and choose other option Disabled by default as shown in below picture.

 Enable WYSIWYG Editor

Click on “Save Config” button to save new changes.

Step 4: Finally, you need to clear cache by menu SYSTEM => Cache Management => Select All => Refresh => Submit

That’s all about How to enable/disable WYSIWYG Editor Magento 2 admin. Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE this post.

Categories
Magento 2

Magento 2 – Set page title by layout XML or Controller

By default URL showing as title but thats not good look that appears on the title bar when created a new custom module. There are 2 (two) ways of Set page title by layout XML or Controller.

1. From frontend view layout module_controller_action.xml by head and title tag.

2. From frontend view layout module_controller_action.xml by referenceBlock page.main.title and set setPageTitle argument tag.

Set page title by PHP Controller

Also we can set page title by PHP controller file controllerName.php in method public function execute()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE