Category Archives: Magento 2

How To Print Error Info For Magento 2 Blank Page

I have a Magento 2 store and Its just showing me the blank page. How can I enable error reporting for Magento 2

To enable error reporting and print the error info directly for Magento 2 blank page.

  • Step 1:
    Connecting to your server via FTP/SFTP or Cpanel and find Magneto root folder
  • Step 2:
    Open “index.php” file and insert the following codes after frst “error_reporting(E_ALL); ini_set(‘display_errors’, 1);
  • Step 3:
    Refreshing your Magento 2 blank page and you will see the error info

How To Change Magento 2 Admin Account Password

I have installed the Magento 2 shop, would like to know how to reset my Magento 2 admin account’s password

  • Method 1:
    Via Mysql to update admin account’s password.

    UPDATE admin_user SET password = CONCAT(SHA2('xxYourNewPassword', 256), ':xx:1') WHERE username = 'admin';

    YourNewPassword = You new password
    admin = You admin account’s username

  • Method 2:
    Via “Forgot your password?” from Magento 2 admin login page
  • Method 3:
    Via Magento 2 CLI to create new Magento 2 admin account

    php bin/magento  admin:user:create --admin-user="[admin]" --admin-password="[newpassword]" --admin-email="[example@softwarehtec.com]"  --admin-firstname="[example]" --admin-lastname="[example]"

How To Change Magento 2 Backend Language

I have installed Magento 2 with English language, If would like to change English to other language for Magento 2 backend, what should I do

  • Step 1:
    Login in to admin panel
  • Step 2:
    Click System -> All Users
  • Step 3:
    Click your admin account
  • Step 4:
    Select the language from Interface Locale
  • Step 5:
    Click “Save User” button

How To Change Magento Database Info

I have changed my current database’s password, I would like to know how to change the database’s password for my current Magento store

The database info of Magento store was stored in ‘/app/etc/local.xml’

You will find similar content like following

<connection>
    <host><![CDATA[localhost]]></host>
    <username><![CDATA[username]]></username>
    <password><![CDATA[password]]></password>
    <dbname><![CDATA[database_name]]></dbname>
    <active>1</active>
</connection>

username : Your magento’s database’s username
password : Your magento’s database’s password
dbname : Your magento’s database name

Which File Store Magento 2 Database Credentials

I have updated the database’s password, I would like to know which file store the Magento 2 database credentials. So I can update it manually

The path of database configuration file should be

/app/etc/env.php

In this file, you will see the following similar key and update with your own database credentials for Magento 2

“host” => “localhost”,
“dbname” => “database-name”,
“username” => “database-username”,
“password” => “databae-password”,

How To Get Magento 2 Product’s Status

How can I get Magento 2 product’s status. e.g I would like to check if the Magento 2 product is disabled or not

Need to load Magento 2 product first and then call getStatus method to retrieve the status info of the Magento 2 product

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepositoryInterface = $objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productRepositoryInterface->getById($productId);
$status = $product->getStatus();

How To Generate PDF programmatically in Magento 2

I would like to create a PDF file, how can I generate PDF programmatically in Magento 2

To create a PDF file in Magento 2

Step 1Define Zend_Pdf object and set page size
Step 2Set style and font for new Magento 2 PDF file
Step 3Draw content by called drawText, drawRectangle or other methods
Step 4Call class FileFactory and saving the content as Magento PDF file

Here is the example to creating a PDF file in Magento 2

$pdf = new \Zend_Pdf();
$pdf->pages[] = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4);
$page = $pdf->pages[0]; // this will get reference to the first page.
$style = new \Zend_Pdf_Style();
$style->setLineColor(new \Zend_Pdf_Color_Rgb(0,0,0));
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES);
$style->setFont($font,15);
$page->setStyle($style);
$width = $page->getWidth();
$hight = $page->getHeight();
$x = 40;
$pageTopalign = 850; //default PDF page height
$y = $pageTopalign - 50;
$style->setFont($font,16);
$page->setStyle($style);
$page->drawText(__("Text Text"), $x + 5, $y+50, 'UTF-8');
$fileName = 'test.pdf';

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$fileFactory = $objectManager->get('Magento\Framework\App\Response\Http\FileFactory');

$fileFactory->create($fileName,$pdf->render(),\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,'application/pdf');