How to Uninstall Magento 2 Modules and Restore Magento 2 Backups (Rollbacks)

- Magento 2

Uninstall Magento 2 Extensions; Restore Magento 2 Rollbacks

In this Magento 2 tutorial, I explain how to uninstall Magento 2 modules. You have several uninstallation options, such as removing the modules’ code, database data, and database schema. I highly recommend you to create backups before doing any changes, because you will leave a chance to recover the data if something goes wrong.

Magento 2 tutorials, features, and rumours on Firebear

Continue Reading

E-Commerce personalization

- E-Commerce

personalization in e-commerce: tips, tools, and services

Have you ever thought about why E-Commerce is more powerful than conventional retail? What makes it so powerful? Let’s recall the most evident reasons .

First, E-Commerce allows retailers to simultaneously reach millions of customers all over the world thanks to significant advances in the sphere of modern technologies. Second, E-Commerce provides the most convenient shopping experience allowing customers to purchase goods anywhere and anytime just in one click. However, there is even more potential here that yet needs to be revealed. And that is personalization. Continue Reading

How to instantiate a custom block in Magento 2

- Magento 2

Magento 2 Development

Unfortunately, the process is not as easy as in Magento 1 ($crumbs = Mage::app()->getLayout->getBlock(‘breadcrumbs’);). In Magento 2, it depends on where you are going to instantiate it from. To create an instance from another block, use the following code:

from a controller:

from a model and a helper:

Please note that in a case of the model you have to create _blockFactory (a protected member), and inject a \Magento\Framework\View\Element\BlockFactory instance in the constructor, assigning it to the member var. For instance:

Continue Reading

How to instantiate a model in Magento 2

- Magento 2

Magento 2 Development

Since Magento strictly discourages the use of ObjectManager, there are service classes for abstracting it for all scenarios. Thus, you should use factory for all models (non-injectables):

You only have to ask a desired model’s factory in a constructor. Hence, it will be automatically generated, while you run compiler or Magento. Continue Reading

How to get the сollection of custom Magento 2 modules

- Magento 2

Magento 2 Development

Take your constructor and inject the model collection factory into it:

It is possible to use it in any class method:

$collection = $this->mymodulemodelFactory->create(); Continue Reading

How to start Developer Mode in Magento 2

- Magento 2

Magento 2 Development

To enable Developer Mode in Magento 2, use SetEnv MAGE_MODE “developer” in your .htaccess file. Please note that this method works only in case when AllowOverride All is situated in a proper <Directory> directive. And don’t forget to check if the Apache process user has write permissions to all necessary directories. Continue Reading

How to create a Magento 2 playground test file with an initialised Magento 2 application

- Magento 2

Magento 2 Development

Create a test.php file in the root of your Magento 2 instance.

In the same place, create a TestApp.php file with the following content:

Call your test.php file in a browser to execute everything from TestApp::launch().

The createApplication method from the bootstrap class creates an application class instance and expects the implementation of \Magento\Framework\AppInterface that contains 2 methods.

You create your own class in TestApp to implement the interface. Since the catchException method always returns false, your app don’t handle exceptions. If something goes wrong, print it on a screen.

The implemented launch method is called by \Magento\Framework\App\Bootstrap::run. The run method behaves almost the same in spite of what the application passed as a parameter.

$response = $application->launch(); is the only thing that depends on the app. It means that calling \Magento\Framework\App\Bootstrap::run inits the Magento env and calls the launch method from your app. Therefore, put all the dirty code inside this method.

Then, \Magento\Framework\App\Bootstrap::run calls $response->sendResponse();, where under $response we mean everything what the launch method returns. Thus, return $this->_response; is required, as it returns an empty response.

The above app class extends \Magento\Framework\App\Http so you get request, response, and other parameters, but you can omit this by making your class extend nothing. Continue Reading