Skip to content

Commit f22a81b

Browse files
committed
BUG#AC-8227:Tax Class set to None when creating new configurable variations in multi store mode
1 parent d91d466 commit f22a81b

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
130130

131131
/**
132132
* @deprecated 103.0.2
133-
*
133+
* @see MAGETWO-71174
134134
* @var ImageContentInterfaceFactory
135135
*/
136136
protected $contentFactory;
137137

138138
/**
139139
* @deprecated 103.0.2
140-
*
140+
* @see MAGETWO-71174
141141
* @var ImageProcessorInterface
142142
*/
143143
protected $imageProcessor;
@@ -149,7 +149,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
149149

150150
/**
151151
* @deprecated 103.0.2
152-
*
152+
* @see MAGETWO-71174
153153
* @var \Magento\Catalog\Model\Product\Gallery\Processor
154154
*/
155155
protected $mediaGalleryProcessor;
@@ -322,6 +322,12 @@ public function getById($productId, $editMode = false, $storeId = null, $forceRe
322322
$product->setData('store_id', $storeId);
323323
}
324324
$product->load($productId);
325+
foreach ($product->getAttributes() as $attributeKey => $attributeValue) {
326+
$defaultValue = $attributeValue->getDefaultValue();
327+
if (!$product->hasData($attributeKey) && $defaultValue) {
328+
$product->setData($attributeKey, $defaultValue);
329+
}
330+
}
325331
if (!$product->getId()) {
326332
throw new NoSuchEntityException(
327333
__("The product that was requested doesn't exist. Verify the product and try again.")
@@ -736,6 +742,7 @@ private function addExtensionAttributes(Collection $collection) : Collection
736742
* Helper function that adds a FilterGroup to the collection.
737743
*
738744
* @deprecated 102.0.0
745+
* @see MAGETWO-71174
739746
* @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
740747
* @param Collection $collection
741748
* @return void
@@ -795,6 +802,7 @@ private function getMediaGalleryProcessor()
795802
* Retrieve collection processor
796803
*
797804
* @deprecated 102.0.0
805+
* @see MAGETWO-71174
798806
* @return CollectionProcessorInterface
799807
*/
800808
private function getCollectionProcessor()

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ protected function fillSimpleProductData(
200200
continue;
201201
}
202202

203-
$product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode()));
203+
$product->setData(
204+
$attribute->getAttributeCode(),
205+
$parentProduct->getData($attribute->getAttributeCode()) ?? $attribute->getDefaultValue()
206+
);
204207
}
205-
206208
$keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id'];
207209
$postData['stock_data'] = array_diff_key((array)$parentProduct->getStockData(), array_flip($keysFilter));
208210
$stockStatus = $parentProduct->getQuantityAndStockStatus();
@@ -212,9 +214,6 @@ protected function fillSimpleProductData(
212214

213215
$postData = $this->processMediaGallery($product, $postData);
214216
$postData['status'] = $postData['status'] ?? Status::STATUS_ENABLED;
215-
$defaultTaxClassId = isset($this->attributes['tax_class_id']) ?
216-
$this->attributes['tax_class_id']->getDefaultValue() : null;
217-
$postData['tax_class_id'] = $postData['tax_class_id'] ?? $parentProduct->getTaxClassId() ?? $defaultTaxClassId;
218217
$product->addData(
219218
$postData
220219
)->setWebsiteIds(

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function testGenerateSimpleProducts(array $productsData): void
7373
->setSmallImage('some_test_image.jpg')
7474
->setThumbnail('some_test_image.jpg')
7575
->setSwatchImage('some_test_image.jpg')
76-
->setTaxClassId(2)
7776
->setNewVariationsAttributeSetId($this->product->getDefaultAttributeSetId());
7877
$generatedProducts = $this->variationHandler->generateSimpleProducts($this->product, $productsData);
7978
$this->assertCount(3, $generatedProducts);
@@ -89,7 +88,6 @@ public function testGenerateSimpleProducts(array $productsData): void
8988
$this->assertNull($product->getSmallImage());
9089
$this->assertNull($product->getThumbnail());
9190
$this->assertNull($product->getSwatchImage());
92-
$this->assertEquals(2, $product->getTaxClassId());
9391
}
9492
}
9593

@@ -111,6 +109,20 @@ public function testGenerateSimpleProductsWithPartialData(array $productsData):
111109
}
112110
}
113111

112+
/**
113+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
114+
* @dataProvider generateSimpleProductsWithPartialDataDataProvider
115+
* @param array $productsData
116+
* @return void
117+
*/
118+
public function testGeneratedSimpleProductInheritTaxClassFromParent(array $productsData): void
119+
{
120+
$this->product->setTaxClassId(2);
121+
$generatedProduct = $this->variationHandler->generateSimpleProducts($this->product, $productsData);
122+
$product = $this->productRepository->getById(reset($generatedProduct));
123+
$this->assertEquals(2, $product->getTaxClassId());
124+
}
125+
114126
/**
115127
* @return array
116128
*/

0 commit comments

Comments
 (0)