Skip to content

Commit 33c7cc8

Browse files
committed
MC-35717: Admin can not add a Product with a Customizable Option (File) to Order by SKU
1 parent f55f411 commit 33c7cc8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
namespace Magento\Catalog\Model\Product\Option\Type;
88

9+
use Magento\Catalog\Model\Product\Exception as ProductException;
10+
use Magento\Catalog\Helper\Product as ProductHelper;
911
use Magento\Framework\App\Filesystem\DirectoryList;
1012
use Magento\Framework\Filesystem;
1113
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\Catalog\Model\Product\Exception as ProductException;
1314
use Magento\Framework\Serialize\Serializer\Json;
1415
use Magento\Framework\App\ObjectManager;
1516

@@ -91,6 +92,11 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
9192
*/
9293
private $filesystem;
9394

95+
/**
96+
* @var ProductHelper
97+
*/
98+
private $productHelper;
99+
94100
/**
95101
* @param \Magento\Checkout\Model\Session $checkoutSession
96102
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -103,6 +109,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
103109
* @param array $data
104110
* @param Filesystem $filesystem
105111
* @param Json|null $serializer
112+
* @param ProductHelper|null $productHelper
106113
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
107114
*/
108115
public function __construct(
@@ -116,7 +123,8 @@ public function __construct(
116123
\Magento\Framework\Escaper $escaper,
117124
array $data = [],
118125
Filesystem $filesystem = null,
119-
Json $serializer = null
126+
Json $serializer = null,
127+
ProductHelper $productHelper = null
120128
) {
121129
$this->_itemOptionFactory = $itemOptionFactory;
122130
$this->_urlBuilder = $urlBuilder;
@@ -129,6 +137,7 @@ public function __construct(
129137
$this->validatorInfo = $validatorInfo;
130138
$this->validatorFile = $validatorFile;
131139
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
140+
$this->productHelper = $productHelper ?: ObjectManager::getInstance()->get(ProductHelper::class);
132141
parent::__construct($checkoutSession, $scopeConfig, $data);
133142
}
134143

@@ -223,6 +232,12 @@ public function validateUserValue($values)
223232
$this->setIsValid(true);
224233
$option = $this->getOption();
225234

235+
if (isset($values['files_prefix'])) {
236+
$processingParams = ['files_prefix' => $values['files_prefix']];
237+
$processingParams = array_merge($this->_getProcessingParams()->getData(), $processingParams);
238+
$this->productHelper->addParamsToBuyRequest($this->getRequest(), $processingParams);
239+
}
240+
226241
/*
227242
* Check whether we receive uploaded file or restore file by: reorder/edit configuration or
228243
* previous configuration with no newly uploaded file

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@
581581
<var key="sku" entityType="product" entityKey="sku" />
582582
<requiredEntity type="product_option">ProductOptionValueDropdown</requiredEntity>
583583
</entity>
584+
<entity name="productWithFileOption" type="product">
585+
<var key="sku" entityType="product" entityKey="sku" />
586+
<requiredEntity type="product_option">ProductOptionFile</requiredEntity>
587+
</entity>
584588
<entity name="productWithDropdownAndFieldOptions" type="product">
585589
<var key="sku" entityType="product" entityKey="sku" />
586590
<requiredEntity type="product_option">ProductOptionValueDropdown</requiredEntity>

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/composite/configure.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ define([
607607
* @param method can be 'item_confirm', 'item_restore', 'current_confirmed_to_form', 'form_confirmed_to_confirmed'
608608
*/
609609
_processFieldsData: function (method) {
610+
var self = this;
610611

611612
/**
612613
* Internal function for rename fields names of some list type
@@ -652,6 +653,11 @@ define([
652653
for (var i = 0; i < elms.length; i++) {
653654
if (elms[i].name && elms[i].type == 'file') {
654655
elms[i].name = elms[i].name.replace(patternFlat, replacementFlat);
656+
self.blockFormFields.insert(new Element('input', {
657+
type: 'hidden',
658+
name: 'options[files_prefix]'.replace(pattern, replacement),
659+
value: 'item_' + itemId + '_'
660+
}));
655661
} else if (elms[i].name) {
656662
elms[i].name = elms[i].name.replace(pattern, replacement);
657663
}

0 commit comments

Comments
 (0)