<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Magento2 &#8211; BKaushik Blog</title>
	<atom:link href="https://bkaushik.com/category/magento2/feed/" rel="self" type="application/rss+xml" />
	<link>https://bkaushik.com</link>
	<description>Code. Build. Learn. Share.</description>
	<lastBuildDate>Thu, 03 Apr 2025 15:35:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>How to get Root Directory path in Magento 2</title>
		<link>https://bkaushik.com/magento2/how-to-get-root-directory-path-in-magento-2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:35:02 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=48</guid>

					<description><![CDATA[While building your custom extension, you will usually need path to your extensions files. If you need to root the directory path in your custom module then, you need to inject \Magento\Framework\App\Filesystem\DirectoryList class in your construct. So, Let’s check the below steps with output. &#60;?php namespace Kaushik\Helloworld\Helper; use Magento\Framework\App\Helper\AbstractHelper; class Data extends AbstractHelper { /** * @var...]]></description>
										<content:encoded><![CDATA[<p>While building your custom extension, you will usually need path to your extensions files. If you need to root the <a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/module-file-structure.html">directory</a> path in your custom module then, you need to inject <strong>\Magento\Framework\App\Filesystem\DirectoryList </strong>class in your construct.</p>
<p>So, Let’s check the below steps with output.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?php
namespace Kaushik\Helloworld\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
class Data extends AbstractHelper
{

/**
 * @var \Magento\Framework\App\Filesystem\DirectoryList
 */
protected $dir;

public function __construct(
    ...
    \Magento\Framework\App\Filesystem\DirectoryList $dir,
    ...        
) {
    ...
    $this-&gt;dir = $dir;
    ...
}

public function getRootPath()
{
    return $this-&gt;dir-&gt;getRoot(); // Output : /var/www/html
}
}</pre>
<p>However, If you want to get a media, var, pub, etc. directory path then, you can use the below codes to get the appropriate directory path.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">$this-&gt;dir-&gt;getPath('pub'); // Output : /var/www/html/pub</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">$this-&gt;dir-&gt;getPath('media'); // Output : /var/www/html/pub/media</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">$this-&gt;dir-&gt;getPath('lib_internal'); // Output : /var/www/html/lib/internal</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">$this-&gt;dir-&gt;getPath('log'); // Output : /var/www/html/var/log</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">$this-&gt;dir-&gt;getPath('generated'); // Output: /var/www/html/generated</pre>
<p>That’s it !!!</p>
<p>In other words, You can use the above code in your function based on your requirement.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to create Cron Job in Magento 2</title>
		<link>https://bkaushik.com/magento2/how-to-create-cron-job-in-magento-2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:34:29 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=46</guid>

					<description><![CDATA[In this article, we will learn how to create cron job in Magento. Magento uses Cron Jobs to run scheduled tasks, reindexing, generating emails, newsletters, sitemaps and much more. Cron job is a great feature by Linux, the free operating system for the user. The cron job will create a command or a script that is appropriate with...]]></description>
										<content:encoded><![CDATA[<p>In this article, we will learn how to create cron job in Magento. Magento uses Cron Jobs to run scheduled tasks, reindexing, generating emails, newsletters, sitemaps and much more.</p>
<p><strong>Cron job</strong> is a great feature by Linux, the free operating system for the user. <strong>The cron job</strong> will create a command or a script that is appropriate with the task you want to do. Instead of manual working, the <strong>cronjob allows running automatically</strong> in exact time and date.</p>
<p>In this example, we are using a sample module with Kaushik as the Vendor name and HelloWorld as the module name.</p>
<h4><b>Step 1: Create crontab.xml</b></h4>
<p>File: <code>app/code/Kaushik/HelloWorld/etc/crontab.xml</code></p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?xml version="1.0"?&gt;
&lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"&gt;
    &lt;group id="default"&gt;
        &lt;job name="custom_cronjob" instance="Kaushik\HelloWorld\Cron\Test" method="execute"&gt;
            &lt;schedule&gt;* * * * *&lt;/schedule&gt;
        &lt;/job&gt;
    &lt;/group&gt;
&lt;/config&gt;</pre>
<ul>
<li><code>group id</code> is your cron group name. You can run only cron for single group at a time.</li>
<li><code>job instance</code> is class to be instantiated.</li>
<li><code>job method</code> is method in <code>job instance</code> to call.</li>
<li><code>job name</code> is Unique ID for this cron job.</li>
<li><code>schedule</code> is schedule in cron format where</li>
</ul>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">* * * * * command to be executed
| | | | |
| | | | +----- Day of week (0 - 7) (Sunday=0 or 7)
| | | +------- Month (1 - 12)
| | +--------- Day of month (1 - 31)
| +----------- Hour (0 - 23)
+------------- Minute (0 - 59)</pre>
<h4><b>Step 2: Create a class to run cron</b></h4>
<p>File: <code>app/code/Kaushik/HelloWorld/Cron/Test.php</code></p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?php
namespace Kaushik\HelloWorld\Cron;

use \Psr\Log\LoggerInterface;
class Test {
  protected $logger;

  public function __construct(LoggerInterface $logger) {
    $this-&gt;logger = $logger;
  }

  /**
    * Write to system.log
    *
    * @return void
  */
  public function execute() {
    // Do your Stuff
    $this-&gt;logger-&gt;info('Cron Works');
  }
}</pre>
<p>In the above code, we created a log. Once the cron is executed, the contents of the ‘execute’ method will be added in the system.log file.</p>
<h4><b>Step 3: Run the cron job</b></h4>
<p>We can run the Magento cron jobs using the below command.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">php bin/magento cron:run</pre>
<p>I hope this is useful blog for you.</p>
<p>Thank you for reading!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Create custom API in Magento 2</title>
		<link>https://bkaushik.com/magento2/create-custom-api-in-magento-2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:33:48 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=44</guid>

					<description><![CDATA[Today I’d like to help you through the process of creating Custom API in Magento 2. At first, we must create the primary files of a module and I would create module under Kaushik name space and call it CustomApi. File – app/code/Kaushik/CustomApi/etc/module.xml &#60;?xml version="1.0"?&#62; &#60;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"&#62; &#60;module name="Kaushik_CustomApi" setup_version="1.0.0" /&#62; &#60;/config&#62; &#160; File –...]]></description>
										<content:encoded><![CDATA[<p>Today I’d like to help you through the process of creating Custom API in Magento 2.</p>
<p>At first, we must create the primary files of a module and I would create module under <em>Kaushik</em> name space and call it <em>CustomApi</em>.</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/etc/module.xml</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?xml version="1.0"?&gt;
&lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"&gt;
    &lt;module name="Kaushik_CustomApi" setup_version="1.0.0" /&gt;
&lt;/config&gt;</pre>
<p>&nbsp;</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/registration.php</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Kaushik_CustomApi',
    __DIR__
);</pre>
<p>&nbsp;</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/etc/webapi.xml</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?xml version="1.0" ?&gt;
&lt;routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"&gt;
    &lt;route method="GET" url="/V1/kaushik-customapi/post"&gt;
        &lt;service class="Kaushik\CustomApi\Api\PostManagementInterface" method="getPost"/&gt;
        &lt;resources&gt;
            &lt;resource ref="anonymous"/&gt;
        &lt;/resources&gt;
    &lt;/route&gt;
&lt;/routes&gt;</pre>
<p>&nbsp;</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/etc/di.xml</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?xml version="1.0" ?&gt;
&lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"&gt;
    &lt;preference for="Kaushik\CustomApi\Api\PostManagementInterface" type="Kaushik\CustomApi\Model\PostManagement"/&gt;
&lt;/config&gt;</pre>
<p>&nbsp;</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/Model/PostManagement.php</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?php 
namespace Kaushik\CustomApi\Model;
 
class PostManagement {

    /**
     * {@inheritdoc}
     */
    public function getPost($param)
    {
        return 'api GET return the $param ' . $param;
    }
}</pre>
<p>&nbsp;</p>
<p><strong>File</strong> – app/code/Kaushik/CustomApi/Api/PostManagementInterface.php</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">&lt;?php 
namespace Kaushik\CustomApi\Api;
 
interface PostManagementInterface {

    /**
     * GET for Post api
     * @param string $param
     * @return string
     */
    public function getPost($param);
}</pre>
<p>&nbsp;</p>
<p>That’s all. We’ve just created custom API and now it’s ready to use.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>List of CLI Commands in Magento 2</title>
		<link>https://bkaushik.com/magento2/list-of-cli-commands-in-magento-2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:33:16 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=42</guid>

					<description><![CDATA[In this post I listed all the useful commands that we can use in Magento 2. Command like content deploy, indexing, setup upgrade, cache and other many more commands. By default, Magento 2 comes with multiple CLI Commands out of box. To use any command, simply type that command in the CLI, like php bin/magento...]]></description>
										<content:encoded><![CDATA[<p>In this post I listed all the useful commands that we can use in Magento 2. Command like content deploy, indexing, setup upgrade, cache and other many more commands.</p>
<p>By default, Magento 2 comes with multiple CLI Commands out of box. To use any command, simply type that command in the CLI, like <strong>php bin/magento cache:clean</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="classic">List Commands
php bin/magento  list                           php bin/magento l

Admin
php bin/magento admin:user:create               php bin/magento a:u:c
php bin/magento admin:user:unlock               php bin/magento a:u:u

Cache
php bin/magento cache:clean                     php bin/magento c:c
php bin/magento cache:disable                   php bin/magento c:d
php bin/magento cache:enable                    php bin/magento c:e
php bin/magento cache:flush                     php bin/magento c:f
php bin/magento cache:status                    php bin/magento c:s

Catalog
php bin/magento catalog:images:resize           php bin/magento c:i:r
php bin/magento catalog:product:attributes:cleanup      php bin/magento c:p:a:c

Cron
php bin/magento cron:run                         php bin/magento c:r

Customer
php bin/magento customer:hash:upgrade            php bin/magento c:h:u

Deploy
php bin/magento deploy:mode:set                  php bin/magento d:m:se
php bin/magento deploy:mode:show                 php bin/magento d:m:sh

Dev
php bin/magento dev:source-theme:deploy          php bin/magento d:source-theme:d
php bin/magento dev:tests:run                    php bin/magento d:t:r
php bin/magento dev:urn-catalog:generate         php bin/magento d:urn-catalog:g
php bin/magento dev:xml:convert                  php bin/magento d:x:c

i18n
php bin/magento i18n:collect-phrases             php bin/magento i:collect-phrases
php bin/magento i18n:pack                        php bin/magento i:p
php bin/magento i18n:uninstall                   php bin/magento i:u

Indexer
php bin/magento indexer:info                     php bin/magento i:i
php bin/magento indexer:reindex                  php bin/magento i:rei
php bin/magento indexer:reset                    php bin/magento i:res
php bin/magento indexer:set-mode                 php bin/magento i:set
php bin/magento indexer:show-mode                php bin/magento i:show
php bin/magento indexer:status                   php bin/magento i:st

Info
php bin/magento info:adminuri                               php bin/magento i:a
php bin/magento info:backups:list                           php bin/magento i:b:l
php bin/magento info:currency:list                          php bin/magento i:c:l
php bin/magento info:dependencies:show-framework            php bin/magento i:d:show-framework
php bin/magento info:dependencies:show-modules              php bin/magento i:d:show-modules
php bin/magento info:dependencies:show-modules-circular     php bin/magento i:d:show-circular
php bin/magento info:language:list                          php bin/magento i:l:l
php bin/magento info:timezone:list                          php bin/magento i:t:l

Maintenance
php bin/magento maintenance:allow-ips            php bin/magento ma:a
php bin/magento maintenance:disable              php bin/magento ma:d
php bin/magento maintenance:enable               php bin/magento ma:e
php bin/magento maintenance:status               php bin/magento ma:s

Module
php bin/magento module:disable                   php bin/magento mo:d
php bin/magento module:enable                    php bin/magento mo:e
php bin/magento module:status                    php bin/magento mo:s
php bin/magento module:uninstall                 php bin/magento mo:u

Setup
php bin/magento setup:backup                     php bin/magento se:b
php bin/magento setup:config:set                 php bin/magento se:c:se
php bin/magento setup:cron:run                   php bin/magento se:c:r
php bin/magento setup:db-data:upgrade            php bin/magento se:db-data:u
php bin/magento setup:db-schema:upgrade          php bin/magento se:db-schema:u
php bin/magento setup:db:status                  php bin/magento se:d:st
php bin/magento setup:di:compile                 php bin/magento se:d:c
php bin/magento setup:install                    php bin/magento se:i
php bin/magento setup:performance:generate-fixtures      php bin/magento se:p:generate-fixtures
php bin/magento setup:rollback                   php bin/magento se:r
php bin/magento setup:static-content:deploy      php bin/magento se:s:d
php bin/magento setup:store-config:set           php bin/magento se:sto:s 
php bin/magento setup:uninstall                  php bin/magento se:un
php bin/magento setup:upgrade                    php bin/magento se:up

Sample Data
php bin/magento sampledata:deploy                php bin/magento ma:d
php bin/magento sampledata:remove                php bin/magento sa:rem
php bin/magento sampledata:reset                 php bin/magento sa:res

Theme
php bin/magento theme:uninstall                  php bin/magento t:u</pre>
<p>That&#8217;s all.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Description of Magento 2 Directory Structure</title>
		<link>https://bkaushik.com/magento2/description-of-magento-2-directory-structure/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:31:59 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=38</guid>

					<description><![CDATA[What are the naming conventions, and how are namespaces established? The root Magento directory contains these primary folders: app/code: where your custom modules are found. Hopefully, very few 3rd- party modules are installed here because it is difficult to remember to keep these up-to-date. Installing modules through Composer provides the module vendor with an easier...]]></description>
										<content:encoded><![CDATA[<h3><span style="color: #000080;"><strong>What are the naming conventions, and how are namespaces established?</strong></span></h3>
<div class="page" title="Page 14">
<div class="section">
<div class="layoutArea">
<div class="column">
<div class="page" title="Page 14">
<div class="section">
<div class="layoutArea">
<div class="column">
<p>The root Magento directory contains these primary folders:</p>
<div class="page" title="Page 14">
<div class="section">
<div class="layoutArea">
<div class="column">
<ul>
<li><code>app/code</code>: where your custom modules are found. Hopefully, very few 3rd- party modules are installed here because it is difficult to remember to keep these up-to-date. <strong><strong><strong>Installing modules through Composer provides the module vendor with an easier way to automatically update their modules and dependencies.</strong></strong></strong></li>
<li><code>app/design/[frontend or adminhtml]</code>: this is where themes are stored.</li>
<li><code>app/i18n</code>: this is where translation (language) packages are stored.</li>
<li><code>app/etc/</code>: this is where the configuration files are stored:
<ul>
<li><code>app/etc/env.php</code>: this is the configuration file that is per environment. This contains your database, redis, and queueing (Advanced Message Queuing Protocol or AMQP) configuration, among other things. This file should NOT be in your Git repository as it contains sensitive information.</li>
<li><code>app/etc/config.php</code>: this file should be committed to your Git repository. It ultimately merges with the <code>env.php</code> file. This holds the configuration for enabling/disabling modules and can include defaults for Store Configuration and theming.</li>
</ul>
</li>
<li><code>bin/</code>: you will type the command <code>bin/magento</code> thousands of times in your tenure as Magento developer &#8230; so this is where this file is stored.</li>
<li><code>dev/</code>: this contains the configuration for built-in tools, such as Grunt. It also contains Magento&#8217;s test suite.</li>
<li><code>generated/</code>: files in this folder are created by Magento. While it is technically safe to delete in production, it&#8217;s a bad idea as it will result in downtime or a slowdown on the website while Magento rebuilds this directory. This is where Magento stores factory classes, interceptor classes (used to make plugins work), proxy classes (used to lazy-load methods to prevent the constructor from triggering too early and causing a problem elsewhere in the system), and extension attribute interfaces and classes.</li>
<li><code>lib/</code>: this folder contains the internal libraries on which Magento relies. Note that jQuery is found in <code>lib/web/jquery/</code>.</li>
<li><code>pub/</code>: this is the directory that should be HTTP root (i.e., the directory that is browsed when you go to https://bkaushik.com) for the webserver. While the root Magento folder would work, you risk exposing folders such as your <code>var</code> folder with a misconfiguration. When you browse to a Magento website, the webserver first checks to see if that exact path exists as a file. If it doesn&#8217;t, the <code>.htaccess</code> or Nginx configuration rewrites the request to <code>pub/index.php</code>, which begins the normal Magento request.
<ul>
<li><code>pub/media/</code>: this is where the website&#8217;s images are stored.</li>
<li><code>pub/static/</code>: this contains the .css, .js and .html files that have been processed and are ready for the end-user to download. If a path is requested but doesn&#8217;t exist as a file in this folder, Magento tries to create it when not in production mode (or if you add a store with a new language). If your website is in <code>developer</code> mode, and you run <code>bin/magento dev:source- theme:deploy</code>, most files in this directory will be symlinked to their sources throughout the Magento codebase. In production mode, you run <code>bin/magento setup:static-content:deploy</code> to process and copy files to this directory.<br />
<strong>What&#8217;s the difference?</strong> <code>dev:source-theme:deploy</code> creates symlinks from module&#8217;s LESS files into the <code>pub/static</code> directory. This allows LESS files changes, in modules, to always be of the latest version. <code>setup:static-content:deploy</code> copies all necessary files (JS, HTML and LESS compiled to CSS) to the <code>pub/static</code> directory. Once this command is run, changes to your LESS and JS files in your module will not be visible on the frontend.</li>
</ul>
</li>
<li><code>setup/</code>: this directory contains important files related to installing Magento. If your webserver is configured so that the document root matches the Magento root directory (ie, not <code>/pub</code>), you can browse to your website <code>/setup</code> URL. This configuration should be very temporary, and production&#8217;s document root should always be <code>/pub</code>. Why? Because a simple misconfiguration (face it, this can happen) can expose sensitive information in the <code>var/</code> or other directories. Magento provides an easy way to avoid this issue by ensuring a correct document root.
<div class="page" title="Page 17">
<div class="section">
<div class="layoutArea">
<div class="column">
<p><strong>But what if I need to install Magento?</strong> Either use the <code>/setup</code> URL (by changing your application&#8217;s document root) temporarily. Or, better yet, use the CLI command: <code>bin/magento setup:install</code>.</p>
</div>
</div>
</div>
</div>
</li>
<li><code>var/</code>: this directory contains files that are temporarily used by the Magento application or results from using it. For example, logs are in <code>var/log/</code>. Error reports are in var/report. If you are using the file-system cache, this is stored in <code>var/cache</code> and <code>var/page_cache</code>. You should only use file- system caches in your development environment and never on production. The reason is that file-system storage prevents horizontal scaling (scaling Magento to multiple stand-alone instances)</li>
<li><code>vendor/</code>: this is where all of the Composer-installed modules are located.<br />
This directory can be deleted and re-created at any time on your development machine (doing this in production would result in your store being down). To create this directory, run <code>composer install</code> (this command is different than <code>composer update</code> in that <code>install</code> doesn&#8217;t change any versions and only installs what is specified in <code>composer.lock</code>).</p>
<div class="page" title="Page 17">
<div class="section">
<div class="layoutArea">
<div class="column">
<p>Because of this, it goes without saying that code in the <code>vendor/</code> directory should never be modified. Doing so will be temporary and these changes will be destroyed next time you run <code>composer update</code> or <code>composer install</code>.</p>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to use Configuration Files in Magento 2</title>
		<link>https://bkaushik.com/magento2/determine-how-to-use-configuration-files-in-magento2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Thu, 03 Apr 2025 15:31:12 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=36</guid>

					<description><![CDATA[A module&#8217;s configuration files are stored in your modules etc/ directory, like app/code/Kaushik/HelloWorld/etc/. In there, you will find several important files. Many of these files can be found in a module&#8217;s etc/ directory. However, you sequester these to a particular area (frontend, adminhtml, webapi_rest, as a couple of examples). This is useful if you want...]]></description>
										<content:encoded><![CDATA[<p>A module&#8217;s configuration files are stored in your modules <code>etc/</code> directory,<br />
like <code>app/code/Kaushik/HelloWorld/etc/</code>. In there, you will find several important files.</p>
<div class="page" title="Page 19">
<div class="section">
<div class="layoutArea">
<div class="column">
<p>Many of these files can be found in a module&#8217;s <code>etc/</code> directory. However, you sequester these to a particular area (<code>frontend</code>, <code>adminhtml</code>, <code>webapi_rest</code>, as a couple of examples). This is useful if you want a particular modification to only affect a particular area. For example, let&#8217;s say you want to prevent a payment method from being used on the frontend. You would configure an event observer in <code>etc/frontend/events.xml</code> (notice the <code>frontend</code> directory = the <code>frontend</code> area code) to observe the <code>payment_method_is_active</code> event. You would then create a class for this observer that implements the <code>ObserverInterface</code>.</p>
<div class="page" title="Page 19">
<div class="section">
<div class="layoutArea">
<div class="column">
<p>These are the most common ones:</p>
<ul>
<li><code>module.xml</code>: this file defines the module and what modules on which your module depends.</li>
<li><code>acl.xml</code>: this creates permissions that can be referenced in a module. An admin can enable/disable these permissions for a particular role.</li>
<li><code>catalog_attributes.xml</code>: this instructs Magento to automatically load specified attributes for particular entities. These attributes are usually installed by the module (in a Data Patch, in your module&#8217;s <code>Setup/Patch/Data/</code> directory).</li>
<li><code>config.xml</code>: this file stores default values for Stores &gt; Configuration values that you configure in <code>etc/adminhtml/system.xml</code>.</li>
<li><code>crontab.xml</code>: this is where you configure scheduled jobs.</li>
<li><code>db_schema.xml</code>: this is how you add and update tables in the database. The sister file, <code>db_schema_whitelist.json</code> will be also stored in the <code>etc/</code> directory.</li>
<li><code>di.xml</code>: this file contains plugin details and configuration of Magento&#8217;s Dependency Injection framework.</li>
<li><code>email_templates.xml</code>: this is where you configure email templates and their associated <code>.html</code> template.</li>
<li><code>events.xml</code>: when you need functionality to execute in response to an action taken in Magento, creating an event observer may be the best solution.<br />
In this file, you configure what classes + methods response (observe) a given event. This file can also be placed into a particular area&#8217;s directory (<code>frontend</code> for example) to limit when this observer is triggered.</li>
<li><code>extension_attributes.xml</code>: this file configures extension attributes. Magento has many models created (Order, Order Item, Customer, etc.). There are many cases in which you want to attach more information (&#8220;have we exported this order to our ERP?&#8221;). Each extension attribute has a type (<code>bool</code>, <code>string</code>, <code>OrderDetails</code> class, as examples). Classes that can use extension attributes extend <code>\Magento\Framework\Model\AbstractExtensibleModel</code>.</li>
<li><code>adminhtml/menu.xml</code>: this adds and customizes the Magento admin menu.</li>
<li><code>product_options.xml</code>: this configures new types of custom options for a Magento product. For example, you can use an entry in this file to create a &#8220;Length&#8221; attribute for custom-sized products.</li>
<li><code>product_types.xml</code>: this is where you set up a new product type. For example, if you need to create a new Kit product type (as a modification of a Grouped product), you would configure that in this file.</li>
<li><code>sales.xml</code>: adds a new total, for example, a &#8220;fee.&#8221;</li>
<li><code>system.xml</code>: this adds new entries into Stores &gt; Configuration.</li>
<li><code>webapi.xml</code>: this configures a new API request route.</li>
<li><code>widget.xml</code>: this configures a new CMS widget.</li>
<li><code>routes.xml</code>: this file tells Magento about a URL path that your module will understand. We will talk about this more later but for now, when you browse to <code>bkaushik.com/cms/page/view/id/1</code>, the route <code>frontName</code> (for the sake of consistency, <code>id</code> should match) would be <code>cms</code>. This matches the first word in the path.<br />
One thing to note: the <code>frontName</code> and <code>id</code> can be different. frontName determines the word(s) that are matched in the URL. The <code>id</code> is used to create the Layout XML handle. In the above example, if this is a code snippet:</p>
<div class="page" title="Page 21">
<div class="section">
<div class="layoutArea">
<div class="column">
<p><code>&lt;route id="content_management_system" frontName="cms"&gt; </code><br />
<code>...</code><br />
<code>&lt;/route&gt;</code></p>
<p>Our layout XML file to accommodate this request would be:</p>
<p><code>app/code/Kaushik/HelloWorld/view/frontend/layout/content_management_system_page_view.xml</code></p>
<p>&nbsp;</p>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Manage Fastly VCL snippets using the API</title>
		<link>https://bkaushik.com/magento2/manage-fastly-vcl-snippets-using-the-api/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Wed, 02 Apr 2025 18:03:24 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=10</guid>

					<description><![CDATA[Delete a snippet 1. Save Fastly service credentials as bash environment variables export FASTLY_SERVICE_ID=&#60;Service ID&#62; export FASTLY_API_TOKEN=&#60;API Token&#62; 2. Check active VCL version curl -H "Fastly-Key: $FASTLY_API_TOKEN" https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/active 3. Save active version number returned in the "number" key export FASTLY_VERSION_ACTIVE=&#60;version&#62; 4. Clone active VCL version and all snippets curl -H "Fastly-Key: $FASTLY_API_TOKEN" https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_VERSION_ACTIVE/clone -X PUT 5. Save the...]]></description>
										<content:encoded><![CDATA[<h2 id="ManageFastlyVCLsnippetsusingtheAPI-Deleteasnippet">Delete a snippet</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">
<strong>1. Save Fastly service credentials as bash environment variables</strong>
<em>export FASTLY_SERVICE_ID=&lt;Service ID&gt;</em>
<em>export FASTLY_API_TOKEN=&lt;API Token&gt;</em>

<strong>2. Check active VCL version</strong>
curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a class="external-link" href="https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/active" rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/active</a>

<strong>3. Save active version number returned in the "<u>number</u>" key</strong>
<em>export FASTLY_VERSION_ACTIVE=&lt;version&gt;</em>

<strong>4. Clone active VCL version and all snippets</strong>
<em>curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a class="external-link" href="https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_VERSION_ACTIVE/clone" rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_VERSION_ACTIVE/clone</a> -X PUT</em>

<strong>5. Save the new version number returned in the "number" key</strong>
<em>export FASTLY_EDIT_VERSION=&lt;Version&gt;</em>

<strong>6. Delete an individual VCL snippet</strong>
<em>curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/snippet/&lt;snippet_name</a>&gt; -X DELETE
</em>Note: name of snippet created from admin UI is prefixed with "magentomodule_" in Fastly. For eg. addForwardSlash in admin will be magentomodule_addForwardSlash in Fastly.
<strong>To list all regular VCL snippets:</strong> <em>curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a class="external-link" href="https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_VERSION/snippet" rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/snippet</a></em>

<strong>7. Validate custom VCL snippets</strong>
<em>curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a class="external-link" href="https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/validate" rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/validate</a></em>

<strong>8. Activate VCL snippets</strong>
<em>curl -H "Fastly-Key: $FASTLY_API_TOKEN" <a class="external-link" href="https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/activate" rel="nofollow">https://api.fastly.com/service/$FASTLY_SERVICE_ID/version/$FASTLY_EDIT_VERSION/activate</a> -X PUT</em>
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Magento 2 admin token using Rest API &#038; CURL</title>
		<link>https://bkaushik.com/magento2/magento-2-admin-token-using-rest-api-curl/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Wed, 02 Apr 2025 18:03:24 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=11</guid>

					<description><![CDATA[Magento access token is used to synchronize and work with any third-party applications. Using the Magento Rest API provided, you can create, authenticate, and remove a token and its access. ************* curl POST HTTP token authentication **************** curl -XPOST -H 'Content-Type: application/json' http://magento231.local/rest/V1/integration/admin/token -d '{ "username": "admin", "password": "admin@123" }' ************* curl GET HTTP token...]]></description>
										<content:encoded><![CDATA[<p>Magento access token is used to synchronize and work with any third-party applications.</p>
<p>Using the Magento Rest API provided, you can create, authenticate, and remove a token and its access.</p>
<p>************* curl POST HTTP token authentication ****************<br />
<code class="EnlighterJSRAW" data-enlighter-language="generic">curl -XPOST -H 'Content-Type: application/json' http://magento231.local/rest/V1/integration/admin/token -d '{ "username": "admin", "password": "admin@123" }'</code></p>
<p>************* curl GET HTTP token authentication ****************<br />
<code class="EnlighterJSRAW" data-enlighter-language="generic">curl -X GET "http://www.magento231.local/rest/all/V1/store/storeViews" -H "accept: application/json" -H "Authorization: Bearer 0kze3s5uy6vwn8fvzt6e23gwbwhrj72i"</code></p>
<p>************* curl PUT HTTP token authentication ****************<br />
<code class="EnlighterJSRAW" data-enlighter-language="generic">curl -X PUT "http://www.magento231.local/rest/all/V1/eav/attribute-sets/1" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer 0kze3s5uy6vwn8fvzt6e23gwbwhrj72i" -d "{ \"attributeSet\": { \"attribute_set_id\": 0 }}"</code></p>
<p>************* curl DELETE HTTP token authentication ****************<br />
<code class="EnlighterJSRAW" data-enlighter-language="generic">curl -X DELETE "http://www.magento231.local/rest/all/V1/eav/attribute-sets/1" -H "accept: application/json" -H "Authorization: Bearer 0kze3s5uy6vwn8fvzt6e23gwbwhrj72i"</code></p>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Magento 2 Send bulk emails using SendGrid API</title>
		<link>https://bkaushik.com/magento2/magento-2-send-bulk-emails-programmatically-using-sendgrid-api/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Wed, 02 Apr 2025 18:03:24 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=12</guid>

					<description><![CDATA[Here in this post, I&#8217;m going to show how you can send bulk transactional emails programmatically using SendGrid API &#38; an email template created in Magento. Before getting started, let&#8217;s understand the used table&#8217;s role in this script. customer_data_live =&#62; here we have a list of customers&#8217; emails with an email sent flag. block_email =&#62;...]]></description>
										<content:encoded><![CDATA[<p>Here in this post, I&#8217;m going to show how you can send bulk transactional emails programmatically using SendGrid API &amp; an email template created in Magento.</p>
<p>Before getting started, let&#8217;s understand the used table&#8217;s role in this script.</p>
<p><em>customer_data_live</em> =&gt; here we have a list of customers&#8217; emails with an email sent flag.</p>
<p><em>block_email</em> =&gt; here we have a list of customers who are blocked from sending emails.</p>
<p>&nbsp;</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;?php
ini_set("memory_limit", "-1");
ini_set('max_execution_time', 18000);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
include '/data/html/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap-&gt;getObjectManager();
$state = $objectManager-&gt;get('Magento\Framework\App\State');
$state-&gt;setAreaCode('frontend');
$resource = $objectManager-&gt;get('Magento\Framework\App\ResourceConnection');
$connection = $resource-&gt;getConnection();

shootMail($connection);

function  shootMail($connection){
    $sql  = "select `template_text` from `email_template` where template_id =10";  //get you email template id from admin
    $email_template =  $connection-&gt;fetchOne($sql);

    $customer_emails = getCustomerList($connection);
    foreach  ($customer_emails as $email)
    {
        $customer_email = $email['email']; 
        $entity_id = $email['entity_id']; 
        $notblocklisted = checkifblocklisted($connection,$customer_email);   //ignore this if you have no any blocked emails record in any custom table
        if($notblocklisted==false)
        {
            $response  = sendEmail($connection,$customer_email,$email_template);
            $sql  = "update `customer_data_live` set `mail_sent` ='$response' where entity_id ='$entity_id'";
            $connection-&gt;query($sql);
        } else 
        {
            $sql  = "update `customer_data_live` set `mail_sent` ='blocklisted_email' where entity_id ='$entity_id'";
            $connection-&gt;query($sql);
        }
    }

}

function sendEmail($connection,$customer_email,$message_text)
{
    $response_mesage=NULL;
    $subject="Celebrating the Sale"; 
    $url = 'https://api.sendgrid.com/';
    $user = 'example@gmail.com';
    $pass = 'test@132';     
    $json_string = array(   
        'category' =&gt;'no-reply'    
    );  

    $fromaddress='Sales'; 
    $from='sales@example.com';
    $request = $url . 'api/mail.send.json';
    $html = $message_text;
    $html = urlencode($html);             
    $session = curl_init($request);   
            
    curl_setopt($session, CURLOPT_POSTFIELDS, "api_user=".$user."&amp;api_key=".$pass."&amp;x-smtpapi=".json_encode($json_string)."&amp;X-PM-TrackOpens=true&amp;to[]=$customer_email&amp;subject=".$subject."&amp;html=".$html."&amp;fromname=".$fromaddress."&amp;from=$from");curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $response = json_decode(curl_exec($session),true);
    if(!empty($response) &amp;&amp;  is_array($response))
    {
        $response_mesage = $response['message']; 

    }
    curl_close($session);   
    return  $response_mesage;       

}

function getCustomerList($connection){
    $sql =  "SELECT `email`,`entity_id` FROM `customer_data_live` where  mail_sent is  null limit 20";
    return $connection-&gt;fetchAll($sql);
}

function  checkifblocklisted($connection,$email){
    $sql  = "select email from `block_email` where email ='$email'";
    $email =  $connection-&gt;fetchOne($sql);
    if(!empty($email))
    {
        return true;
    }
    return false;
}</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to redirect to previous page in Magento 2</title>
		<link>https://bkaushik.com/magento2/how-to-redirect-to-previous-page-in-magento2/</link>
		
		<dc:creator><![CDATA[Bikash]]></dc:creator>
		<pubDate>Wed, 02 Apr 2025 18:03:23 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<guid isPermaLink="false">https://bkaushik.com/?p=9</guid>

					<description><![CDATA[In Magento 2, You can redirect to the previous page. This allows customers to redirect back to the page from where the customer came. In Your Controller write the following code: &#60;?php namespace Company\Module\Controller\Index; use Magento\Framework\Controller\ResultFactory; class Actionname name extends \Magento\Framework\App\Action\Action { public function execute() { $resultRedirect = $this-&#62;resultFactory-&#62;create(ResultFactory::TYPE_REDIRECT); //your code work around here $resultRedirect-&#62;setUrl($this-&#62;_redirect-&#62;getRefererUrl());...]]></description>
										<content:encoded><![CDATA[<p>In Magento 2, You can redirect to the previous page. This allows customers to redirect back to the page from where the customer came.</p>
<p>In Your Controller write the following code:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="php">&lt;?php
namespace Company\Module\Controller\Index;
use Magento\Framework\Controller\ResultFactory; 

class Actionname name extends \Magento\Framework\App\Action\Action
{      
    public function execute()
    {
        $resultRedirect = $this-&gt;resultFactory-&gt;create(ResultFactory::TYPE_REDIRECT);

        //your code work around here

        $resultRedirect-&gt;setUrl($this-&gt;_redirect-&gt;getRefererUrl());
        return $resultRedirect;
    }
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
