Monthly Archives: February 2018
- 3 min read
Imagine you are cooking pasta and sit down to play some game. You listen with one ear to see if the "dish" does not boil away. In this case, you are an observer. When the pasta starts to boil away — the event "pasta_began_to_boil_away" is triggered, which causes you (the observer) to rush to the kitchen (perform an action, an algorithm).
In Magento 2, as in real life, there are observers and events that are implemented on the basis of the "Publish-subscribe pattern". We have already described , which allows you to extend and change the functionality of the store. Let's see how you can do this with the help of events and observers in Magento 2.
Events
Events are triggered by Magento 2 modules when an action has occurred or has to occur. Magento has many native events and also allows you to call your own event.
Use the dispatch method of the \Magento\Framework\Event\ Manager class to call an event.
For example:
namespace MyCompany\MyModule;class MyClass{
/** *ihor
- 2 min read
You often need to change the JavaScript code logic located in the .js file. The easiest way is to override the js file is by using a theme. You can learn how to override view files in the article about . This is a quick but not an elegant way.
To change one or more js-file methods, use the mixins available in RequireJS.
To extend this file:
app/code/VendorName/ModuleName/view/%area%/web/js/folder1/folder2/somefile.js
with the following code:
define( [ 'jquery', 'underscore', 'ko', 'uiComponent', 'uiRegistry', ], function ( $, _, ko, Component, registry, ) { 'use strict';
return Component.extend({ // ... method1: function() { /* some code */ }, method2: function() { /* some code */ } // ... });
});
%area% - the area where the file is extended, for example: frontend, adminhtml, base.
To override theihor
- 1 min read
Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. It is one of the . All you need to do to fix it is to change file permissions and add executive one.
To fix the bash permission denied error follow these steps:
1. Open terminal (shell)
2. Navigate to the folder with the script
3. Run the CLI command to change file permission settings:
chmod +x path_to_file/file_name
For example, if you run a :
bin/magento ...
and get the error:
bash: bin/magento: Permission denied
You need to add an execute (x) permission to the bin/magento file.
For this, please run the CLI command:
chmod +x bin/magento
In case of Magento 2 you can also use the next command to avoid the issue (php before bin/magento):
php bin/magento ...
Another issue you might face when running bin/magento commands, like the following ones, is the website breakdown during deployment:
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magentoihor
