Magento 2.4.6 or Adobe Commerce 2.4.6 Installation Steps in XAMPP

Follow below steps.

Step [1] – System Requirement

Operating system:

Windows 11
Linux x86-64 (such as Red Hat Enterprise Linux, CentOS, Ubuntu, Debian, etc.)
macOS (only for local development environments)

Web server:

Apache 2.4 or later
NGINX 1.18 or later

Database:

MySQL 8.0 or later
MariaDB 10.4 or later

PHP version:

PHP 8.1 or later
Required PHP extensions:

ext-bcmath
ext-ctype
ext-curl
ext-dom
ext-gd
ext-hash
ext-iconv
ext-intl
ext-mbstring
ext-openssl
ext-pdo_mysql
ext-simplexml
ext-soap
ext-xsl
ext-zip
ext-sockets
ext-xml
ext-xmlreader
ext-xmlwriter
lib-libxml (DOMDocument)

In Case XAMPP php.ini – below extensions need to be enabled.

extension=intl
extension=curl
extension=soap
extension=sockets
extension=sodium
extension=xsl
extension=zip
extension=gd


Composer / Elasticsearch

Composer 2.2 or later
Elasticsearch 7.9 or later

Step [2] – Run below script to downland Magento 2.x or Adobe Commerce Repository

composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition 2.4.x

Step [3] – Run below CLI Script

php bin/magento setup:install –base-url=”http://dev.adobeb2b246.com” –db-host=”localhost” –db-name=”adobeb2b246p1″ –db-user=”root” –admin-firstname=”admin” –admin-lastname=”admin” –admin-email=”admin@admin.com” –admin-user=”admin” –admin-password=”admin123″ –language=”en_US” –currency=”INR” –timezone=”America/Chicago” –use-rewrites=”1″ –backend-frontname=”admin” –search-engine=elasticsearch7 –opensearch-host=localhost –opensearch-port=9200 –opensearch-index-prefix=magento2 –opensearch-timeout=15

php bin/magento setup:install 
--base-url="http://dev.adobeb2b246.com" 
--db-host="localhost" 
--db-name="adobeb2b246p1" 
--db-user="root" 
--admin-firstname="admin" 
--admin-lastname="admin" 
--admin-email="admin@admin.com" 
--admin-user="admin" 
--admin-password="admin123" 
--language="en_US" 
--currency="INR" 
--timezone="America/Chicago" 
--use-rewrites="1" 
--backend-frontname="admin" 
--search-engine=elasticsearch7 
--opensearch-host=localhost 
--opensearch-port=9200 
--opensearch-index-prefix=magento2 
--opensearch-timeout=15































Rest of steps as per below link

Magento 2. x or Adobe Commerce Database Tables need to be truncated to increase high speed up Performance.

The following below set of Database tables need be truncated to increase high speed up Performance.

  • dataflow_batch_export,
  • dataflow_batch_import,
  • log_customer,
  • log_quote,
  • log_summary,
  • log_summary_type,
  • log_url,
  • log_url_info,
  • log_visitor,
  • log_visitor_info,
  • log_visitor_online,
  • report_viewed_product_index,
  • report_compared_product_index,
  • report_event,
  • index_event,
  • Catalog_compare_item.

How to Protect template files against XSS attack in Adobe Commerce / Magento 2.x

Cross-site scripting, or XSS, is a security vulnerability that can be found in web applications. This vulnerability allows attackers to inject malicious code/styles into a web page viewed by users. Hackers trying to attack in HTML code to attack / harm files

PHTML templates
An ‘Escaper’ class is provided for .phtml templates and PHP classes responsible for generating HTML. It contains HTML sanitization methods for a variety of contexts.

The following code sample illustrates XSS-safe output in templates:

<?php echo $block->getTitleHtml() ?>
<?php echo $block->getHtmlTitle() ?>
<?php echo $block->escapeHtml($block->getTitle()) ?>
<?php echo (int)$block->getId() ?>
<?php echo count($var); ?>
<?php echo 'some text' ?>
<?php echo "some text" ?>
<a href="<?php echo $block->escapeUrl($block->getUrl()) ?>"><?php echo $block->getAnchorTextHtml() ?></a>

The $block local variable available inside .phtml templates duplicates these methods.

Follow below adobe commerce link to know more details

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/xss-protection.html

How To Get Store Email addresses in Magento 2.x / Adobe Commerce by Programmatically

The following below code to get store Email Address

