How to Setup and Upgrade Database in Magento 2

How to Setup and Upgrade Database in Magento 2


Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /var/www/html/wp-content/plugins/urvanov-syntax-highlighter/class-urvanov-syntax-highlighter-langs.php on line 86

how to install and upgrade sql script for module in Magento 2. When you install or upgrade a module, you may need to change the database structure or add some new data for current table. To do this, Magento 2 provide you some classes which you can do all of them. Table of content Magento 2 provides some classes in the directory app/code/[Namespace]/[ModuleName]/Setup to create or upgrade database.

  • InstallSchema – setup database structure
  • InstallData – initial the data for database table.
  • UpgradeSchema – upgraded database structure
  • UpgradeData – upgraded (add/remove) data from table.

Functions of these classes will be run when we install or upgrade module by this command line:

Elaborating each step,

  1. Install Schema
    Create file: app/code/Cozmot/HelloWorld/Setup/InstallSchema.php

In this file, we created a table with name “data_example” with four columns: example_id, title, content, created_at with data types are integer, varchar, text, timestamp
You can review all data types in this file: MagentoFrameworkDbDdlTable.php

2. Install Data
File: app/code/Cozmot/HelloWorld/Setup/InstallData.php

Here,  we insert a row with value for “title” and “content” columns to data_example table.

3. Upgrade Schema
File: app/code/ Cozmot/HelloWorld/Setup/UpgradeSchema.php

Here, note that we have to check module version in upgrade function. In this example, we upgraded module from version 1.0.0 to 1.0.1. Drop created_at column from the data_example table.

4. Upgrade Data
File: app/code/ Cozmot/HelloWorld/Setup/UpgradeData.php

]]>

How to Setup and Upgrade Database in Magento 2

Add Custom Category Attribute Magento2 Extension Free

USER GUIDE

  1. How to Register Module in Magento 2
  2. Tell Magento Which Extesions to Be Included
  3. Register Attribute in our Core
  4. Add Code for showing Attribute to set value from Admin Dashboard  

After Registering Tell Magento to Load Our Extension

Not it’s time to Implement Logic, Here are we Registering our Attribute for Category which will be Boolean Formed.

Now we have to add Admin side option in Category options to set value of our Attribute.

Hurrayyyy… That’s all needed Now run Following commands according to your Installation.

]]>

How to Setup and Upgrade Database in Magento 2

How to Create Barcode in Magento 2 Invoice PDF

Magento 2 facilitates the merchants to provide multiple things in invoice PDFs like order id, customer name, shipping address, product name, product quantity, product price, total amount, and so on.

However, depending on the business requirements, customization in invoice PDF can be done.

One such customization solution is offered in this post to create barcode and add it in Magento 2 invoice PDF.

Barcode in invoice PDF helps the customer to scan and get the order id using which it is easy to get order details.

Steps to Create Barcode and Add it in Magento 2 PDF Invoice

1. Create di.xml file at Vendor\Extension\etc

 

2. Create Invoice.php file in Vendor\Extension\Plugin\Invoice.php

Done! That’s what you need to do.

 

For Details Visit Cozmot.com 

Follow us on Facebook and visit Our Blog]]>

How to get Product Grid by Category ID Magento2

How to get Product Grid by Category ID Magento2

Another solution if you only wanna fetch Products 

Object Manager Usage Good and Bad: ]]>

Category Products Widget Extension Free with Custom Filters Magento2

USER GUIDE

  1. How to Register Module in Magento 2
  2. Tell Magento Which Extesions to Be Included
  3. Create Over Meta Title Remove Class  

After Registering Tell Magento Which Extesions to Be Included

Now Module Registered so Try adding Widget XML Structure

Since we added all essential files so you better download and install Our Module to run featue out of Box Here is link to Widget Page [button link="https://cozmot.com/category-products-widget-with-custom-filters-magento-2/" type="big"] Link text[/button]  ]]>