Skip to content

Commit eb52e26

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into MAGETWO-73411
2 parents bbd9626 + 0a2da15 commit eb52e26

File tree

21 files changed

+812
-174
lines changed

21 files changed

+812
-174
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
}

app/code/Magento/Sales/Model/Order/Shipment.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ public function register()
262262
if (!$item->getOrderItem()->isDummy(true)) {
263263
$totalQty += $item->getQty();
264264
}
265-
} else {
266-
$item->isDeleted(true);
267265
}
268266
}
269267

app/code/Magento/Sales/Model/Order/Shipment/OrderRegistrar.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ class OrderRegistrar implements \Magento\Sales\Model\Order\Shipment\OrderRegistr
1717
*/
1818
public function register(OrderInterface $order, ShipmentInterface $shipment)
1919
{
20-
/** @var \Magento\Sales\Api\Data\ShipmentItemInterface|\Magento\Sales\Model\Order\Shipment\Item $item */
20+
$totalQty = 0;
21+
/** @var \Magento\Sales\Model\Order\Shipment\Item $item */
2122
foreach ($shipment->getItems() as $item) {
2223
if ($item->getQty() > 0) {
2324
$item->register();
25+
26+
if (!$item->getOrderItem()->isDummy(true)) {
27+
$totalQty += $item->getQty();
28+
}
2429
}
2530
}
31+
$shipment->setTotalQty($totalQty);
32+
2633
return $order;
2734
}
2835
}

app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Sales\Api\Data\OrderInterface;
1515
use Magento\Sales\Api\Data\ShipmentCommentCreationInterface;
1616
use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface;
17+
use Magento\Sales\Api\Data\OrderItemInterface;
1718

1819
/**
1920
* Class ShipmentDocumentFactory
@@ -77,13 +78,23 @@ public function create(
7778
array $packages = [],
7879
ShipmentCreationArgumentsInterface $arguments = null
7980
) {
80-
$shipmentItems = $this->itemsToArray($items);
81+
$shipmentItems = empty($items)
82+
? $this->getQuantitiesFromOrderItems($order->getItems())
83+
: $this->getQuantitiesFromShipmentItems($items);
84+
8185
/** @var Shipment $shipment */
8286
$shipment = $this->shipmentFactory->create(
8387
$order,
8488
$shipmentItems
8589
);
86-
$this->prepareTracks($shipment, $tracks);
90+
91+
foreach ($tracks as $track) {
92+
$hydrator = $this->hydratorPool->getHydrator(
93+
\Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class
94+
);
95+
$shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)]));
96+
}
97+
8798
if ($comment) {
8899
$shipment->addComment(
89100
$comment->getComment(),
@@ -101,30 +112,29 @@ public function create(
101112
}
102113

103114
/**
104-
* Adds tracks to the shipment.
115+
* Translate OrderItemInterface array to product id => product quantity array.
105116
*
106-
* @param ShipmentInterface $shipment
107-
* @param ShipmentTrackCreationInterface[] $tracks
108-
* @return ShipmentInterface
117+
* @param OrderItemInterface[] $items
118+
* @return int[]
109119
*/
110-
private function prepareTracks(\Magento\Sales\Api\Data\ShipmentInterface $shipment, array $tracks)
120+
private function getQuantitiesFromOrderItems(array $items)
111121
{
112-
foreach ($tracks as $track) {
113-
$hydrator = $this->hydratorPool->getHydrator(
114-
\Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class
115-
);
116-
$shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)]));
122+
$shipmentItems = [];
123+
foreach ($items as $item) {
124+
if (!$item->getIsVirtual() && (!$item->getParentItem() || $item->isShipSeparately())) {
125+
$shipmentItems[$item->getItemId()] = $item->getQtyOrdered();
126+
}
117127
}
118-
return $shipment;
128+
return $shipmentItems;
119129
}
120130

121131
/**
122-
* Convert items to array
132+
* Translate ShipmentItemCreationInterface array to product id => product quantity array.
123133
*
124134
* @param ShipmentItemCreationInterface[] $items
125-
* @return array
135+
* @return int[]
126136
*/
127-
private function itemsToArray(array $items = [])
137+
private function getQuantitiesFromShipmentItems(array $items)
128138
{
129139
$shipmentItems = [];
130140
foreach ($items as $item) {

0 commit comments

Comments
 (0)