Skip to content

Commit 215ee87

Browse files
committed
Merge remote-tracking branch 'mainline-ce/2.3-develop' into MC-19247
2 parents 6252d2c + 6f1a6f7 commit 215ee87

File tree

25 files changed

+729
-231
lines changed

25 files changed

+729
-231
lines changed

app/code/Magento/Bundle/Model/Product/CopyConstructor/Bundle.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Catalog\Model\Product;
99
use Magento\Catalog\Model\Product\Type;
1010

11+
/**
12+
* Provides duplicating bundle options and selections
13+
*/
1114
class Bundle implements \Magento\Catalog\Model\Product\CopyConstructorInterface
1215
{
1316
/**
@@ -27,7 +30,17 @@ public function build(Product $product, Product $duplicate)
2730
$bundleOptions = $product->getExtensionAttributes()->getBundleProductOptions() ?: [];
2831
$duplicatedBundleOptions = [];
2932
foreach ($bundleOptions as $key => $bundleOption) {
30-
$duplicatedBundleOptions[$key] = clone $bundleOption;
33+
$duplicatedBundleOption = clone $bundleOption;
34+
/**
35+
* Set option and selection ids to 'null' in order to create new option(selection) for duplicated product,
36+
* but not modifying existing one, which led to lost of option(selection) in original product.
37+
*/
38+
$productLinks = $duplicatedBundleOption->getProductLinks() ?: [];
39+
foreach ($productLinks as $productLink) {
40+
$productLink->setSelectionId(null);
41+
}
42+
$duplicatedBundleOption->setOptionId(null);
43+
$duplicatedBundleOptions[$key] = $duplicatedBundleOption;
3144
}
3245
$duplicate->getExtensionAttributes()->setBundleProductOptions($duplicatedBundleOptions);
3346
}

app/code/Magento/Bundle/Test/Unit/Model/Product/CopyConstructor/BundleTest.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Bundle\Test\Unit\Model\Product\CopyConstructor;
77

