CORS policy: No ‘Access-Control-Allow-Origin’

CORS policy No ‘Access-Control-Allow-Origin’ error

Font from origin domain.dev has been blocked… (CORS and browsersync)

If you are getting issue fonts are blocked in web client CORS then below code will help you. Use the code in .htaccess file and problem will be resolved 🙂
# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
<FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$”>
Header set Access-Control-Allow-Origin “*”
</FilesMatch>
</IfModule>

How to enable maintenance mode in Magento

This article describes how to enable maintenance mode in Magento. When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.

This feature allows you to develop and test your store before it goes “live,” or do other maintenance tasks, such as installing updates.

To set Magento in maintenance mode you need to create a file with name “maintenance.flag” and drop it to Magento home directory. While this file exists your website visitors will see a temporary page (/errors/503.php). If you want to edit this page content you can find it in Magento admin – CMS/Pages, it is called “503 Service Unavailable”.

Once you finished with changes and your website is ready to work just delete maintenance.flag file and maintenance mode will be off, so your Magento website will work as usual.

All we need to do it edit 3 lines.

Open: index.php in root and above line 57 add (remembering to edit the ‘allowed’ array to contain the IP’s you want to be able to access the site);

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.

then change the line
if (file_exists($maintenanceFile)) {
to
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Simple. Now you can access the site, while others see its maintenance mode.

Redirect all url to https

Redirect all url to https

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

Magento 500 internal server error

Magento 500 internal server error

A 500 Internal Server Error in Magento can be frustrating, as it disrupts your store’s functionality and can impact sales.

This error often stems from incorrect file permissions, memory limits, corrupted .htaccess files, or issues with third-party extensions. To resolve it, start by checking the error logs (var/log and var/report) for specific details.

Ensure that the correct file permissions are set (755 for directories and 644 for files), and try increasing the PHP memory limit in the php.ini file. Additionally, clearing the Magento cache (bin/magento cache:clean) and regenerating static files (bin/magento setup:static-content:deploy) can help. If the problem persists, disabling recently installed extensions and verifying server configurations, such as the .htaccess file, may pinpoint the issue.

A well-maintained Magento installation with up-to-date software and optimized server settings can prevent such errors from recurring.

Media query for large screen

Media query for large screen:

@media screen and (min-width: 1400px) {

}
@media screen and (min-width: 1600px) {

}
@media screen and (min-width: 1900px) {

}

How to reset admin password in Magento 2

This is easy and complicated too!! There are two different methods to restore your admin password. The first one is quite easy while the second is more complicated..

In the first solution there is you need to reset password your email address stored in magento site.For this you need to open the admin panel of your store and click on the «Forgot your password?» link. Then, fill in your email address associated with the admin account and hit the «Retrieve Password» button.

In a moment, you’ll receive receive an email with the link that allows you to reset your current password or set a new one. Click on that and add your new password.

The second method is little complicated using phpMyadmin. First, you need to login to cPanel if you have one installed. Then, in the «Databases» section of the cPanel, select the phpMyAdmin link and copy the following sql query:
UPDATE admin_user SET password = CONCAT(SHA2('xxxxxxxYourNewPassword', 256), ':xxxxxxx:1') WHERE username = 'admin';

The xxxxxxx character sequence is a cryptographic salt.
it is saved in app\etc\env.php file


array (
'key' => '763701df77e6cba98d5e9a1bb3d935cv', //cryptographic salt
),
...

Invalid credentials for ‘https://repo.magento.com/packages.json’, aborting

Invalid credentials for ‘https://repo.magento.com/packages.json’, aborting

The error message “Invalid credentials for ‘https://repo.magento.com/packages.json‘, aborting” typically occurs when trying to authenticate with Magento’s Composer repository using incorrect or missing credentials. This issue often arises due to an incorrect username or password in your auth.json file or when your Magento Marketplace API keys are not properly configured. To resolve this, ensure that your authentication details are correct by verifying your public key (as the username) and private key (as the password) from your Magento Marketplace account. Then, update your Composer authentication using the following command:

composer config --global --auth http-basic.repo.magento.com your-public-key your-private-key

After updating the credentials, try running the Composer command again. If the issue persists, consider clearing Composer’s cache using composer clear-cache and ensuring that your network connection is stable.

How to override .phtml files in Magento 2

Here is tips for how to override .phtml files in Magento 2. Please follow below steps

vendor/vendor/magento/module-checkout/view/frontend/templates/onepage.phtml

Follow this path

app/design/frontend/Vendor/theme/Magento_Checkout/templates/onepage.phtml

Get Magento catalog image

Today  I will show you how you can get the magento catalog image via code on any page. Please use below code and you will be done!!

 

Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);

Exclude a category id from category collection in Magento

Please use the below code for exclude a category id from category collection in Magento

<?php
      $allCategories = Mage::getModel('catalog/category')
                       ->getCollection()
                       ->addAttributeToSelect('*')
                       ->addAttributeToFilter('level',2)
                       ->addAttributeToFilter('entity_id', array('nin' => 69))
                       ->addIsActiveFilter(); 

?>