Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 6a60737

Browse files
author
Alex Taranovskyi
committed
1 parent 1ac4468 commit 6a60737

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/guides/v2.3/ext-best-practices/tutorials/copy-fieldsets.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The code snippet in the next step uses the name of the fieldset and aspect to sp
3636

3737
**etc/fieldset.xml:**
3838

39+
The following example shows how to copy `sales_convert_quote`.`demo` to `sales_order`.`demo`.
40+
3941
```xml
4042
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4143
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
@@ -49,6 +51,41 @@ The code snippet in the next step uses the name of the fieldset and aspect to sp
4951
</config>
5052
```
5153

54+
Use the `targetField` attribute to specify the destination field. The following example, shows how to copy `sales_convert_quote`.`demo` to `sales_order`.`order_demo`.
55+
56+
```xml
57+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58+
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
59+
<scope id="global">
60+
<fieldset id="sales_convert_quote">
61+
<field name="demo">
62+
<aspect name="to_order" targetField="order_demo"/>
63+
</field>
64+
</fieldset>
65+
</scope>
66+
</config>
67+
```
68+
69+
Define a new `aspect` if you need to copy a field of a source table into couple fields of a destination table.
70+
71+
The following example shows how to copy `sales_convert_quote`.`demo` into
72+
- `sales_order`.`demo`
73+
- `sales_order`.`order_demo`
74+
75+
```xml
76+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
77+
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
78+
<scope id="global">
79+
<fieldset id="sales_convert_quote">
80+
<field name="demo">
81+
<aspect name="to_order"/>
82+
<aspect name="to_demo_order" targetField="order_demo"/>
83+
</field>
84+
</fieldset>
85+
</scope>
86+
</config>
87+
```
88+
5289
## Step 3: Copy the fieldset {#step-3}
5390

5491
For copying the fieldset, we'll observe the `sales_model_service_quote_submit_before` event by using the following code in our `etc/events.xml`:
@@ -108,7 +145,6 @@ class SaveOrderBeforeSalesModelQuoteObserver implements ObserverInterface
108145
return $this;
109146
}
110147
}
111-
112148
```
113149

114150
In the code, an instance of the `Copy` class is obtained from the constructor using [dependency injection][2].

0 commit comments

Comments
 (0)