88
use Magento\Bundle\Api\Data\BundleOptionInterface;
9+
use Magento\Bundle\Model\Link;
910
use Magento\Bundle\Model\Product\CopyConstructor\Bundle;
1011
use Magento\Catalog\Api\Data\ProductExtensionInterface;
1112
use Magento\Catalog\Model\Product;
@@ -45,6 +46,7 @@ public function testBuildNegative()
4546
*/
4647
public function testBuildPositive()
4748
{
49+
/** @var Product|\PHPUnit_Framework_MockObject_MockObject $product */
4850
$product = $this->getMockBuilder(Product::class)
4951
->disableOriginalConstructor()
5052
->getMock();
@@ -60,18 +62,42 @@ public function testBuildPositive()
6062
->method('getExtensionAttributes')
6163
->willReturn($extensionAttributesProduct);
6264

65+
$productLink = $this->getMockBuilder(Link::class)
66+
->setMethods(['setSelectionId'])
67+
->disableOriginalConstructor()
68+
->getMock();
69+
$productLink->expects($this->exactly(2))
70+
->method('setSelectionId')
71+
->with($this->identicalTo(null));
72+
$firstOption = $this->getMockBuilder(BundleOptionInterface::class)
73+
->setMethods(['getProductLinks'])
74+
->disableOriginalConstructor()
75+
->getMockForAbstractClass();
76+
$firstOption->expects($this->once())
77+
->method('getProductLinks')
78+
->willReturn([$productLink]);
79+
$firstOption->expects($this->once())
80+
->method('setOptionId')
81+
->with($this->identicalTo(null));
82+
$secondOption = $this->getMockBuilder(BundleOptionInterface::class)
83+
->setMethods(['getProductLinks'])
84+
->disableOriginalConstructor()
85+
->getMockForAbstractClass();
86+
$secondOption->expects($this->once())
87+
->method('getProductLinks')
88+
->willReturn([$productLink]);
89+
$secondOption->expects($this->once())
90+
->method('setOptionId')
91+
->with($this->identicalTo(null));
6392
$bundleOptions = [
64-
$this->getMockBuilder(BundleOptionInterface::class)
65-
->disableOriginalConstructor()
66-
->getMockForAbstractClass(),
67-
$this->getMockBuilder(BundleOptionInterface::class)
68-
->disableOriginalConstructor()
69-
->getMockForAbstractClass()
93+
$firstOption,
94+
$secondOption
7095
];
7196
$extensionAttributesProduct->expects($this->once())
7297
->method('getBundleProductOptions')
7398
->willReturn($bundleOptions);
7499

100+
/** @var Product|\PHPUnit_Framework_MockObject_MockObject $duplicate */
75101
$duplicate = $this->getMockBuilder(Product::class)
76102
->disableOriginalConstructor()
77103
->getMock();

app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,63 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Set;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
9+
use Magento\Framework\Registry;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Backend\Model\View\Result\Page;
13+
use Magento\Framework\View\Result\PageFactory;
14+
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
16+
use Magento\Catalog\Controller\Adminhtml\Product\Set;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Magento\Framework\App\Action\HttpGetActionInterface;
1019

11-
class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpGetActionInterface
20+
/**
21+
* Edit attribute set controller.
22+
*/
23+
class Edit extends Set implements HttpGetActionInterface
1224
{
1325
/**
14-
* @var \Magento\Framework\View\Result\PageFactory
26+
* @var PageFactory
1527
*/
1628
protected $resultPageFactory;
1729

1830
/**
19-
* @param \Magento\Backend\App\Action\Context $context
20-
* @param \Magento\Framework\Registry $coreRegistry
21-
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
31+
* @var AttributeSetRepositoryInterface
32+
*/
33+
private $attributeSetRepository;
34+
35+
/**
36+
* @param Context $context
37+
* @param Registry $coreRegistry
38+
* @param PageFactory $resultPageFactory
39+
* @param AttributeSetRepositoryInterface $attributeSetRepository
2240
*/
2341
public function __construct(
24-
\Magento\Backend\App\Action\Context $context,
25-
\Magento\Framework\Registry $coreRegistry,
26-
\Magento\Framework\View\Result\PageFactory $resultPageFactory
42+
Context $context,
43+
Registry $coreRegistry,
44+
PageFactory $resultPageFactory,
45+
AttributeSetRepositoryInterface $attributeSetRepository = null
2746
) {
2847
parent::__construct($context, $coreRegistry);
2948
$this->resultPageFactory = $resultPageFactory;
49+
$this->attributeSetRepository = $attributeSetRepository ?:
50+
ObjectManager::getInstance()->get(AttributeSetRepositoryInterface::class);
3051
}
3152

3253
/**
33-
* @return \Magento\Backend\Model\View\Result\Page
54+
* @inheritdoc
3455
*/
3556
public function execute()
3657
{
3758
$this->_setTypeId();
38-
$attributeSet = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
39-
->load($this->getRequest()->getParam('id'));
40-
59+
$attributeSet = $this->attributeSetRepository->get($this->getRequest()->getParam('id'));
4160
if (!$attributeSet->getId()) {
4261
return $this->resultRedirectFactory->create()->setPath('catalog/*/index');
4362
}
44-
4563
$this->_coreRegistry->register('current_attribute_set', $attributeSet);
4664

47-
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
65+
/** @var Page $resultPage */
4866
$resultPage = $this->resultPageFactory->create();
4967
$resultPage->setActiveMenu('Magento_Catalog::catalog_attributes_sets');
5068
$resultPage->getConfig()->getTitle()->prepend(__('Attribute Sets'));

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4747
* @SuppressWarnings(PHPMD.TooManyFields)
4848
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
49+
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
4950
* @since 101.0.0
5051
*/
5152
class Eav extends AbstractModifier
@@ -1048,6 +1049,10 @@ private function isScopeGlobal($attribute)
10481049
*/
10491050
private function getAttributeModel($attribute)
10501051
{
1052+
// The statement below solves performance issue related to loading same attribute options on different models
1053+
if ($attribute instanceof EavAttribute) {
1054+
return $attribute;
1055+
}
10511056
$attributeId = $attribute->getAttributeId();
10521057

10531058
if (!array_key_exists($attributeId, $this->attributesCache)) {

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ $_helper = $this->helper(Magento\Catalog\Helper\Output::class);
7272
</strong>
7373
<?= $block->getReviewsSummaryHtml($_product, $templateType) ?>
7474
<?= /* @noEscape */ $block->getProductPrice($_product) ?>
75-
<?= $block->getProductDetailsHtml($_product) ?>
75+
<?php if ($_product->isAvailable()) :?>
76+
<?= $block->getProductDetailsHtml($_product) ?>
77+
<?php endif; ?>
7678

7779
<div class="product-item-inner">
7880
<div class="product actions product-item-actions"<?= strpos($pos, $viewMode . '-actions') ? $block->escapeHtmlAttr($position) : '' ?>>

app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config/Matrix.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ protected function getAttributes()
197197
foreach ($attributes as $key => $attribute) {
198198
if (isset($configurableData[$key])) {
199199
$attributes[$key] = array_replace_recursive($attribute, $configurableData[$key]);
200+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
200201
$attributes[$key]['values'] = array_merge(
201202
isset($attribute['values']) ? $attribute['values'] : [],
202203
isset($configurableData[$key]['values'])
@@ -412,14 +413,15 @@ private function prepareAttributes(
412413
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
413414
'chosen' => [],
414415
];
415-
foreach ($attribute->getOptions() as $option) {
416-
if (!empty($option->getValue())) {
416+
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
417+
foreach ($options as $option) {
418+
if (!empty($option['value'])) {
417419
$attributes[$attribute->getAttributeId()]['options'][] = [
418420
'attribute_code' => $attribute->getAttributeCode(),
419421
'attribute_label' => $attribute->getStoreLabel(0),
420-
'id' => $option->getValue(),
421-
'label' => $option->getLabel(),
422-
'value' => $option->getValue(),
422+
'id' => $option['value'],
423+
'label' => $option['label'],
424+
'value' => $option['value'],
423425
'__disableTmpl' => true,
424426
];
425427
}

app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Framework\Escaper;
2222

2323
/**
24+
* Associated products helper
25+
*
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
2628
class AssociatedProducts
@@ -231,6 +233,8 @@ public function getConfigurableAttributesData()
231233
*
232234
* @return void
233235
* @throws \Zend_Currency_Exception
236+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
237+
* phpcs:disable Generic.Metrics.NestingLevel
234238
*/
235239
protected function prepareVariations()
236240
{
@@ -262,14 +266,15 @@ protected function prepareVariations()
262266
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
263267
'chosen' => [],
264268
];
265-
foreach ($attribute->getOptions() as $option) {
266-
if (!empty($option->getValue())) {
267-
$attributes[$attribute->getAttributeId()]['options'][$option->getValue()] = [
269+
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
270+
foreach ($options as $option) {
271+
if (!empty($option['value'])) {
272+
$attributes[$attribute->getAttributeId()]['options'][$option['value']] = [
268273
'attribute_code' => $attribute->getAttributeCode(),
269274
'attribute_label' => $attribute->getStoreLabel(0),
270-
'id' => $option->getValue(),
271-
'label' => $option->getLabel(),
272-
'value' => $option->getValue(),
275+
'id' => $option['value'],
276+
'label' => $option['label'],
277+
'value' => $option['value'],
273278
];
274279
}
275280
}

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ protected function buildQueries(array $matches, array $queryValue)
138138

139139
$transformedTypes = [];
140140
foreach ($matches as $match) {
141-
$attributeAdapter = $this->attributeProvider->getByAttributeCode($match['field']);
141+
$resolvedField = $this->fieldMapper->getFieldName(
142+
$match['field'],
143+
['type' => FieldMapperInterface::TYPE_QUERY]
144+
);
145+
146+
$attributeAdapter = $this->attributeProvider->getByAttributeCode($resolvedField);
142147
$fieldType = $this->fieldTypeResolver->getFieldType($attributeAdapter);
143148
$valueTransformer = $this->valueTransformerPool->get($fieldType ?? 'text');
144149
$valueTransformerHash = \spl_object_hash($valueTransformer);
@@ -151,10 +156,6 @@ protected function buildQueries(array $matches, array $queryValue)
151156
continue;
152157
}
153158

154-
$resolvedField = $this->fieldMapper->getFieldName(
155-
$match['field'],
156-
['type' => FieldMapperInterface::TYPE_QUERY]
157-
);
158159
$conditions[] = [
159160
'condition' => $queryValue['condition'],
160161
'body' => [

app/code/Magento/Paypal/etc/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
<title>Credit Card (Payflow Advanced)</title>
165165
<partner>PayPal</partner>
166166
<vendor>PayPal</vendor>
167-
<user>PayPal</user>
168167
<csc_required>1</csc_required>
169168
<csc_editable>1</csc_editable>
170169
<url_method>GET</url_method>

app/code/Magento/ProductAlert/Controller/Add/Price.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
namespace Magento\ProductAlert\Controller\Add;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface;
10-
use Magento\ProductAlert\Controller\Add as AddController;
11-
use Magento\Framework\App\Action\Context;
12-
use Magento\Customer\Model\Session as CustomerSession;
13-
use Magento\Store\Model\StoreManagerInterface;
149
use Magento\Catalog\Api\ProductRepositoryInterface;
15-
use Magento\Framework\UrlInterface;
10+
use Magento\Customer\Model\Session as CustomerSession;
1611
use Magento\Framework\App\Action\Action;
12+
use Magento\Framework\App\Action\Context;
13+
use Magento\Framework\App\Action\HttpGetActionInterface;
1714
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Controller\Result\Redirect;
1816
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Framework\UrlInterface;
18+
use Magento\ProductAlert\Controller\Add as AddController;
19+
use Magento\Store\Model\StoreManagerInterface;
1920

2021
/**
2122
* Controller for notifying about price.
@@ -28,15 +29,17 @@ class Price extends AddController implements HttpGetActionInterface
2829
protected $storeManager;
2930

3031
/**
31-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
32+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
3233
*/
3334
protected $productRepository;
3435

3536
/**
36-
* @param \Magento\Framework\App\Action\Context $context
37-
* @param \Magento\Customer\Model\Session $customerSession
38-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
39-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
37+
* Price constructor.
38+
*
39+
* @param Context $context
40+
* @param CustomerSession $customerSession
41+
* @param StoreManagerInterface $storeManager
42+
* @param ProductRepositoryInterface $productRepository
4043
*/
4144
public function __construct(
4245
Context $context,
@@ -54,6 +57,7 @@ public function __construct(
5457
*
5558
* @param string $url
5659
* @return bool
60+
* @throws NoSuchEntityException
5761
*/
5862
protected function isInternal($url)
5963
{
@@ -68,13 +72,14 @@ protected function isInternal($url)
6872
/**
6973
* Method for adding info about product alert price.
7074
*
71-
* @return \Magento\Framework\Controller\Result\Redirect
75+
* @return \Magento\Framework\Controller\ResultInterface
76+
* @throws NoSuchEntityException
7277
*/
7378
public function execute()
7479
{
7580
$backUrl = $this->getRequest()->getParam(Action::PARAM_NAME_URL_ENCODED);
7681
$productId = (int)$this->getRequest()->getParam('product_id');
77-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
82+
/** @var Redirect $resultRedirect */
7883
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
7984
if (!$backUrl || !$productId) {
8085
$resultRedirect->setPath('/');
@@ -93,17 +98,17 @@ public function execute()
9398
->setWebsiteId($store->getWebsiteId())
9499
->setStoreId($store->getId());
95100
$model->save();
96-
$this->messageManager->addSuccess(__('You saved the alert subscription.'));
101+
$this->messageManager->addSuccessMessage(__('You saved the alert subscription.'));
97102
} catch (NoSuchEntityException $noEntityException) {
98-
$this->messageManager->addError(__('There are not enough parameters.'));
103+
$this->messageManager->addErrorMessage(__('There are not enough parameters.'));
99104
if ($this->isInternal($backUrl)) {
100105
$resultRedirect->setUrl($backUrl);
101106
} else {
102107
$resultRedirect->setPath('/');
103108
}
104109
return $resultRedirect;
105110
} catch (\Exception $e) {
106-
$this->messageManager->addException(
111+
$this->messageManager->addExceptionMessage(
107112
$e,
108113
__("The alert subscription couldn't update at this time. Please try again later.")
109114
);

0 commit comments

Comments
 (0)