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?”

Create a Custom REST API for Bulk product update in Magento 2.

Native Magento comes with a lot of REST APIs for different Entities like Product, Order, Customer, and other APIs.

I want to give a demo for updating bulk products using rest API in Magento 2.

By Default Native Magento doesn’t provide Bulk Product Update API. You need to call REST API to iterate over a loop. At a time you can update only a single product. Continue reading “Create a Custom REST API for Bulk product update in Magento 2.”