Skip to content

Commit

Permalink
Merge pull request #5786 from magento-tsg-csl3/2.4-develop-pr29
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr29)
  • Loading branch information
viktym authored Jun 11, 2020
2 parents 8513dfd + 059b73c commit f3a160c
Show file tree
Hide file tree
Showing 26 changed files with 568 additions and 602 deletions.
57 changes: 0 additions & 57 deletions app/code/Magento/Catalog/Model/Product/SalabilityChecker.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositi
* @param bool $insert
* @return array
*/
private function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false)
public function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false)
{
if (empty($insertLinks)) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function saveLinks(
$resource = $this->linkFactory->create();
$mainTable = $resource->getMainTable();
$positionAttrId = [];
$nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable);

// pre-load 'position' attributes ID for each link type once
foreach ($this->linkNameToId as $linkId) {
Expand All @@ -103,6 +102,7 @@ public function saveLinks(
$positionAttrId[$linkId] = $importEntity->getConnection()->fetchOne($select, $bind);
}
while ($bunch = $dataSourceModel->getNextBunch()) {
$nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable);
$this->processLinkBunches($importEntity, $linkField, $bunch, $resource, $nextLinkId, $positionAttrId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<element name="PageSize" type="input" selector="input[name='parameters[page_size]']"/>
<element name="ProductAttribute" type="multiselect" selector="select[name='parameters[show_attributes][]']"/>
<element name="ButtonToShow" type="multiselect" selector="select[name='parameters[show_buttons][]']"/>
<element name="InputAnchorCustomText" type="input" selector="input[name='parameters[anchor_text]']"/>
<element name="InputAnchorCustomTitle" type="input" selector="input[name='parameters[title]']"/>
<!--Compare on Storefront-->
<element name="ProductName" type="text" selector=".product.name.product-item-name"/>
<element name="CompareBtn" type="button" selector=".action.tocompare"/>
Expand Down
8 changes: 5 additions & 3 deletions app/code/Magento/Config/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function save()
);

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

Expand Down Expand Up @@ -370,6 +371,7 @@ private function getChangedPaths(
$oldConfig,
$extraOldGroups
);
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
$changedPaths = \array_merge($changedPaths, $subGroupChangedPaths);
}
}
Expand Down Expand Up @@ -435,11 +437,11 @@ protected function _processGroup(
if (!isset($fieldData['value'])) {
$fieldData['value'] = null;
}

if ($field->getType() == 'multiline' && is_array($fieldData['value'])) {
$fieldData['value'] = trim(implode(PHP_EOL, $fieldData['value']));
}

$data = [
'field' => $fieldId,
'groups' => $groups,
Expand All @@ -453,7 +455,7 @@ protected function _processGroup(
$backendModel->addData($data);
$this->_checkSingleStoreMode($field, $backendModel);

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

$inherit = !empty($fieldData['inherit']);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Block\DataProviders;

use Magento\Framework\AuthorizationInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Provides permissions data into template.
*/
class PermissionsData implements ArgumentInterface
{
/**
* @var AuthorizationInterface
*/
private $authorization;

/**
* Constructor
*
* @param AuthorizationInterface $authorization
*/
public function __construct(AuthorizationInterface $authorization)
{
$this->authorization = $authorization;
}

/**
* Check that user is allowed to manage attributes
*
* @return bool
*/
public function isAllowedToManageAttributes(): bool
{
return $this->authorization->isAllowed('Magento_Catalog::attributes_attributes');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<item name="modal" xsi:type="string">configurableModal</item>
<item name="dataScope" xsi:type="string">productFormConfigurable</item>
</argument>
<argument name="permissions" xsi:type="object">Magento\ConfigurableProduct\Block\DataProviders\PermissionsData</argument>
</arguments>
</block>
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Bulk" name="step3" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/bulk.phtml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
*/

/* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues */
$isAllowedToManageAttributes = $block->getPermissions()->isAllowedToManageAttributes();
$attributesUrl = $block->getUrl('catalog/product_attribute/getAttributes');
$optionsUrl = $block->getUrl('catalog/product_attribute/createOptions');
?>
<div data-bind="scope: '<?= /* @noEscape */ $block->getComponentName() ?>'">
<h2 class="steps-wizard-title"><?= $block->escapeHtml(
__('Step 2: Attribute Values')
); ?></h2>
<div class="steps-wizard-info">
<span><?= $block->escapeHtml(
__('Select values from each attribute to include in this product. Each unique combination of values creates a unique product SKU.')
__('Select values from each attribute to include in this product. ' .
'Each unique combination of values creates a unique product SKU.')
);?></span>
</div>
<div data-bind="foreach: attributes, sortableList: attributes">
Expand Down Expand Up @@ -72,7 +76,8 @@
<label data-bind="text: label, visible: label, attr:{for:id}"
class="admin__field-label"></label>
</div>
<div class="admin__field admin__field-create-new" data-bind="attr:{'data-role':id}, visible: !label">
<div class="admin__field admin__field-create-new"
data-bind="attr:{'data-role':id}, visible: !label">
<div class="admin__field-control">
<input class="admin__control-text"
name="label"
Expand Down Expand Up @@ -101,14 +106,14 @@
</li>
</ul>
</fieldset>
<button class="action-create-new action-tertiary"
type="button"
data-action="addOption"
data-bind="click: $parent.createOption, visible: canCreateOption">
<span><?= $block->escapeHtml(
__('Create New Value')
); ?></span>
</button>
<?php if ($isAllowedToManageAttributes): ?>
<button class="action-create-new action-tertiary"
type="button"
data-action="addOption"
data-bind="click: $parent.createOption, visible: canCreateOption">
<span><?= $block->escapeHtml(__('Create New Value')); ?></span>
</button>
<?php endif; ?>
</div>
</div>
</div>
Expand All @@ -120,8 +125,8 @@
"<?= /* @noEscape */ $block->getComponentName() ?>": {
"component": "Magento_ConfigurableProduct/js/variations/steps/attributes_values",
"appendTo": "<?= /* @noEscape */ $block->getParentComponentName() ?>",
"optionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/getAttributes') ?>",
"createOptionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/createOptions') ?>"
"optionsUrl": "<?= /* @noEscape */ $attributesUrl ?>",
"createOptionsUrl": "<?= /* @noEscape */ $optionsUrl ?>"
}
}
}
Expand Down
33 changes: 24 additions & 9 deletions app/code/Magento/Downloadable/Controller/Download/LinkSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

namespace Magento\Downloadable\Controller\Download;

use Magento\Catalog\Model\Product\SalabilityChecker;
use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Downloadable\Model\Link as LinkModel;
use Magento\Downloadable\Model\RelatedProductRetriever;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;

Expand All @@ -20,20 +21,21 @@
class LinkSample extends \Magento\Downloadable\Controller\Download
{
/**
* @var SalabilityChecker
* @var RelatedProductRetriever
*/
private $salabilityChecker;
private $relatedProductRetriever;

/**
* @param Context $context
* @param SalabilityChecker|null $salabilityChecker
* @param RelatedProductRetriever $relatedProductRetriever
*/
public function __construct(
Context $context,
SalabilityChecker $salabilityChecker = null
RelatedProductRetriever $relatedProductRetriever
) {
parent::__construct($context);
$this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class);

$this->relatedProductRetriever = $relatedProductRetriever;
}

/**
Expand All @@ -44,9 +46,10 @@ public function __construct(
public function execute()
{
$linkId = $this->getRequest()->getParam('link_id', 0);
/** @var \Magento\Downloadable\Model\Link $link */
$link = $this->_objectManager->create(\Magento\Downloadable\Model\Link::class)->load($linkId);
if ($link->getId() && $this->salabilityChecker->isSalable($link->getProductId())) {
/** @var LinkModel $link */
$link = $this->_objectManager->create(LinkModel::class);
$link->load($linkId);
if ($link->getId() && $this->isProductSalable($link)) {
$resource = '';
$resourceType = '';
if ($link->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
Expand Down Expand Up @@ -74,4 +77,16 @@ public function execute()

return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}

/**
* Check is related product salable.
*
* @param LinkModel $link
* @return bool
*/
private function isProductSalable(LinkModel $link): bool
{
$product = $this->relatedProductRetriever->getProduct((int) $link->getProductId());
return $product ? $product->isSalable() : false;
}
}
33 changes: 24 additions & 9 deletions app/code/Magento/Downloadable/Controller/Download/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

namespace Magento\Downloadable\Controller\Download;

use Magento\Catalog\Model\Product\SalabilityChecker;
use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Downloadable\Model\RelatedProductRetriever;
use Magento\Downloadable\Model\Sample as SampleModel;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;

Expand All @@ -20,20 +21,21 @@
class Sample extends \Magento\Downloadable\Controller\Download
{
/**
* @var SalabilityChecker
* @var RelatedProductRetriever
*/
private $salabilityChecker;
private $relatedProductRetriever;

/**
* @param Context $context
* @param SalabilityChecker|null $salabilityChecker
* @param RelatedProductRetriever $relatedProductRetriever
*/
public function __construct(
Context $context,
SalabilityChecker $salabilityChecker = null
RelatedProductRetriever $relatedProductRetriever
) {
parent::__construct($context);
$this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class);

$this->relatedProductRetriever = $relatedProductRetriever;
}

/**
Expand All @@ -44,9 +46,10 @@ public function __construct(
public function execute()
{
$sampleId = $this->getRequest()->getParam('sample_id', 0);
/** @var \Magento\Downloadable\Model\Sample $sample */
$sample = $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class)->load($sampleId);
if ($sample->getId() && $this->salabilityChecker->isSalable($sample->getProductId())) {
/** @var SampleModel $sample */
$sample = $this->_objectManager->create(SampleModel::class);
$sample->load($sampleId);
if ($sample->getId() && $this->isProductSalable($sample)) {
$resource = '';
$resourceType = '';
if ($sample->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
Expand All @@ -71,4 +74,16 @@ public function execute()

return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}

/**
* Check is related product salable.
*
* @param SampleModel $sample
* @return bool
*/
private function isProductSalable(SampleModel $sample): bool
{
$product = $this->relatedProductRetriever->getProduct((int) $sample->getProductId());
return $product ? $product->isSalable() : false;
}
}
Loading

0 comments on commit f3a160c

Please sign in to comment.