Posts

Add Admin User name and Action name in Order Comment Section through Action Performed from Sales Order Grid in Magento 2

  Step 1:  First, we need to create an “events.xml“ file inside our extension at the following path app\code\Vendor\Extension\etc\adminhtml\ Then add the code as follows. <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">     <event name="sales_order_save_after">         <observer name="sales_order_save_after_comment_history_add"           instance="\Vendor\Extension\Observer\OrderSaveAfter" />     </event> </config> Step 2:  After that, we need to create an “OrderSaveAfter.php” file inside our extension at the following path app\code\Vendor\Extension\Observer\ And embed the code as given below. <?php  namespace Vendor\Extension\Observer;   use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\RequestInterface; use Magento\Backen...

How to Remove JS and CSS using Layout XML in Magento 2

 Step 1: Go to your layout file app\code\Vendor\Extension\view\frontend\layout\your_layout_file.xml  To remove JS and CSS, you need to add <remove> tag in layout XML under the <head> tag. <?xml version="1.0"?>   <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">       <head>         <remove src="Vendor_Extension::css/custom.css"/>         <remove src="Vendor_Extension::js/custom.js"/>     </head>   </page>

How to Add Editable Field in Admin Order View Page in Magento 2

 Step 1: Go to the below file path app\code\Vendor\Extension\view\adminhtml\layout\sales_order_view.xml Then add the below code <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">     <body>         <referenceBlock name="order_additional_info">             <block class="Vendor\Extension\Block\Adminhtml\Order\Checkoutcustomformedit" name="admin.chekoutcustomfield" template="Vendor_Extension::checkoutcustomformedit.phtml" />         </referenceBlock>     </body> </page> Step 2: Next, move to the following file path app\code\Vendor\Extension\Block\Adminhtml\Order\Checkoutcustomformedit.php Now add the below-mentioned code snippet <?php namespace Vendor\Extension\Block\Adminhtml\Order;   use \Magento\Backend\Block\Templa...

How to Get Product Attribute List using Attribute Set ID in Magento 2

 <?php use \Magento\Framework\AppInterface; try { require __DIR__ . '/../app/bootstrap.php';  } catch (\Exception $e) { echo 'Autoload error: ' . $e->getMessage(); exit(1); } try { $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $productAttributesManagement = $objectManager->get('\Magento\Catalog\Api\ProductAttributeManagementInterface'); $productAttributesRepository = $objectManager->get('\Magento\Catalog\Api\ProductAttributeRepositoryInterface'); $attrubuteOptionRepository = $objectManager->get('\Magento\Catalog\Model\Product\Attribute\Repository'); $productAttributes = $productAttributesManagement->getAttributes(9); // enter attribute id $attributeData = array(); foreach($productAttributes as $key=>$val...

How to Join Two Tables and Create Admin Grid using UI Component in Magento 2

 Step 1: Firstly, you need to edit the di.xml file. For that go to the below path app/code/Vendor/Extension/etc/di.xml Now add the code as follows <?xml version="1.0"?>   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">     <!-- here we remove virtualType and defile collection as follow-->     <type name="Vendor\Extension\Model\ResourceModel\Custom\Grid\Collection">         <arguments>             <argument name="mainTable" xsi:type="string">magecomp_customtable</argument>             <argument name="eventPrefix" xsi:type="string">magecomp_grid_collection</argument>             <argument name="eventObject" xsi:type="string">magecomp_collection</argument>           ...

How to Set and Get Cookie in Magento 2

 <?php namespace Vendor\Extension\Model; class Customcookie {     private $customCookieManager;     private $customCookieMetadataFactory;     public function __construct(         \Magento\Framework\Stdlib\CookieManagerInterface $customCookieManager,         \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $customCookieMetadataFactory)    {         $this->customCookieManager = $customCookieManager;         $this->customCookieMetadataFactory = $customCookieMetadataFactory;     }     public function setCookie()     {         $customCookieMetadata = $this->customCookieMetadataFactory->createPublicCookieMetadata();         $customCookieMetadata->setDurationOneYear();         $customCookieMetadata->setPath('/');         $customCookieMe...

How to Reset Customer Password using Console Command in Magento 2

 Step 1: First, we need to create a “di.xml” file inside the extension etc directory of our extension. app\code\Vendor\Extension\etc Then add the below code <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">     <type name="Vendor\Extension\Command\Changepasswordcommand">         <arguments>             <argument name="resource" xsi:type="object">Magento\Customer\Model\ResourceModel\Customer\Proxy</argument>         </arguments>     </type>     <type name="Magento\Framework\Console\CommandList">         <arguments>             <argument name="commands" xsi:type="array">                 ...