-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05answer_question.doc
More file actions
83 lines (75 loc) · 3.64 KB
/
05answer_question.doc
File metadata and controls
83 lines (75 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
0. Share github
1. How to join tables in Magento 2?
- Step 1: Set a Collection class that extends
- Step 2: Set your own function to get data
- Step 3: Get the collection and call to filterOrder function above
- Step 4: Save.
2. How to filter by an attribute? Filter by a normal field ? Sort order ? Add more attribute / fields to collection ?
- Filter by an attribute use: addAttributeToFilter()
- Filter by a normal field use: addFieldToFilter()
- Sort order
3. How to get data from request (get/post) in correct way in magento 2 ?
- with a class extends from Magento\Framework\App\Action\Action class, we can use method getPost.
Ex:
class ClassName
{
protected $request;
public function __construct
(
\Magento\Framework\App\Request\Http $request
)
{
$this->request = $request;
}
public function getDataPostRequest()
{
$post = $this->request->getPost();
// can do something...
}
}
4. How to validate form data with JS (client side) and PHP (server side) in Magento 2?
- step1: create a test form, the form is created as the attribute for validation.
- step2: accept javascript validation, please run the below script:
<script type="text/x-magento-init">
{
"#custom-form": {
"validation": {}
}
}
</script>
or you can make that operation directly in .html like this:
<form data-mage-init='{"validation": {}}' class="form" id="custom-form" method="post" autocomplete="off">
or
<script type="text/javascript">
require([
'jquery',
'mage/mage'
], function($){
var dataForm = $('#custom-form');
dataForm.mage('validation', {});
});
</script>
5. How to initiate configuration for a component ?
Following step:
- Create the module directory.
- Create the required registration.php file
- Create the module.xml configuration file
- Create the default.xml layout configuration file
- Add new block declaration under the “content” container in the default.xml file
- Create new script.phtml file
- Add HTML markup with the data-bind attribute and scope name for the UI Component
- Add UI component configuration via text/x-magento-init script
- Create new JavaScript part of the UI Component in the component.js file
- Enable module by running bin/magento module:enable command
- Install module by running bin/magento setup:upgrade command
6. What is VirtualType in di.xml? Can we use a data provider class implementation instead of VirtualType ?
- The virtualYype allows inserting different dependencies into the existing classes but not making any change to other classes.
- - Yes, we can use a data provider class implementation instead of VirtualType.
7. What is the difference between custom EAV attributes and extension attributes ?
Custom attribute là các thuộc tính tùy chọn của sản phẩm mà người quản trị có thể tự định nghĩa và tạo mới thông qua giao diện quản trị. Custom Attribute chỉ có tác dụng phân loại sản phẩm theo các thuộc tính thực của chúng.
Extension Attribute là các thuộc tính được khởi tạo thông qua code, chúng có rất nhiều tính năng và không xuất hiện trong giao diện quản trị hệ thống.
Extension Attribute có thể sử dụng trong tìm kiếm, filter collection, authentication user...
8. How to customize UI component template?
Để customize UI component templates ta có thể thực hiện thông qua extend file xml của template tương ứng hoặc thông qua modifer class
9. How to customize a JS component (any JS module or component UI JS) ?
Để customize JS Component ta thực hiện thông qua extends module bằng hàm extend.()