<?php
namespace John\Mage2db\Controller\Index;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $request;
    protected $scopeConfig;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\App\Request\Http $request,
    ScopeConfigInterface $scopeConfig
){
    parent::__construct($context);
    $this->scopeConfig = $scopeConfig;
    $this->request = $request;
}

public function execute()
{
    $email = $this->scopeConfig->getValue('trans_email/ident_support/email',ScopeInterface::SCOPE_STORE);
    $name  = $this->scopeConfig->getValue('trans_email/ident_support/name',ScopeInterface::SCOPE_STORE);

    echo $email;echo "<br/>";
    echo $name;echo "<br/>";

}

The abovecode provide Store Support Email ID & Name

If you want to do General Email, Sales Email, Customer Support Email, Customer Support Email1 and Customer Support Email2

General :– ident_general

Sales:- ident_sales

Customer Support:- ident_support

Custom Email1:- ident_custom1

Custom Email2:- ident_custom2

Change below line code as per your business need ident_support to ident_general or ident_sales or ident_custom1 or ident_custom2
$email = $this->scopeConfig->getValue('trans_email/ident_support/email',ScopeInterface::SCOPE_STORE);
    $name  = $this->scopeConfig->getValue('trans_email/ident_support/name',ScopeInterface::SCOPE_STORE);

How To Get Region or State List by Country id in Magento 2 / Adobe Commerce

The following below code in your Block of your custom module

Step [1] – Code inside your block / controller / helper file

<?php
/*
 * John_Country

 * @category   Adobe Commerce Region / State List By Country ID
 * @package    Country Form
 * @copyright  Copyright (c) 2023 - Mage2DB.com
 * @Email      johndusa1021@gmail.com
 * @version    1.0.0
 */
namespace John\Country\Model;

use Magento\Directory\Model\Country;
use Magento\Directory\Model\CountryFactory;

class Country
{
/**
* @var Country
*/
public $countryFactory;

public function __construct(
    CountryFactory $countryFactory
) {
    $this->countryFactory = $countryFactory;
}

/**
 * Region / State List By Country ID
 *
 * @return string
 */
Public function getregionsOfCountry($countryCode) {
 $regionCollection = $this->countryFactory->create()->loadByCode($countryCode)->getRegions();
        $regions = $regionCollection->loadData()->toOptionArray(false);
        return $regions;
    }

}

Step [2] – if you have written above code in your Custom Block, call this Block in your custom template.

<?php
/*
 * John_Customercompanycreation

 * @category   Adobe Commerce Region / State List By Country ID
 * @package    Customerregister Form
 * @copyright  Copyright (c) 2023 - Mage2DB.com
 * @Email      johndusa1021@gmail.com
 * @version    1.0.0
 */
?>
<?php
 $countryCode="US";

 echo"<BR><B>Country=</b>".$block->getCountryName($countryCode);

foreach($block->getregionsOfCountry($countryCode) as $key=>$regionlist):

  if($key>0): 
  echo"<BR><b>Region / State ID==".$regionlist['value']."&nbsp;&nbsp;&nbsp;&nbsp;"."Region / State ID==</b>".$regionlist['title'];
  endif;
endforeach;

?>

How To Get Country name by Country id in Magento 2 / Adobe Commerce

The following below code in your Block of your custom module

Step [1] – Code inside your block / controller / helper file

<?php
/*
 * John_Country

 * @category   Adobe Commerce Region / State List By Country ID
 * @package    Country Name
 * @copyright  Copyright (c) 2023 - Mage2DB.com
 * @Email      johndusa1021@gmail.com
 * @version    1.0.0
 */
namespace John\Country\Model;

use Magento\Directory\Model\Country;
use Magento\Directory\Model\CountryFactory;

class Country
{
/**
* @var Country
*/
public $countryFactory;

public function __construct(
    CountryFactory $countryFactory
) {
    $this->countryFactory = $countryFactory;
}

/**
 * country full name
 *
 * @return string
 */
public function getCountryName($countryId)
{
    $countryName = '';
    $country = $this->countryFactory->create()->loadByCode($countryId);
    if (!empty($country)) {
        $countryName = $country->getName();
    }
    return $countryName;
}

}

Step [2] – if you have written above code in your Custom Block, call this Block in your custom template.

<?php
/*
 * John_Country

 * @category   Adobe Commerce Region / State List By Country ID
 * @package    Country Name
 * @copyright  Copyright (c) 2023 - Mage2DB.com
 * @Email      johndusa1021@gmail.com
 * @version    1.0.0
 */
?>
<?php
 $countryCode="US";

 echo"<BR><B>Country=</b>".$block->getCountryName($countryCode);
?>

Output ::