Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 667192d

Browse files
authored
Merge pull request magento#7918 from BarnyShergold/technical/dynamic_row_defaults
Added Dynamic Row Default Example
2 parents c2c9e0c + 8e77152 commit 667192d

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

src/guides/v2.3/ext-best-practices/tutorials/dynamic-row-system-config.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,71 @@ class TaxColumn extends Select
171171

172172
This block sets values for the drop-down option.
173173

174-
## Step 4: Clean cache
174+
## Step 4: Set default values - OPTIONAL
175+
176+
It is possible to set defaults for a dynamic row configuration, this is done by adding additional XML to the defaults block in the `config.xml` file for the module.
177+
178+
Add a block to the `<default>` section of the `config.xml` file and do not include any values:
179+
180+
```xml
181+
<system>
182+
<general>
183+
<ranges></ranges>
184+
</general>
185+
</system>
186+
```
187+
188+
For each complete line of configuration, create an XML block with a repeating node that has a different value to all the others and contains XML tags for each sub-option and value.
189+
For example, you can use `<item1>, <item2>`.
190+
191+
The sub-options are the columns defined in the `_prepareToRender()` method as described in [Step 2](#step-2-create-the-block-class-to-describe-custom-field-columns).
192+
193+
In the following excerpt, a single row for `item1` contains 4 sub-options:
194+
195+
```xml
196+
<item1>
197+
<from_qty>5</from_qty>
198+
<to_qty>6</to_qty>
199+
<price>10.00</price>
200+
<tax>1</tax>
201+
</item1>
202+
```
203+
204+
Continue building the default block by adding 3 items to the `ranges` configuration option in the `config.xml` file:
205+
206+
```xml
207+
<system>
208+
<general>
209+
<ranges>
210+
<item1>
211+
<from_qty>1</from_qty>
212+
<to_qty>5</to_qty>
213+
<price>10.00</price>
214+
<tax>1</tax>
215+
</item1>
216+
<item2>
217+
<from_qty>6</from_qty>
218+
<to_qty>10</to_qty>
219+
<price>20.00</price>
220+
<tax>1</tax>
221+
</item2>
222+
<item3>
223+
<from_qty>11</from_qty>
224+
<to_qty>15</to_qty>
225+
<price>30.00</price>
226+
<tax>0</tax>
227+
</item3>
228+
</ranges>
229+
</general>
230+
</system>
231+
```
232+
233+
To verify the default values for the configuration are correct, do the following :
234+
235+
- Ensure that this configuration option has no entry in the database.
236+
- Continue with Step 5
237+
238+
## Step 5: Clean cache
175239

176240
Clean the Magento cache with the following command:
177241

@@ -186,7 +250,7 @@ bin/magento cache:clean config
186250

187251
## Result
188252

189-
The result is a new dynamic system row field in the Admin panel.
253+
The result is a new dynamic system row field in the Admin panel. If you have set optional default values, these should also appear.
190254

191255
![Dynamic Rows System Config]({{ site.baseurl }}/common/images/ext-best-practices/dynamic-rows-config-result.png)
192256

0 commit comments

Comments
 (0)