Advanced Development with RequireJS (+ Magento 2 Tutorial)
Below, I shed light on such useful technology as
Below, I shed light on such useful technology as
Being in business since 2006,
On Firebear, I’ve already compared Magento and Shopify. You can find that blog post here: Magento vs Shopify. Now, it is time to pay attention to differences between Magento 2 and Sopify. The following blog post discusses pros and cons related to both platforms. Let’s start with Shopify.
Since Magento 2 provides a very useful implementation of Symfony’s Console component, you can easily perform tons of important actions from a command line interface. It is possible to reindex, clean cache, generate code, create database backups, and run other commands with the help of this instrument. Moreover, you can easily enhance the existing solution with your own commands aimed at your Magento 2 extensions. Below, I explain how to use Magento 2 CLI tool and what commands to run. Continue Reading
This post describes how to update Magento 2 to the latest available version. Below, you will find all the necessary information related to the procedure, including some vital prerequisites. So, the version of your platform is a little bit outdated? Find out how to update it with the following Magento 2 tutorial.
Everything about Magento 2 on Firebear
UPD (07.04.16): Command Line Update
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.
Maintenance mode is a crucial part of every site launch; besides, there are tons of other situations when you can use it. Being an essential part of Magento 1.x development, maintenance mode is also available in Magento 2. Below, I will tell you how to enable it in a case of new platform.
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:
1 |
$this->getLayout()->createBlock('Full\Block\Class\Name\Here'); |
from a controller:
1 |
$this->_view->getLayout()->createBlock('Full\Block\Class\Name\Here'); |
from a model and a helper:
1 |
$this->_blockFactory->createBlock('Full\Block\Class\Name\Here'); |
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:
1 |
protected $_blockFactory; public function __construct( ..., \Magento\Framework\View\Element\BlockFactory $blockFactory, .... ){ .... $this->_blockFactory = $blockFactory; .... } |
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):
1 2 3 4 5 6 7 8 9 10 11 12 13 |
protected $pageFactory; public function __construct(\Magento\Cms\Model\PageFactory $pageFactory) { $this->pageFactory = $pageFactory; } public function someFunc() { ... $page = $this->pageFactory->create(); ... } |
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
Take your constructor and inject the model collection factory into it:
1 |
protected $mymodulemodelFactory; public function __construct( .... \[Namespace]\[Module]\Model\Resource\[Entity]\CollectionFactory $mymodulemodelFactory, ... ) { ... $this->mymodulemodelFactory = $mymodulemodelFactory; ... } |
It is possible to use it in any class method:
$collection = $this->mymodulemodelFactory->create(); Continue Reading