Skip to content

Commit 424a131

Browse files
committed
MC-36835: [Cloud] Adding new disabled products to Magento flushes categories cache
1 parent 14db4ad commit 424a131

File tree

2 files changed

+64
-36
lines changed

2 files changed

+64
-36
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ public function priceReindexCallback()
10341034
*/
10351035
public function eavReindexCallback()
10361036
{
1037-
if ($this->isObjectNew() || $this->isDataChanged($this)) {
1037+
if ($this->isObjectNew() || $this->isDataChanged()) {
10381038
$this->_productEavIndexerProcessor->reindexRow($this->getEntityId());
10391039
}
10401040
}
@@ -1180,7 +1180,7 @@ public function getTierPrice($qty = null)
11801180
/**
11811181
* Get formatted by currency product price
11821182
*
1183-
* @return array|double
1183+
* @return array|double
11841184
* @since 102.0.6
11851185
*/
11861186
public function getFormattedPrice()

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,7 @@ protected function setUp(): void
313313

314314
$contextMock = $this->createPartialMock(
315315
Context::class,
316-
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'],
317-
[],
318-
'',
319-
false
316+
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator']
320317
);
321318
$contextMock->expects($this->any())->method('getAppState')->willReturn($this->appStateMock);
322319
$contextMock->expects($this->any())
@@ -541,7 +538,7 @@ public function testGetStoreSingleSiteModelIds(
541538
/**
542539
* @return array
543540
*/
544-
public function getSingleStoreIds()
541+
public function getSingleStoreIds(): array
545542
{
546543
return [
547544
[
@@ -619,15 +616,15 @@ public function testGetCategoryCollectionCollectionNull($initCategoryCollection,
619616

620617
$result = $product->getCategoryCollection();
621618

622-
$productIdCachedActual = $this->getPropertyValue($product, '_productIdCached', $productIdCached);
619+
$productIdCachedActual = $this->getPropertyValue($product, '_productIdCached');
623620
$this->assertEquals($getIdResult, $productIdCachedActual);
624621
$this->assertEquals($initCategoryCollection, $result);
625622
}
626623

627624
/**
628625
* @return array
629626
*/
630-
public function getCategoryCollectionCollectionNullDataProvider()
627+
public function getCategoryCollectionCollectionNullDataProvider(): array
631628
{
632629
return [
633630
[
@@ -742,7 +739,7 @@ public function testReindex($productChanged, $isScheduled, $productFlatCount, $c
742739
/**
743740
* @return array
744741
*/
745-
public function getProductReindexProvider()
742+
public function getProductReindexProvider(): array
746743
{
747744
return [
748745
'set 1' => [true, false, 1, 1],
@@ -774,12 +771,18 @@ public function testPriceReindexCallback()
774771
/**
775772
* @dataProvider getIdentitiesProvider
776773
* @param array $expected
777-
* @param array $origData
774+
* @param array|null $origData
778775
* @param array $data
779776
* @param bool $isDeleted
780-
*/
781-
public function testGetIdentities($expected, $origData, $data, $isDeleted = false)
782-
{
777+
* @param bool $isNew
778+
*/
779+
public function testGetIdentities(
780+
array $expected,
781+
?array $origData,
782+
array $data,
783+
bool $isDeleted = false,
784+
bool $isNew = false
785+
) {
783786
$this->model->setIdFieldName('id');
784787
if (is_array($origData)) {
785788
foreach ($origData as $key => $value) {
@@ -790,13 +793,14 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
790793
$this->model->setData($key, $value);
791794
}
792795
$this->model->isDeleted($isDeleted);
796+
$this->model->isObjectNew($isNew);
793797
$this->assertEquals($expected, $this->model->getIdentities());
794798
}
795799

796800
/**
797801
* @return array
798802
*/
799-
public function getIdentitiesProvider()
803+
public function getIdentitiesProvider(): array
800804
{
801805
$extensionAttributesMock = $this->getMockBuilder(ExtensionAttributesInterface::class)
802806
->disableOriginalConstructor()
@@ -814,60 +818,61 @@ public function getIdentitiesProvider()
814818
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
815819
],
816820
'new product' => $this->getNewProductProviderData(),
821+
'new disabled product' => $this->getNewDisabledProductProviderData(),
817822
'status and category change' => [
818823
[0 => 'cat_p_1', 1 => 'cat_c_p_1', 2 => 'cat_c_p_2'],
819-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
824+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_DISABLED],
820825
[
821826
'id' => 1,
822827
'name' => 'value',
823828
'category_ids' => [2],
824-
'status' => 1,
829+
'status' => Status::STATUS_ENABLED,
825830
'affected_category_ids' => [1, 2],
826831
'is_changed_categories' => true
827832
],
828833
],
829834
'status change only' => [
830835
[0 => 'cat_p_1', 1 => 'cat_c_p_7'],
831-
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 1],
832-
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 2],
836+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => Status::STATUS_ENABLED],
837+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => Status::STATUS_DISABLED],
833838
],
834839
'status changed, category unassigned' => $this->getStatusAndCategoryChangesData(),
835840
'no status changes' => [
836841
[0 => 'cat_p_1'],
837-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
838-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
842+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
843+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
839844
],
840845
'no stock status changes' => [
841846
[0 => 'cat_p_1'],
842-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
847+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
843848
[
844849
'id' => 1,
845850
'name' => 'value',
846851
'category_ids' => [1],
847-
'status' => 1,
852+
'status' => Status::STATUS_ENABLED,
848853
'stock_data' => ['is_in_stock' => true],
849854
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
850855
],
851856
],
852857
'no stock status data 1' => [
853858
[0 => 'cat_p_1'],
854-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
859+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
855860
[
856861
'id' => 1,
857862
'name' => 'value',
858863
'category_ids' => [1],
859-
'status' => 1,
864+
'status' => Status::STATUS_ENABLED,
860865
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
861866
],
862867
],
863868
'no stock status data 2' => [
864869
[0 => 'cat_p_1'],
865-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
870+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
866871
[
867872
'id' => 1,
868873
'name' => 'value',
869874
'category_ids' => [1],
870-
'status' => 1,
875+
'status' => Status::STATUS_ENABLED,
871876
'stock_data' => ['is_in_stock' => true],
872877
],
873878
],
@@ -878,16 +883,16 @@ public function getIdentitiesProvider()
878883
/**
879884
* @return array
880885
*/
881-
private function getStatusAndCategoryChangesData()
886+
private function getStatusAndCategoryChangesData(): array
882887
{
883888
return [
884889
[0 => 'cat_p_1', 1 => 'cat_c_p_5'],
885-
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => 2],
890+
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => Status::STATUS_DISABLED],
886891
[
887892
'id' => 1,
888893
'name' => 'value',
889894
'category_ids' => [],
890-
'status' => 1,
895+
'status' => Status::STATUS_ENABLED,
891896
'is_changed_categories' => true,
892897
'affected_category_ids' => [5]
893898
],
@@ -897,7 +902,7 @@ private function getStatusAndCategoryChangesData()
897902
/**
898903
* @return array
899904
*/
900-
private function getNewProductProviderData()
905+
private function getNewProductProviderData(): array
901906
{
902907
return [
903908
['cat_p_1', 'cat_c_p_1'],
@@ -908,24 +913,47 @@ private function getNewProductProviderData()
908913
'category_ids' => [1],
909914
'affected_category_ids' => [1],
910915
'is_changed_categories' => true
911-
]
916+
],
917+
false,
918+
true,
919+
];
920+
}
921+
922+
/**
923+
* @return array
924+
*/
925+
private function getNewDisabledProductProviderData(): array
926+
{
927+
return [
928+
['cat_p_1'],
929+
null,
930+
[
931+
'id' => 1,
932+
'name' => 'value',
933+
'category_ids' => [1],
934+
'status' => Status::STATUS_DISABLED,
935+
'affected_category_ids' => [1],
936+
'is_changed_categories' => true
937+
],
938+
false,
939+
true,
912940
];
913941
}
914942

915943
/**
916944
* @param MockObject $extensionAttributesMock
917945
* @return array
918946
*/
919-
private function getStatusStockProviderData($extensionAttributesMock)
947+
private function getStatusStockProviderData($extensionAttributesMock): array
920948
{
921949
return [
922950
[0 => 'cat_p_1', 1 => 'cat_c_p_1'],
923-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
951+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => Status::STATUS_ENABLED],
924952
[
925953
'id' => 1,
926954
'name' => 'value',
927955
'category_ids' => [1],
928-
'status' => 1,
956+
'status' => Status::STATUS_ENABLED,
929957
'stock_data' => ['is_in_stock' => false],
930958
ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributesMock,
931959
],
@@ -1440,7 +1468,7 @@ public function testGetCustomAttributes()
14401468
/**
14411469
* @return array
14421470
*/
1443-
public function priceDataProvider()
1471+
public function priceDataProvider(): array
14441472
{
14451473
return [
14461474
'receive empty array' => [[]],

0 commit comments

Comments
 (0)