Skip to content

Commit 0a2da15

Browse files
authored
Merge pull request #2220 from magento-qwerty/PR-13032018
[Qwerty] March bugfixes
2 parents 1c74b3b + 25385bb commit 0a2da15

File tree

5 files changed

+85
-28
lines changed

5 files changed

+85
-28
lines changed

.htaccess

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@
355355
Require all denied
356356
</IfVersion>
357357
</Files>
358+
<Files auth.json>
359+
<IfVersion < 2.4>
360+
order allow,deny
361+
deny from all
362+
</IfVersion>
363+
<IfVersion >= 2.4>
364+
Require all denied
365+
</IfVersion>
366+
</Files>
358367

359368
# For 404s and 403s that aren't handled by the application, show plain 404 response
360369
ErrorDocument 404 /pub/errors/404.php

.htaccess.sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@
332332
Require all denied
333333
</IfVersion>
334334
</Files>
335+
<Files auth.json>
336+
<IfVersion < 2.4>
337+
order allow,deny
338+
deny from all
339+
</IfVersion>
340+
<IfVersion >= 2.4>
341+
Require all denied
342+
</IfVersion>
343+
</Files>
335344

336345
# For 404s and 403s that aren't handled by the application, show plain 404 response
337346
ErrorDocument 404 /pub/errors/404.php

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public function save(
201201

202202
/** @var \Magento\Bundle\Model\Option $existingOption */
203203
$existingOption = $optionCollection->getFirstItem();
204-
if (!$optionId) {
205-
$option->setOptionId(null);
206-
}
207204
if (!$optionId || $existingOption->getParentId() != $parentId) {
205+
//If option ID is empty or existing option's parent ID is different
206+
//we'd need a new ID for the option.
207+
$option->setOptionId(null);
208208
$option->setDefaultTitle($option->getTitle());
209209
if (is_array($option->getProductLinks())) {
210210
$linksToAdd = $option->getProductLinks();

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Bundle\Model\Product;
77

8+
use Magento\Bundle\Api\Data\OptionInterface;
89
use Magento\Catalog\Api\Data\ProductInterface;
910
use Magento\Bundle\Api\ProductOptionRepositoryInterface as OptionRepository;
1011
use Magento\Bundle\Api\ProductLinkManagementInterface;
@@ -49,42 +50,58 @@ public function __construct(
4950
?: ObjectManager::getInstance()->get(MetadataPool::class);
5051
}
5152

53+
/**
54+
* @param ProductInterface $bundle
55+
* @param OptionInterface[] $currentOptions
56+
*
57+
* @return void
58+
*/
59+
private function removeOldOptions(
60+
ProductInterface $bundle,
61+
array $currentOptions
62+
) {
63+
$oldOptions = $this->optionRepository->getList($bundle->getSku());
64+
if ($oldOptions) {
65+
$remainingOptions = [];
66+
$metadata
67+
= $this->metadataPool->getMetadata(ProductInterface::class);
68+
$productId = $bundle->getData($metadata->getLinkField());
69+
70+
foreach ($currentOptions as $option) {
71+
$remainingOptions[] = $option->getOptionId();
72+
}
73+
foreach ($oldOptions as $option) {
74+
if (!in_array($option->getOptionId(), $remainingOptions)) {
75+
$option->setParentId($productId);
76+
$this->removeOptionLinks($bundle->getSku(), $option);
77+
$this->optionRepository->delete($option);
78+
}
79+
}
80+
}
81+
}
82+
5283
/**
5384
* @param object $entity
5485
* @param array $arguments
55-
* @return \Magento\Catalog\Api\Data\ProductInterface|object
86+
*
87+
* @return ProductInterface|object
88+
*
5689
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5790
*/
5891
public function execute($entity, $arguments = [])
5992
{
6093
/** @var \Magento\Bundle\Api\Data\OptionInterface[] $options */
6194
$options = $entity->getExtensionAttributes()->getBundleProductOptions() ?: [];
62-
95+
//Only processing bundle products.
6396
if ($entity->getTypeId() !== 'bundle' || empty($options)) {
6497
return $entity;
6598
}
66-
99+
/** @var ProductInterface $entity */
100+
//Removing old options
67101
if (!$entity->getCopyFromView()) {
68-
$updatedOptions = [];
69-
$oldOptions = $this->optionRepository->getList($entity->getSku());
70-
71-
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
72-
73-
$productId = $entity->getData($metadata->getLinkField());
74-
75-
foreach ($options as $option) {
76-
$updatedOptions[$option->getOptionId()][$productId] = (bool)$option->getOptionId();
77-
}
78-
79-
foreach ($oldOptions as $option) {
80-
if (!isset($updatedOptions[$option->getOptionId()][$productId])) {
81-
$option->setParentId($productId);
82-
$this->removeOptionLinks($entity->getSku(), $option);
83-
$this->optionRepository->delete($option);
84-
}
85-
}
102+
$this->removeOldOptions($entity, $options);
86103
}
87-
104+
//Saving active options.
88105
foreach ($options as $option) {
89106
$this->optionRepository->save($entity, $option);
90107
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,29 @@ public function __construct(
8787
$this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class);
8888
}
8989

90+
/**
91+
*
92+
* Clear the table we'll be writing de-normalized data into
93+
* to prevent archived data getting in the way of actual data.
94+
*
95+
* @return void
96+
*/
97+
private function clearCurrentTable()
98+
{
99+
$this->connection->delete(
100+
$this->activeTableSwitcher
101+
->getAdditionalTableName($this->getMainTable())
102+
);
103+
}
104+
90105
/**
91106
* Refresh entities index
92107
*
93108
* @return $this
94109
*/
95110
public function execute()
96111
{
112+
$this->clearCurrentTable();
97113
$this->reindex();
98114
$this->activeTableSwitcher->switchTable($this->connection, [$this->getMainTable()]);
99115
return $this;
@@ -103,6 +119,9 @@ public function execute()
103119
* Return select for remove unnecessary data
104120
*
105121
* @return \Magento\Framework\DB\Select
122+
*
123+
* @deprecated Not used anymore.
124+
* @see clearCurrentTable()
106125
*/
107126
protected function getSelectUnnecessaryData()
108127
{
@@ -127,12 +146,14 @@ protected function getSelectUnnecessaryData()
127146
* Remove unnecessary data
128147
*
129148
* @return void
149+
*
150+
* @deprecated Not used anymore.
151+
* @see clearCurrentTable()
130152
*/
131153
protected function removeUnnecessaryData()
132154
{
133-
$this->connection->query(
134-
$this->connection->deleteFromSelect($this->getSelectUnnecessaryData(), $this->getMainTable())
135-
);
155+
//Called for backward compatibility.
156+
$this->getSelectUnnecessaryData();
136157
}
137158

138159
/**
@@ -233,6 +254,7 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe
233254
)
234255
);
235256
$this->publishData();
257+
//Called for backward compatibility.
236258
$this->removeUnnecessaryData();
237259
}
238260
}

0 commit comments

Comments
 (0)