Skip to content

Commit 93ecf99

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-fast-lane-prs
- merged with '2.4-develop-prs' branch
2 parents bd9a345 + db0f733 commit 93ecf99

File tree

10 files changed

+418
-194
lines changed

10 files changed

+418
-194
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ public function execute($id = null)
8585
$ids = [$id];
8686
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8787

88+
$storeIds = $this->getAssignedStoreIdsOfProduct($id);
89+
8890
$stores = $this->_storeManager->getStores();
8991
foreach ($stores as $store) {
9092
$tableExists = $this->_isFlatTableExists($store->getId());
9193
if ($tableExists) {
94+
if (!in_array($store->getId(), $storeIds)) {
95+
$this->flatItemEraser->deleteProductsFromStore($id, $store->getId());
96+
continue;
97+
}
9298
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
9399
$this->flatItemEraser->removeDisabledProducts($ids, $store->getId());
94100
}
@@ -129,4 +135,23 @@ public function execute($id = null)
129135

130136
return $this;
131137
}
138+
139+
/**
140+
* Get list store id where the product is enable
141+
*
142+
* @param int $productId
143+
* @return array
144+
*/
145+
private function getAssignedStoreIdsOfProduct($productId)
146+
{
147+
$select = $this->_connection->select();
148+
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
149+
->where('c.product_id = ' . $productId)
150+
->joinLeft(
151+
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
152+
'e.website_id = c.website_id',
153+
[]
154+
);
155+
return $this->_connection->fetchCol($select);
156+
}
132157
}

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/RowTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ public function testExecuteWithExistingFlatTablesCreatesTables()
160160
->willReturn('store_flat_table');
161161
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
162162
->willReturn(true);
163+
$this->connection->expects($this->any())->method('fetchCol')
164+
->willReturn(['store_id_1']);
163165
$this->flatItemEraser->expects($this->once())->method('removeDeletedProducts');
164166
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
165167
$this->model->execute('product_id_1');
166168
}
169+
170+
public function testExecuteWithExistingFlatTablesRemoveProductFromStore()
171+
{
172+
$this->productIndexerHelper->expects($this->any())->method('getFlatTableName')
173+
->willReturn('store_flat_table');
174+
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
175+
->willReturn(true);
176+
$this->connection->expects($this->any())->method('fetchCol')
177+
->willReturn([1]);
178+
$this->flatItemEraser->expects($this->once())->method('deleteProductsFromStore');
179+
$this->flatItemEraser->expects($this->never())->method('removeDeletedProducts');
180+
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
181+
$this->model->execute('product_id_1');
182+
}
167183
}

app/code/Magento/Quote/Model/Cart/CartTotalRepository.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Quote\Model\Cart;
710

811
use Magento\Quote\Api;
@@ -12,9 +15,11 @@
1215
use Magento\Framework\Api\ExtensibleDataInterface;
1316
use Magento\Quote\Model\Cart\Totals\ItemConverter;
1417
use Magento\Quote\Api\CouponManagementInterface;
18+
use Magento\Quote\Api\Data\TotalsInterface as QuoteTotalsInterface;
1519

1620
/**
1721
* Cart totals data object.
22+
*
1823
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1924
*/
2025
class CartTotalRepository implements CartTotalRepositoryInterface
@@ -79,11 +84,8 @@ public function __construct(
7984

8085
/**
8186
* @inheritdoc
82-
*
83-
* @param int $cartId The cart ID.
84-
* @return Totals Quote totals data.
8587
*/
86-
public function get($cartId)
88+
public function get($cartId): QuoteTotalsInterface
8789
{
8890
/** @var \Magento\Quote\Model\Quote $quote */
8991
$quote = $this->quoteRepository->getActive($cartId);
@@ -96,17 +98,14 @@ public function get($cartId)
9698
}
9799
unset($addressTotalsData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
98100

99-
/** @var \Magento\Quote\Api\Data\TotalsInterface $quoteTotals */
101+
/** @var QuoteTotalsInterface $quoteTotals */
100102
$quoteTotals = $this->totalsFactory->create();
101103
$this->dataObjectHelper->populateWithArray(
102104
$quoteTotals,
103105
$addressTotalsData,
104-
\Magento\Quote\Api\Data\TotalsInterface::class
106+
QuoteTotalsInterface::class
105107
);
106-
$items = [];
107-
foreach ($quote->getAllVisibleItems() as $index => $item) {
108-
$items[$index] = $this->itemConverter->modelToDataObject($item);
109-
}
108+
$items = array_map([$this->itemConverter, 'modelToDataObject'], $quote->getAllVisibleItems());
110109
$calculatedTotals = $this->totalsConverter->process($addressTotals);
111110
$quoteTotals->setTotalSegments($calculatedTotals);
112111

0 commit comments

Comments
 (0)