Magento 2: Upload File & Image

This article shows how you can upload files and images in Magento 2. You can use this code in any custom module you build. Here’s the input file field HTML code: <input type="file" name="my_custom_file" id="my_custom_file" title="Custom File" class="input-text" data-validate="{required:true}"> Here’s the controller class file code: <?php namespace YourNamespace\YourModule\Controller; use Magento\Framework\App\Action\Context; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Filesystem; use … Read more

Magento 2: Return JSON, XML, HTML & Raw Text Data Response from Controller

This article shows how you can return JSON data, XML data, HTML data, or Raw Text data from any Controller class in Magento 2. Generally, in the Magento2 controller’s execute() function, we see the redirect or forwarding call which redirects to the specified URL page. However, we might sometime need to return the JSON format … Read more

Magento 2: Create, Edit, Delete Customer Attribute Programmatically

This article shows how you can programmatically add or create a new customer attribute in Magento 2. It also shows how you can update and delete/remove the customer attribute programmatically in Magento 2. I will also show how you can add the product attributes from both Install Script and Upgrade Script: – Add customer attribute … Read more

Magento 2: Create Product Attribute, Attribute Group/Tab & Attribute Set Programmatically

This article shows how you can programmatically add or create a new product attribute, product attribute group, and product attribute set in Magento 2. In this article, we will be looking at the following: Create Product Attribute Update Product Attribute Remove Product Attribute Create Product Attribute Group/Tab Add Product Attributes to the Attribute Group/Tab Create … Read more

Migrate data from Magento 1.x to Magento 2.x

This article shows how you can migrate data from Magento 1.x site to Magento 2.x site. We will use the Magento’s official Data Migration tool module. – The data migration can be done via the CLI commands. – The data like categories, products, orders, configuration settings, etc. can be migrated. -The data migration depends upon … Read more

Magento 2: Create Customer Programmatically

This article shows how you can create customers programmatically (through code) in Magento 2.x. I have also written a similar article on Creating Customer Programmatically in Magento 1.x. In this example code, I will show how you can save a customer with general information like firstname, lastname, and email. I will also show how you … Read more

Magento 2: Forbidden You don’t have permission to access /magento2/ on this server. Server unable to read htaccess file, denying access to be safe

I downloaded the latest Magento 2 version from the Magento download site. Then, extracted it on my Apache Webserver root directory. I renamed the extracted Magento directory as magento2. I installed Magento2 via command line. Now, when I browse http://127.0.0.1/magento2, I get the following error: Forbidden You don’t have permission to access /magento2/ on this … Read more