Category Archives: Uncategorized

How To Get Current Magento 2 Store Info Programmatically

How can I get current Magento 2 store info from Block class programmatically. Like store name, store id, store code, store url, is store active, website id and store name
To get current Magento 2 store’s info programmatically, you need load “Magento\Store\Model\StoreManagerInterface” object first and then call “getStore()” method to retrive current store object. Here is the example.

objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’);

Get current store’s  id

$storeManager->getStoreId();

Get current store’s code

$storeManager->getStoreCode();

Get current website ID

$storeManager->getWebsiteId();

Get current store’s name

$storeManager->getStoreName();

Get current store’s url

$storeManager->getStoreUrl();

Check current store is active or inactive

$storeManager->isStoreActive();

How Can I Add Featured Products To Magento 2 Home Page

I am looking for a way to add the featured products to my Magento 2 home page.
  1. Login to your backend and move to “content” -> “Pages”
  2. Find your home page and click edit
  3. Click Content tab and click “Show/Hide Editor” if you do not see editor bar
  4. Now click widget icon from editor bar
  5. Then select “Catalog Products List” from Widget Type and add your own Conditions rules for your Magneto 2 featured products

How To Create Magento 2 StoreGroup Programmatically

How can I create Magento 2’s StoreGroup programmatically, like from phtml

You can call ‘groupFactory ‘ class to create Magento 2’s Store Group and use the group resource model to save the group object. Here is the example to create a Magento 2’s store group programmatically

$groupFactory = \Magento\Framework\App\ObjectManager::getInstance()
            ->get('Magento\Store\Model\GroupFactory');
$groupResourceModel = \Magento\Framework\App\ObjectManager::getInstance()
            ->get('use Magento\Store\Model\ResourceModel\Group');
$group = $groupFactory->create();

$group->setWebsiteId(1);
$group->setName('Custom Store Group Name');
$group->setRootCategoryId(2);
$group->setDefaultStoreId(3); $groupResourceModel->save($group);

How To Upgrade Magento 2

I have a Magento 2.1 store, how can I upgrade it to the latest version e.g Magento 2.2

The easiest way to upgrade Magento is using Web Setup Wizard via the Magento backend.

Web Setup Wizard

  • Login to Magento admin

  • Click SYSTEM -> Web Setup Wizard

  • Click System Upgrade

  • Select version you would like to upgrade

There are other 2 ways to upgrade Magento 2

By Composer

If you would like to use composer to upgrade Magento 2, you will need to use SSH

  • Login via SSH and move to Magento 2 root folder
  • Remove everything from vendor folder
  • Change the versoin to the latest version e.g 2.2.5 from composer.json file
  • Run following command
    composer update

    It will ask you abount credentials and you can get – https://marketplace.magento.com/customer/accessKeys/

    Public key is your username
    Private Key is your password

Manually upgrade

You can download latest Magneto 2 files and upload all files via FTP/Cpanel

Once uploaded, just run the following command to upgrade the database, compile and deploy static content.

php bin/magento setup:upgrade
php bin/magento deploy:mode:set production

How Can I Add Page Title For A PDF File

How can I add page title for PDF file, I mean when I open the PDF by browser, I would like to customize the browser title and do not present the file name

To add page title for a PDF file, you need a PDF editor software. e.g Adobe Acrobat Pro

1. Open the PDF file by Adobe Acrobat Pro
2. Select File -> Properties
3. Description tab -> Title (Add or change)
4. Initial View tab -> Window Options section
5. Change option of “Show” to “Document Title”
6. Save your PDF file

How Can I Hide Price For Magento Guest

How can I hide the price for Magento if user not login, e,g on Magento product detail page and Magento cateogry page

From your price template
e.g “magento_root\app\design\frontend\default\\template\catalog\product\price.phtml”
, you can use Magento Method “isLoggedIn()” to detect if user login or not

<?php if(Mage::getSingleton('customer/session')->isLoggedIn()): ?>
/** move the price code (you would like to hide) to this area **/
<?php endif;  ?>

WordPress XML-RPC Brute Force Attacks With Multiple Logins

Recently, my WordPress site was attacked by XML-RPC Brute Force, I would like how to protect this kind of attack or any patch I can install

Brute Force attacks are one of the oldest and most common types of attacks. In fact, Brute Force attacks against any CMS. XML-RPC is a simple, portable way to make remote procedure calls over HTTP. It can be used with Perl, Java, Python, C, C++, PHP and many other programming languages. WordPress, Drupal and most content management systems support XML-RPC. One of the hidden features of XML-RPC is that you can use the system.multicall method to execute multiple methods inside a single request. So the attackers could try thousands of passwords with only 3 or 4 HTTP requests.

You can do following methods to protect your site.

1. If you have a dedicated server, you can install OSSEC
2. If you dont need XML-RPC, you can block all access to xmlrpc.php
3. If you can’t block XML-RPC, you can block system.multicall requests only

How To Reset WordPress Password Via FTP

How to reset WordPress password, if Lost your password is not working

If you’re using the default admin user of your WordPress site you can reset your password via FTP.

  1. Access your site via FTP and edit your activated theme’s functions.php file
  2. At the beginning after the opening <?php line, add the following:
    wp_set_password( 'password', 1 );

    In this command, the 1 is the user ID of your WordPress site, and password should be changed to your desired password.

  3. Save and upload this file to your WordPress site.
  4. After logging in, go back to the functions.php file of your activated theme and remove the code you just entered because it will reset your password every time the user logs in.