In the recipe Creating an install and upgrade script, we learned how we can automate the execution of database changes.
In these install scripts, we can also add attributes to products, as we will learn in this recipe.
We will work further on the Packt_HelloWorld
module that we have created in the previous recipes. Make sure you have the module installed.
The following steps describe the procedure to create an upgrade script that adds a product attribute to all products:
The module
Packt_HelloWorld
is already installed in our system so we have to create an upgrade script. Create the fileUpgradeData.php
in the folderapp/code/Packt/HelloWorld/Setup
. Add the following content in that file:<?php namespace Packt\HelloWorld\Setup; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class UpgradeData implements UpgradeDataInterface...