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

Commit

Permalink
magento/devdocs#: Update "Copying fieldsets" documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Taranovskyi committed Oct 24, 2020
1 parent 1ac4468 commit 42e39ae
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 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,41 @@ 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 couple fields of 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 +145,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

0 comments on commit 42e39ae

Please sign in to comment.