3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Catalog \Controller \Adminhtml \Product ;
7
9
8
10
use Magento \Catalog \Model \ProductFactory ;
15
17
use Magento \Catalog \Model \Product ;
16
18
use Magento \Catalog \Model \Product \Type as ProductTypes ;
17
19
20
+ /**
21
+ * Build a product based on a request
22
+ *
23
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
+ */
18
25
class Builder
19
26
{
20
27
/**
@@ -81,8 +88,9 @@ public function __construct(
81
88
* @param RequestInterface $request
82
89
* @return \Magento\Catalog\Model\Product
83
90
* @throws \RuntimeException
91
+ * @throws \Magento\Framework\Exception\LocalizedException
84
92
*/
85
- public function build (RequestInterface $ request )
93
+ public function build (RequestInterface $ request ): Product
86
94
{
87
95
$ productId = (int ) $ request ->getParam ('id ' );
88
96
$ storeId = $ request ->getParam ('store ' , 0 );
@@ -92,6 +100,7 @@ public function build(RequestInterface $request)
92
100
if ($ productId ) {
93
101
try {
94
102
$ product = $ this ->productRepository ->getById ($ productId , true , $ storeId );
103
+ $ product ->setAttributeSetId ($ attributeSetId );
95
104
} catch (\Exception $ e ) {
96
105
$ product = $ this ->createEmptyProduct (ProductTypes::DEFAULT_TYPE , $ attributeSetId , $ storeId );
97
106
$ this ->logger ->critical ($ e );
@@ -113,6 +122,8 @@ public function build(RequestInterface $request)
113
122
}
114
123
115
124
/**
125
+ * Create a product with the given properties
126
+ *
116
127
* @param int $typeId
117
128
* @param int $attributeSetId
118
129
* @param int $storeId
0 commit comments