Remove Compare feature from Magento 2

How to remove “Add to Compare” links in sidebar and product page in Magento 2 product pages Magento 2 Community has a default feature of comparison lists for multiple products. Learn how you can disable the “Add to Compare” feature in magento2 community edition. Many stores don’t need it, and the links just add clutter to product pages and listings. There’s no admin setting to switch it off, so the way to hide it is to remove its blocks in your theme’s layout. ...

December 20, 2017 · 2 min · Harshvardhan Malpani

CORS policy for subdomains – htaccess – apache server

Browsers won’t let a page on one origin read a response from another origin (load a web font, or read the result of an AJAX call) unless the other server says it’s allowed, with an Access-Control-Allow-Origin header. On a Magento store this shows up as CORS errors in the browser console when the shop, its static files and other parts of the site live on different subdomains. The catch is that Access-Control-Allow-Origin takes exactly one origin or *. You can’t list several subdomains in it. The rules below get around that: Apache checks the Origin header of each request against a pattern and, if it matches, sends that same origin back as the allowed one. ...

December 20, 2017 · 3 min · Harshvardhan Malpani

How to manage Magento 2 product attribute values options using console

Keeping a dropdown attribute’s options up to date in the Magento 2 admin means a lot of clicking: deleting the values you no longer sell and adding new ones, one row at a time. This script does both in one go. You give it the list of values the attribute should end up with, and it makes the Manage Options table match that list. This is an update to my previous script which was used to add custom product attribute values using the backend – Add values to product attribute ...

November 22, 2017 · 4 min · Harshvardhan Malpani

How to find rows which exist in new table but not in old table – MySQL

When I get an updated copy of a table, I sometimes need to know which rows are new: the ones that are in the new table but weren’t in the old one. MySQL only added an EXCEPT operator in version 8.0.31, so the usual way to do this is a LEFT JOIN that looks for rows with no match. SQL Query: SELECT t1.stone FROM newatt t1 LEFT JOIN att t2 ON t2.stone = t1.stone WHERE t2.stone IS NULL ...

November 18, 2017 · 2 min · Harshvardhan Malpani

Insert Indian States in Magento Database

Magento ships with lists of states or regions for some countries, but when I wrote this India wasn’t one of them. For a country without a region list, customers get a free-text “State/Province” box instead of a dropdown, so the same state ends up spelled several different ways across orders, and anything that depends on the state, such as tax rates per state, is harder to set up. The query below adds the Indian states and union territories so they show up as a dropdown at checkout, in customer addresses and in the admin. ...

November 1, 2017 · 3 min · Harshvardhan Malpani

How to create Magento 2 category programmatically?

Creating a handful of categories in the admin is fine, but when you’re setting up a new store or migrating a category tree from another system, clicking through the form for each one gets old quickly. This standalone PHP script boots Magento 2 and creates categories with a single function call each. Before you start Save the script as a PHP file (for example create-category.php) in the Magento root folder, the one that contains app/ and bin/. It includes ./app/bootstrap.php, and that path is resolved from the folder you run it in. Run it from the command line with php create-category.php, as the user that owns the Magento files. Find the ID of the parent category you want to use. Go to Catalog > Categories in the admin and select the category; its ID is shown next to its name at the top of the form. Use this code: ...

October 27, 2017 · 3 min · Harshvardhan Malpani

How to secure a folder by whitelisting one IP using HTACCESS and denying all others

If a folder such as /admin should only ever be used from one place, say your office, you can lock it to that IP address in .htaccess, so everyone else gets 403 Forbidden before the admin login page even loads. This post does it with mod_rewrite, and then adds a small PHP script that updates the allowed IP for you, which helps when your connection’s IP changes from time to time. ...

October 26, 2017 · 4 min · Harshvardhan Malpani

Compare two columns in Excel and check the missing values

Say column A holds a full list, for example all your product SKUs, and column B a shorter list that should contain the same values. This formula shows which values from column A are missing from column B. =IF(COUNTIF($B:$B, $A1)=0, $A1, “”) How to use it. Put the formula in the first row of an empty column, for example C1, and fill it down to the last row of column A. Each row shows the value from column A if it doesn’t appear anywhere in column B, and stays empty if it does. Filter that column to hide the blanks and you have the list of missing values. ...

October 26, 2017 · 2 min · Harshvardhan Malpani

Magento 2.1x – Add options in custom product attribute using backend

Adding values to a dropdown attribute in the Magento 2 admin means clicking Add Option and typing a value, once for every value. That’s fine for five colours, but not for fifty. Instead, I let the browser console do the clicking and typing. I wrote this for Magento 2.1 in 2017. Go to the attribute edit page using the Magento 2 admin panel (Stores > Attributes > Product > Edit attribute) Use the console – ctrl + shift + J (Cmd + Option + J on a Mac) Edit the JS array mimim and then paste the following code in the console. ...

October 14, 2017 · 2 min · Harshvardhan Malpani

CVE-2017-1000253: the old Linux PIE bug that still turns a foothold into root

If you still look after an old CentOS or RHEL 6/7 box, this one’s for you. At a glance CVE: CVE-2017-1000253. Qualys, who found it, called it “Linux PIE/stack corruption”. Severity: 7.8 (High) on NVD, and Red Hat rates it Important. That score assumes the attacker already has a local account, though. Nobody can fire this at your server over the internet. Affected: any kernel that never picked up a fix from April 2015. Upstream, that’s 2.6.25 up to (but not including) 3.10.77, 3.12.43, 3.14.41, 3.16.35, 3.18.14, 3.19.7 and 4.0.2, plus the old 3.2 and 3.4 branches. In practice, Qualys says the big ones were every version of CentOS 6 and RHEL 6, CentOS 7 before 1708, and RHEL 7 before 7.4. Ubuntu 16.04 and newer were never affected. Known exploited: Yes. CISA added it to its Known Exploited Vulnerabilities (KEV) catalog on 2024-09-09, and says it’s known to be used in ransomware campaigns. What’s going on When Linux starts a program, the kernel lays its pieces out in memory and leaves a gap between the program and its stack. For position-independent executables (PIEs), it didn’t reserve enough room for the whole binary. A program with a big enough data segment could end up partly mapped on top of its own stack, so the two would overwrite each other. ...

October 3, 2017 · 4 min · Harshvardhan Malpani