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

magento/devdocs#: Update "Copying fieldsets" documentation #8122

Merged
merged 3 commits into from
Oct 31, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/guides/v2.3/ext-best-practices/tutorials/copy-fieldsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The code snippet in the next step uses the name of the fieldset and aspect to sp

**etc/fieldset.xml:**

The following example shows how to copy `sales_convert_quote`.`demo` to `sales_order`.`demo`.

```xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
Expand All @@ -49,6 +51,42 @@ The code snippet in the next step uses the name of the fieldset and aspect to sp
</config>
```

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`.

```xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="demo">
<aspect name="to_order" targetField="order_demo"/>
</field>
</fieldset>
</scope>
</config>
```

Define a new `aspect` if you need to copy a field of a source table into multiple fields in a destination table.

The following example shows how to copy `sales_convert_quote`.`demo` into

- `sales_order`.`demo`
- `sales_order`.`order_demo`

```xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote">
<field name="demo">
<aspect name="to_order"/>
<aspect name="to_demo_order" targetField="order_demo"/>
</field>
</fieldset>
</scope>
</config>
```

## Step 3: Copy the fieldset {#step-3}

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`:
Expand Down Expand Up @@ -108,7 +146,6 @@ class SaveOrderBeforeSalesModelQuoteObserver implements ObserverInterface
return $this;
}
}

```

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