Magento 2 – Add custom links to top menu

In this post we are discussing on how we can add custom menu to the magento 2 top menu

Add these code to YourTheme/Magento_Theme/layout/default.xml

 <referenceContainer name="catalog.topnav">
               <block before="-" class="Magento\Framework\View\Element\Html\Link\Current" name="your.link">
                    <arguments>
                        <argument name="label" xsi:type="string">Link-name</argument>
                        <argument name="path" xsi:type="string">Link-url</argument>
                    </arguments>
              </block> 
 </referenceContainer>

This is how we can add custom links to magento 2 top menu.

Magento2 – Direct Mysql Query without using model

In this post we are discussing about the mysql queries in magento2 that we can execute directly without using model

In Magento 1 it uses two resources one for read and another for write, and the scenario in Magento 2 is different, in this we have only one resource connection that can handle both read and write

Here is how we can do it

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('sms'); //gives table name with prefix
 
//Select Data from table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.
 
//Delete Data from table
$sql = "Delete FROM " . $tableName." Where sms_id = 1";
$connection->query($sql);
 
//Insert Data into table
$sql = "Insert Into " . $tableName . " (sms_id, destination, message) Values ('','944740850','Test')";
$connection->query($sql);
 
//Update Data into table
$sql = "Update " . $tableName . "Set destination = '9447408507' where sms_id = 1";
$connection->query($sql);

This is how we can do Direct Mysql Query without using model in Magento2

 

Magento 2 CLI Commands

  • Magento  Admin Url Info:
    ==> bin/magento info:adminuri
  • Magento Enable/Disable command :
    ==> magento module:disable Magento_Weee
    ==> magento module:enable Magento_Weee
  • Filemode Ignore Command:
    ==> git config core.fileMode false
  • Magento admin url command:
    ==> php bin/magento info:adminuri
  • Magento 2 reindex:
    ==> bin/magento indexer:reindex
  • Magento 2 cache:
    ==> bin/magento cache:flush
  • Magento 2 static content Deploy:
    ==> bin/magento setup:static-content:deploy
  • Magento 2 compile & Upgrade:
    ==> bin/magento setup:di:compile
    ==> bin/magento setup:upgrade (Update the database)
  • Magento 2 Folder Permissions:
    ==> find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento
    ==> sudo chmod -R 777 var pub