Skip to content

Commit f3a160c

Browse files
authored
Merge pull request #5786 from magento-tsg-csl3/2.4-develop-pr29
[TSG-CSL3] For 2.4 (pr29)
2 parents 8513dfd + 059b73c commit f3a160c

File tree

26 files changed

+568
-602
lines changed

26 files changed

+568
-602
lines changed

app/code/Magento/Catalog/Model/Product/SalabilityChecker.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositi
147147
* @param bool $insert
148148
* @return array
149149
*/
150-
private function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false)
150+
public function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false)
151151
{
152152
if (empty($insertLinks)) {
153153
return [];

app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function saveLinks(
8989
$resource = $this->linkFactory->create();
9090
$mainTable = $resource->getMainTable();
9191
$positionAttrId = [];
92-
$nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable);
9392

9493
// pre-load 'position' attributes ID for each link type once
9594
foreach ($this->linkNameToId as $linkId) {
@@ -103,6 +102,7 @@ public function saveLinks(
103102
$positionAttrId[$linkId] = $importEntity->getConnection()->fetchOne($select, $bind);
104103
}
105104
while ($bunch = $dataSourceModel->getNextBunch()) {
105+
$nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable);
106106
$this->processLinkBunches($importEntity, $linkField, $bunch, $resource, $nextLinkId, $positionAttrId);
107107
}
108108
}

app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<element name="PageSize" type="input" selector="input[name='parameters[page_size]']"/>
3939
<element name="ProductAttribute" type="multiselect" selector="select[name='parameters[show_attributes][]']"/>
4040
<element name="ButtonToShow" type="multiselect" selector="select[name='parameters[show_buttons][]']"/>
41+
<element name="InputAnchorCustomText" type="input" selector="input[name='parameters[anchor_text]']"/>
42+
<element name="InputAnchorCustomTitle" type="input" selector="input[name='parameters[title]']"/>
4143
<!--Compare on Storefront-->
4244
<element name="ProductName" type="text" selector=".product.name.product-item-name"/>
4345
<element name="CompareBtn" type="button" selector=".action.tocompare"/>

app/code/Magento/Config/Model/Config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public function save()
208208
);
209209

210210
$groupChangedPaths = $this->getChangedPaths($sectionId, $groupId, $groupData, $oldConfig, $extraOldGroups);
211+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
211212
$changedPaths = \array_merge($changedPaths, $groupChangedPaths);
212213
}
213214

