How to disable products in Magento2 which dont have any gallery image?

Products without a picture show up on category pages and in search results with Magento’s grey placeholder image, which looks unfinished. After a big import there can be hundreds of them, and disabling them one by one in the admin isn’t practical. This query disables every product that has no image in its gallery, in one go. Before you run it Back up the database. The query changes the status of many products at once and there’s no undo. Check which products will be affected first. The part inside the brackets, from SELECT to IS NULL, is a complete query on its own. Run it by itself and you get the IDs of all products without a gallery image. Check the ID of the status attribute in your database (see below). UPDATE `catalog_product_entity_int` SET `value`=2 where `entity_id` in (SELECT a.`entity_id` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_media_gallery_value` AS b ON a.entity_id = b.entity_id LEFT JOIN `catalog_product_entity_media_gallery` AS c ON b.value_id = c.value_id WHERE c.value IS NULL) and `attribute_id` = 96 It is SQL query ...

August 22, 2019 · 3 min · Harshvardhan Malpani

How to batch edit multiple images to make square sized pictures with original image in center using php imagejpeg?

When a gallery, shop or listing needs every picture to be square, cropping can cut off part of the image and stretching distorts it. This script does neither. It takes every JPEG in a folder, places it in the middle of a white square canvas and saves the result in an out folder, so the original picture stays whole and only white space is added around it. It uses PHP’s GD functions (imagecreatefromjpeg(), imagejpeg() and friends), so the GD extension has to be enabled in your PHP installation. ...

August 18, 2019 · 4 min · Harshvardhan Malpani

How to wipe all the tables and data in MySQL? Clean whole database

Sometimes I need to empty a MySQL database completely while keeping the database itself. The usual case is re-importing a fresh dump of a Magento or WordPress site into a database that was created through cPanel or another hosting panel, where the database, its user and their permissions are set up there and I don’t want to drop and recreate the database. The script below drops every table in the database you’re connected to, whatever the tables are called and however many there are. ...

August 3, 2019 · 4 min · Harshvardhan Malpani

How to track qty changes in cart?

On many cart pages, changing a quantity does nothing until the shopper clicks Update cart. Until then the line totals and the subtotal still show the old numbers, and it’s easy to miss that the button needs pressing. This snippet watches the quantity fields and makes the update button stand out as soon as any quantity differs from what the page loaded with. This is not CMS or software specific. It can be used for Shopify, Magento, WordPress or any other cart page. ...

July 21, 2019 · 3 min · Harshvardhan Malpani

How to add qty plus minus buttons in shopify?

Many Shopify themes of 2019 had a plain box for the quantity on the product page. This adds a minus and a plus button on either side of it, and stops the plus button at the stock of the selected variant, so shoppers can’t choose more than you have. It builds on my earlier post on showing stock quantities for every variant, which prints each variant’s stock into the page as a JavaScript object called inv_qty. ...

July 21, 2019 · 7 min · Harshvardhan Malpani

Sort keys of an array based on order of values in another array – PHP

Sometimes you have a list of records and a separate list that says what order they should be in. For example, $b holds rows that each start with an ID, and $a holds the same IDs in the order you want to show them. PHP’s built-in sort functions order things by their own values, so an order defined by another array needs a little code of its own. This snippet rebuilds $b in the order given by $a. ...

July 17, 2019 · 2 min · Harshvardhan Malpani

How to filter and validate pincode in Indian woocommerce?

By default, WooCommerce only validates the ZIP code of a few countries. WooCommerce stores in India therefore accept any PIN code a customer types in, including ones with the wrong number of digits. Here is how you can enable checking of the PIN code for Indian WooCommerce stores. WooCommerce checks postcodes in WC_Validation::is_postcode(). In the version linked in the reference below, that function only has rules for Brazil, Switzerland, the UK, Portugal and the US, and returns true for every other country. Its result is passed through the woocommerce_validate_postcode filter before it’s used, so you can add your own rule for India there. ...

July 16, 2019 · 2 min · Harshvardhan Malpani

How to show stock quantity for all variants in shopify?

How to show “xxx left in stock” on shopify product page? Showing how many items are left, especially when stock is low, tells customers whether they need to hurry. Many themes don’t show this out of the box, and the tricky part is products with variants: the number has to change when the customer picks a different size or colour, without reloading the page. This needs three pieces: some Liquid in the product template for the first page load, a few lines of JavaScript for variant changes, and some CSS. ...

July 15, 2019 · 4 min · Harshvardhan Malpani

What is DMARC and How to set it up?

DMARC stands for Domain-based Message Authentication, Reporting, and Conformance It can be used as a way to prevent specific type of SPAM. Hence it should be added as TXT record in your DNS zone, just like SPF and DKIM signatures. Example DMARC policies These are some example policies and how they appear in the DNS TXT record. TXT record hostname must be “_dmarc“ The values in these examples are defined in DMARC TXT record values, below. ...

July 3, 2019 · 1 min · Harshvardhan Malpani

Funny php bug due to hashing and is_numeric

So I was working on an automation project and was testing the api to upload entitites. I used get parameters to send data and wrote a wrapper on server to process that. I used hashes (part of hashes to be precise) to identify the requester instead of using real names. some name came up with hash 12200e7973d0eecd8d75da83e816783496e440e22210ee72cb5cf37f7989a8ff I was using first 10 characters of this has which happen to be ...

June 9, 2019 · 2 min · Harshvardhan Malpani