Declarative Schema is a feature introduced in Magento 2.3 that provides a new way to define database schema changes using XML files. Traditionally, database schema changes in Magento were defined using InstallSchema and UpgradeSchema PHP scripts. However, with Declarative Schema, you can define the database schema changes in XML format, making it more readable and easier to manage.
In Declarative Schema, you describe the structure of your database tables, columns, indexes, and foreign keys in XML files located in the module's etc/db_schema.xml directory. These XML files provide a clear and concise representation of the database schema changes, making it easier to understand and maintain.
Declarative Schema also provides benefits such as improved performance during setup and upgrades, better compatibility with version control systems, and easier collaboration among developers working on database-related tasks.
Overall, Declarative Schema simplifies the process of managing database schema
The model is like a way of communcation for a single row in a table. It hides the complexity of how it interacts with the database, making it easier to work with the data.
The model class will extend \Magento\Framework\Model\AbstractModel and implements \Magento\Framework\DataObject\IdentityInterface. The IdentityInterface will force the Model class to define the getIdentities() method which will return a unique id for each model.
Resource Model
So we can create Resource model folder and Blog.php under it.
Collection
We understand that in the context of database tables, a model represents an individual row, while a collection encompasses all the rows within that table. You can envision the collection as a group of models or equivalently, as executing a "Select * From Table table_name" query.
When we need to work with multiple rows, such as retrieving all records, applying filters using "where" or "like" clauses,
I will make it very simple sweet and short. No long boring text. Just to the point.
Lets start!
Magento 2 only need two files to register and initialize a module.
registration.php: This file is located in the root directory of your module (app/code/Anees/Training/registration.php). It uses a Magento function to register the module with the framework.
etc/module.xml: This file is located within the etc folder of your module (app/code/Anees/Training/etc/module.xml). It defines the module's name, setup version, and any dependencies it might have.
After adding above two files run command bin/magento module:enable Anees_Training
Remember this is just a start. Magic will happen later when you go to advance level.
So first you have to check where you are getting collection. Most of time its coming from block and this blog also share how to do it when collection is coming from block.
Now go to your block file and add a _prepareLayout() function. This function render the layout of page as its visible from its name like we can set page title and other things also this function runs automatically.
See below function.
protected function _prepareLayout() { parent::_prepareLayout(); $this->pageConfig->getTitle()->set(__('My Reward History'));
// Assuming $macAddress is available, get records for the given MAC address $blockss_c = $this->getLayout()->createBlock('\Motoris\Vehiclelookup\Block\Cookie'); $macAddress = $blockss_c->get('customer_veh');
Increase or set Memory for Elastic search in Magento 2
Open the jvm.options file for editing:
sudo nano /etc/elasticsearch/jvm.options
Replace nano with your preferred text editor if you're using something else.
Locate line 31, which contains the -Xms2g option.
Remove any leading spaces before the -Xms2g option. The line should look like this:
text
-Xms2g
Save the file and exit the text editor (usually by pressing Ctrl + O to save and Ctrl + X to exit in the nano editor).
journalctl -u elasticsearch.service
To set the heap size for Elasticsearch, you can create a custom JVM options file with the .options extension and store it in the jvm.options.d/ directory. Here's how you can do it:
Navigate to the JVM Options Directory:
cd /etc/elasticsearch/jvm.options.d/
Create a Custom JVM Options File:
sudo nano heap_size.options
Set Heap Size: In the heap_size.options file, add the following lines to set both the initial and maximum heap size to 2GB: