In Magento 2 there are several ways of showing and hiding blocks conditionally. If its visibility depends on a configuration settings value, use the expression in your layout file: Continue Reading
Since Magento 2 relies on the concept of resources to interact with database, you can easily get the global resource and use it for playing with SQL queries or execute directly. Continue Reading
Mage::Registry in Magento 2 is very similar to the registry of Magento 1. You can find it here: \Magento\Framework\Registry
Utilize dependency injection for adding it to the constructor. As a result, you will be able to use both $registry->register($key, $value) and $registry->registry($key) methods to store / access data.
The process is almost similar to Magento 1, but you only have to rename local.xml.sample to local.xml within your pub/errors directory. Continue Reading
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:
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:
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