Get Product collection Using GraphQL Magento 2.

From Magento version 2.3, one of the latest features for the storefront API called GraphQL is introduced.

Out of the Box Magento Products Query with all the possible fields by clicking on the link, Use Product Query GraphQl in Magento to display all the products-related fields.

This example is just for learning purposes. Getting all the product collections using GraphQL in Magento 2 You need to create a simple module for achieving it.

We need to create a Resolver model and add our custom logic for getting all the Product collection.

You can add a custom condition for getting specific Products in the Resolver PHP file based on your requirements. We will display all the products in the response.

Continue reading “Get Product collection Using GraphQL Magento 2.”

How to create Product attribute programmatically in Magento 2?

Up to Magento 2.2 Version, We can create product attributes programmatically using the InstallData.php file.

Using dynamically create product attribute save the time for creating attribute manually using the admin panel.

If you are creating an extension package and you need product attribute at that time below code snippet will be helpful for creating Product attribute.

Continue reading “How to create Product attribute programmatically in Magento 2?”

How to resize product image in magento 2?

To resize product images in Magento 2, You need to refer to the code snippet for resizing product images at any place in the file.

Magento Class file Magento\Catalog\Helper\Image is used to resize the product image.

Call Init() function and pass parameters,

The first parameter is the $product Object,
The second parameter is the product id, You can be called any product id like thumbnail, or small_image (Check the list of image id under the theme etc/view.xml file)
The third parameter as array is optional,

For Custom Image resizing refer to the blog, Resize the custom image in Magento 2

Continue reading “How to resize product image in magento 2?”