@@ -370,6 +371,7 @@ private function getChangedPaths(
370371
$oldConfig,
371372
$extraOldGroups
372373
);
374+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
373375
$changedPaths = \array_merge($changedPaths, $subGroupChangedPaths);
374376
}
375377
}
@@ -435,11 +437,11 @@ protected function _processGroup(
435437
if (!isset($fieldData['value'])) {
436438
$fieldData['value'] = null;
437439
}
438-
440+
439441
if ($field->getType() == 'multiline' && is_array($fieldData['value'])) {
440442
$fieldData['value'] = trim(implode(PHP_EOL, $fieldData['value']));
441443
}
442-
444+
443445
$data = [
444446
'field' => $fieldId,
445447
'groups' => $groups,
@@ -453,7 +455,7 @@ protected function _processGroup(
453455
$backendModel->addData($data);
454456
$this->_checkSingleStoreMode($field, $backendModel);
455457

456-
$path = $this->getFieldPath($field, $fieldId, $extraOldGroups, $oldConfig);
458+
$path = $this->getFieldPath($field, $fieldId, $oldConfig, $extraOldGroups);
457459
$backendModel->setPath($path)->setValue($fieldData['value']);
458460

459461
$inherit = !empty($fieldData['inherit']);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Block\DataProviders;
9+
10+
use Magento\Framework\AuthorizationInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Provides permissions data into template.
15+
*/
16+
class PermissionsData implements ArgumentInterface
17+
{
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(AuthorizationInterface $authorization)
29+
{
30+
$this->authorization = $authorization;
31+
}
32+
33+
/**
34+
* Check that user is allowed to manage attributes
35+
*
36+
* @return bool
37+
*/
38+
public function isAllowedToManageAttributes(): bool
39+
{
40+
return $this->authorization->isAllowed('Magento_Catalog::attributes_attributes');
41+
}
42+
}

app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_wizard.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<item name="modal" xsi:type="string">configurableModal</item>
4949
<item name="dataScope" xsi:type="string">productFormConfigurable</item>
5050
</argument>
51+
<argument name="permissions" xsi:type="object">Magento\ConfigurableProduct\Block\DataProviders\PermissionsData</argument>
5152
</arguments>
5253
</block>
5354
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Bulk" name="step3" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/bulk.phtml">

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
*/
66

77
/* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues */
8+
$isAllowedToManageAttributes = $block->getPermissions()->isAllowedToManageAttributes();
9+
$attributesUrl = $block->getUrl('catalog/product_attribute/getAttributes');
10+
$optionsUrl = $block->getUrl('catalog/product_attribute/createOptions');
811
?>
912
<div data-bind="scope: '<?= /* @noEscape */ $block->getComponentName() ?>'">
1013
<h2 class="steps-wizard-title"><?= $block->escapeHtml(
1114
__('Step 2: Attribute Values')
1215
); ?></h2>
1316
<div class="steps-wizard-info">
1417
<span><?= $block->escapeHtml(
15-
__('Select values from each attribute to include in this product. Each unique combination of values creates a unique product SKU.')
18+
__('Select values from each attribute to include in this product. ' .
19+
'Each unique combination of values creates a unique product SKU.')
1620
);?></span>
1721
</div>
1822
<div data-bind="foreach: attributes, sortableList: attributes">
@@ -72,7 +76,8 @@
7276
<label data-bind="text: label, visible: label, attr:{for:id}"
7377
class="admin__field-label"></label>
7478
</div>
75-
<div class="admin__field admin__field-create-new" data-bind="attr:{'data-role':id}, visible: !label">
79+
<div class="admin__field admin__field-create-new"
80+
data-bind="attr:{'data-role':id}, visible: !label">
7681
<div class="admin__field-control">
7782
<input class="admin__control-text"
7883
name="label"
@@ -101,14 +106,14 @@
101106
</li>
102107
</ul>
103108
</fieldset>
104-
<button class="action-create-new action-tertiary"
105-
type="button"
106-
data-action="addOption"
107-
data-bind="click: $parent.createOption, visible: canCreateOption">
108-
<span><?= $block->escapeHtml(
109-
__('Create New Value')
110-
); ?></span>
111-
</button>
109+
<?php if ($isAllowedToManageAttributes): ?>
110+
<button class="action-create-new action-tertiary"
111+
type="button"
112+
data-action="addOption"
113+
data-bind="click: $parent.createOption, visible: canCreateOption">
114+
<span><?= $block->escapeHtml(__('Create New Value')); ?></span>
115+
</button>
116+
<?php endif; ?>
112117
</div>
113118
</div>
114119
</div>
@@ -120,8 +125,8 @@
120125
"<?= /* @noEscape */ $block->getComponentName() ?>": {
121126
"component": "Magento_ConfigurableProduct/js/variations/steps/attributes_values",
122127
"appendTo": "<?= /* @noEscape */ $block->getParentComponentName() ?>",
123-
"optionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/getAttributes') ?>",
124-
"createOptionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/createOptions') ?>"
128+
"optionsUrl": "<?= /* @noEscape */ $attributesUrl ?>",
129+
"createOptionsUrl": "<?= /* @noEscape */ $optionsUrl ?>"
125130
}
126131
}
127132
}

app/code/Magento/Downloadable/Controller/Download/LinkSample.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\Downloadable\Controller\Download;
99

10-
use Magento\Catalog\Model\Product\SalabilityChecker;
1110
use Magento\Downloadable\Helper\Download as DownloadHelper;
11+
use Magento\Downloadable\Model\Link as LinkModel;
12+
use Magento\Downloadable\Model\RelatedProductRetriever;
1213
use Magento\Framework\App\Action\Context;
1314
use Magento\Framework\App\ResponseInterface;
1415

@@ -20,20 +21,21 @@
2021
class LinkSample extends \Magento\Downloadable\Controller\Download
2122
{
2223
/**
23-
* @var SalabilityChecker
24+
* @var RelatedProductRetriever
2425
*/
25-
private $salabilityChecker;
26+
private $relatedProductRetriever;
2627

2728
/**
2829
* @param Context $context
29-
* @param SalabilityChecker|null $salabilityChecker
30+
* @param RelatedProductRetriever $relatedProductRetriever
3031
*/
3132
public function __construct(
3233
Context $context,
33-
SalabilityChecker $salabilityChecker = null
34+
RelatedProductRetriever $relatedProductRetriever
3435
) {
3536
parent::__construct($context);
36-
$this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class);
37+
38+
$this->relatedProductRetriever = $relatedProductRetriever;
3739
}
3840

3941
/**
@@ -44,9 +46,10 @@ public function __construct(
4446
public function execute()
4547
{
4648
$linkId = $this->getRequest()->getParam('link_id', 0);
47-
/** @var \Magento\Downloadable\Model\Link $link */
48-
$link = $this->_objectManager->create(\Magento\Downloadable\Model\Link::class)->load($linkId);
49-
if ($link->getId() && $this->salabilityChecker->isSalable($link->getProductId())) {
49+
/** @var LinkModel $link */
50+
$link = $this->_objectManager->create(LinkModel::class);
51+
$link->load($linkId);
52+
if ($link->getId() && $this->isProductSalable($link)) {
5053
$resource = '';
5154
$resourceType = '';
5255
if ($link->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
@@ -74,4 +77,16 @@ public function execute()
7477

7578
return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
7679
}
80+
81+
/**
82+
* Check is related product salable.
83+
*
84+
* @param LinkModel $link
85+
* @return bool
86+
*/
87+
private function isProductSalable(LinkModel $link): bool
88+
{
89+
$product = $this->relatedProductRetriever->getProduct((int) $link->getProductId());
90+
return $product ? $product->isSalable() : false;
91+
}
7792
}

app/code/Magento/Downloadable/Controller/Download/Sample.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\Downloadable\Controller\Download;
99

10-
use Magento\Catalog\Model\Product\SalabilityChecker;
1110
use Magento\Downloadable\Helper\Download as DownloadHelper;
11+
use Magento\Downloadable\Model\RelatedProductRetriever;
12+
use Magento\Downloadable\Model\Sample as SampleModel;
1213
use Magento\Framework\App\Action\Context;
1314
use Magento\Framework\App\ResponseInterface;
1415

@@ -20,20 +21,21 @@
2021
class Sample extends \Magento\Downloadable\Controller\Download
2122
{
2223
/**
23-
* @var SalabilityChecker
24+
* @var RelatedProductRetriever
2425
*/
25-
private $salabilityChecker;
26+
private $relatedProductRetriever;
2627

2728
/**
2829
* @param Context $context
29-
* @param SalabilityChecker|null $salabilityChecker
30+
* @param RelatedProductRetriever $relatedProductRetriever
3031
*/
3132
public function __construct(
3233
Context $context,
33-
SalabilityChecker $salabilityChecker = null
34+
RelatedProductRetriever $relatedProductRetriever
3435
) {
3536
parent::__construct($context);
36-
$this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class);
37+
38+
$this->relatedProductRetriever = $relatedProductRetriever;
3739
}
3840

3941
/**
@@ -44,9 +46,10 @@ public function __construct(
4446
public function execute()
4547
{
4648
$sampleId = $this->getRequest()->getParam('sample_id', 0);
47-
/** @var \Magento\Downloadable\Model\Sample $sample */
48-
$sample = $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class)->load($sampleId);
49-
if ($sample->getId() && $this->salabilityChecker->isSalable($sample->getProductId())) {
49+
/** @var SampleModel $sample */
50+
$sample = $this->_objectManager->create(SampleModel::class);
51+
$sample->load($sampleId);
52+
if ($sample->getId() && $this->isProductSalable($sample)) {
5053
$resource = '';
5154
$resourceType = '';
5255
if ($sample->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
@@ -71,4 +74,16 @@ public function execute()
7174

7275
return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
7376
}
77+
78+
/**
79+
* Check is related product salable.
80+
*
81+
* @param SampleModel $sample
82+
* @return bool
83+
*/
84+
private function isProductSalable(SampleModel $sample): bool
85+
{
86+
$product = $this->relatedProductRetriever->getProduct((int) $sample->getProductId());
87+
return $product ? $product->isSalable() : false;
88+
}
7489
}

0 commit comments

Comments
 (0)