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

Commit 14aa316

Browse files
committed
Reverting the 2.0 changes
1 parent d309fc6 commit 14aa316

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed

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

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In this tutorial, you will learn to copy custom data from a {% glossarytooltip 7
1717

1818
The following code defines a simple [extension attribute][1] named `demo` for the Cart and Order objects.
1919

20-
**etc/extension_attributes.xml**
20+
**extension_attributes.xml**
2121

2222
{% highlight xml %}
2323
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Api/etc/extension_attributes.xsd">
@@ -36,9 +36,9 @@ The following code defines a simple [extension attribute][1] named `demo` for th
3636
The following code adds the `demo` field to the `sales_convert_quote` fieldset with the `to_order` aspect.
3737
The code snippet in the next step uses the name of the fieldset and aspect to specify which fields to copy.
3838

39-
**etc/fieldset.xml**
39+
**fieldset.xml**
4040

41-
```xml
41+
{% highlight xml %}
4242
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DataObject/etc/fieldset.xsd">
4343
<scope id="global">
4444
<fieldset id="sales_convert_quote">
@@ -48,66 +48,50 @@ The code snippet in the next step uses the name of the fieldset and aspect to sp
4848
</fieldset>
4949
</scope>
5050
</config>
51-
```
51+
{% endhighlight %}
5252

5353
## Step 3: Copy the fieldset
5454
{:#step-3}
5555

56-
For copying the fieldset, we'll observe the `sales_model_service_quote_submit_before` event by using the following code in our `events.xml` file:
57-
58-
```xml
59-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
60-
<event name="sales_model_service_quote_submit_before">
61-
<observer name="[vendor]_[module]_sales_model_service_quote_submit_before" instance="Vendor\Module\Observer\SaveOrderBeforeSalesModelQuoteObserver" />
62-
</event>
63-
</config>
64-
```
65-
6656
The following code snippets highlight the code pieces needed to copy a fieldset using the `\Magento\Framework\DataObject\Copy` class.
6757

68-
```php
69-
<?php
70-
namespace Vendor\Module\Observer;
58+
{% highlight php startinline %}
59+
...
7160

72-
use Magento\Framework\Event\ObserverInterface;
61+
/**
62+
* @var \Magento\Framework\DataObject\Copy
63+
*/
64+
protected $objectCopyService;
7365

74-
class SaveOrderBeforeSalesModelQuoteObserver implements ObserverInterface
75-
{
7666
...
77-
/**
78-
* @var \Magento\Framework\DataObject\Copy
79-
*/
80-
protected $objectCopyService;
8167

68+
/**
69+
* @param \Magento\Framework\DataObject\Copy $objectCopyService
70+
...
71+
*/
72+
public function __construct(
73+
\Magento\Framework\DataObject\Copy $objectCopyService,
74+
...
75+
) {
76+
$this->objectCopyService = $objectCopyService;
8277
...
78+
}
79+
80+
...
8381

84-
/**
85-
* @param \Magento\Framework\DataObject\Copy $objectCopyService
86-
...
87-
*/
88-
public function __construct(
89-
\Magento\Framework\DataObject\Copy $objectCopyService,
90-
...
91-
) {
92-
$this->objectCopyService = $objectCopyService;
93-
...
94-
}
95-
96-
/**
97-
* @param \Magento\Framework\Event\Observer $observer
98-
*/
99-
private function execute(\Magento\Framework\Event\Observer $observer)
100-
{
101-
/* @var Magento\Sales\Model\Order $order */
102-
$order = $observer->getEvent()->getData('order');
103-
/* @var Magento\Quote\Model\Quote $quote */
104-
$quote = $observer->getEvent()->getData('quote');
105-
$this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $quote, $order);
106-
...
107-
}
82+
/**
83+
* @param $quote \Magento\Quote\Api\Data\CartInterface
84+
* @param $order \Magento\Sales\Api\Data\Order
85+
*/
86+
private function copyQuoteToOrder($quote, $order)
87+
{
88+
...
89+
$copy->copyFieldsetToTarget('sales_convert_quote', 'to_order', $quote, $order);
90+
...
10891
}
10992

110-
```
93+
...
94+
{% endhighlight %}
11195

11296

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

0 commit comments

Comments
 (0)