Skip to content

Commit 4d9d6b0

Browse files
Merge pull request #1437 from magento-jackalopes/pr-aug25
[jackalopes] MAGETWO-71551: Inconsistent quote information after upgrade on 2.2
2 parents 59a6784 + 947b583 commit 4d9d6b0

File tree

11 files changed

+122
-80
lines changed

11 files changed

+122
-80
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
153153
/**
154154
* Items per page for collection limitation
155155
*
156-
* @var null
156+
* @var int|null
157157
*/
158158
protected $_itemsPerPage = null;
159159

160160
/**
161161
* Header columns for export file
162162
*
163163
* @var array
164+
* @deprecated
164165
*/
165166
protected $_headerColumns = [];
166167

@@ -234,17 +235,15 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
234235
protected $_fieldsMap = [
235236
'image' => 'base_image',
236237
'image_label' => "base_image_label",
237-
'image' => 'base_image',
238-
'image_label' => 'base_image_label',
239238
'thumbnail' => 'thumbnail_image',
240239
'thumbnail_label' => 'thumbnail_image_label',
241240
self::COL_MEDIA_IMAGE => 'additional_images',
242241
'_media_image_label' => 'additional_image_labels',
243-
Product::COL_STORE => 'store_view_code',
244-
Product::COL_ATTR_SET => 'attribute_set_code',
245-
Product::COL_TYPE => 'product_type',
246-
Product::COL_CATEGORY => 'categories',
247-
Product::COL_PRODUCT_WEBSITES => 'product_websites',
242+
self::COL_STORE => 'store_view_code',
243+
self::COL_ATTR_SET => 'attribute_set_code',
244+
self::COL_TYPE => 'product_type',
245+
self::COL_CATEGORY => 'categories',
246+
self::COL_PRODUCT_WEBSITES => 'product_websites',
248247
'status' => 'product_online',
249248
'news_from_date' => 'new_from_date',
250249
'news_to_date' => 'new_to_date',
@@ -691,7 +690,7 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
691690
*/
692691
public function _getHeaderColumns()
693692
{
694-
return $this->_customHeadersMapping($this->_headerColumns);
693+
return $this->_customHeadersMapping($this->rowCustomizer->addHeaderColumns($this->_headerColumns));
695694
}
696695

697696
/**
@@ -700,13 +699,13 @@ public function _getHeaderColumns()
700699
* @param array $customOptionsData
701700
* @param array $stockItemRows
702701
* @return void
702+
* @deprecated Logic will be moved to _getHeaderColumns in future release
703+
*
704+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
703705
*/
704706
protected function setHeaderColumns($customOptionsData, $stockItemRows)
705707
{
706708
if (!$this->_headerColumns) {
707-
$customOptCols = [
708-
'custom_options',
709-
];
710709
$this->_headerColumns = array_merge(
711710
[
712711
self::COL_SKU,
@@ -719,21 +718,19 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
719718
$this->_getExportMainAttrCodes(),
720719
[self::COL_ADDITIONAL_ATTRIBUTES],
721720
reset($stockItemRows) ? array_keys(end($stockItemRows)) : [],
722-
[],
723721
[
724722
'related_skus',
725723
'related_position',
726724
'crosssell_skus',
727725
'crosssell_position',
728726
'upsell_skus',
729-
'upsell_position'
730-
],
731-
['additional_images', 'additional_image_labels', 'hide_from_product_page']
727+
'upsell_position',
728+
'additional_images',
729+
'additional_image_labels',
730+
'hide_from_product_page',
731+
'custom_options'
732+
]
732733
);
733-
// have we merge custom options columns
734-
if ($customOptionsData) {
735-
$this->_headerColumns = array_merge($this->_headerColumns, $customOptCols);
736-
}
737734
}
738735
}
739736

@@ -892,10 +889,12 @@ protected function getExportData()
892889
$productIds = array_keys($rawData);
893890
$stockItemRows = $this->prepareCatalogInventory($productIds);
894891

895-
$this->rowCustomizer->prepareData($this->_getEntityCollection(), $productIds);
892+
$this->rowCustomizer->prepareData(
893+
$this->_prepareEntityCollection($this->_entityCollectionFactory->create()),
894+
$productIds
895+
);
896896

897897
$this->setHeaderColumns($multirawData['customOptionsData'], $stockItemRows);
898-
$this->_headerColumns = $this->rowCustomizer->addHeaderColumns($this->_headerColumns);
899898

900899
foreach ($rawData as $productId => $productData) {
901900
foreach ($productData as $storeId => $dataRow) {
@@ -1231,9 +1230,6 @@ private function appendMultirowData(&$dataRow, &$multiRawData)
12311230
return null;
12321231
} elseif ($storeId != Store::DEFAULT_STORE_ID) {
12331232
$dataRow[self::COL_STORE] = $this->_storeIdToCode[$storeId];
1234-
if (isset($productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY])) {
1235-
$dataRow[self::COL_VISIBILITY] = $productData[Store::DEFAULT_STORE_ID][self::COL_VISIBILITY];
1236-
}
12371233
}
12381234
$dataRow[self::COL_SKU] = $sku;
12391235
return $dataRow;

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,15 @@ public function testGetHeaderColumns()
270270
$headerColumnsValue = ['headerColumns value'];
271271
$expectedResult = 'result';
272272
$this->setPropertyValue($product, '_headerColumns', $headerColumnsValue);
273-
$product
274-
->expects($this->once())
273+
$this->setPropertyValue($product, 'rowCustomizer', $this->rowCustomizer);
274+
$product->expects($this->once())
275275
->method('_customHeadersMapping')
276276
->with($headerColumnsValue)
277277
->willReturn($expectedResult);
278+
$this->rowCustomizer->expects($this->once())
279+
->method('addHeaderColumns')
280+
->with($headerColumnsValue)
281+
->willReturn($headerColumnsValue);
278282

279283
$result = $product->_getHeaderColumns();
280284

app/code/Magento/ConfigurableImportExport/Model/Export/RowCustomizer.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,29 @@
1313

1414
class RowCustomizer implements RowCustomizerInterface
1515
{
16+
/**
17+
* Header column for Configurable Product variations
18+
*/
19+
const CONFIGURABLE_VARIATIONS_COLUMN = 'configurable_variations';
20+
21+
/**
22+
* Header column for Configurable Product variation labels
23+
*/
24+
const CONFIGURABLE_VARIATIONS_LABELS_COLUMN = 'configurable_variation_labels';
25+
1626
/**
1727
* @var array
1828
*/
1929
protected $configurableData = [];
2030

31+
/**
32+
* @var string[]
33+
*/
34+
private $configurableColumns = [
35+
self::CONFIGURABLE_VARIATIONS_COLUMN,
36+
self::CONFIGURABLE_VARIATIONS_LABELS_COLUMN
37+
];
38+
2139
/**
2240
* Prepare configurable data for export
2341
*
@@ -54,8 +72,11 @@ public function prepareData($collection, $productIds)
5472
}
5573

5674
$this->configurableData[$product->getId()] = [
57-
'configurable_variations' => implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations),
58-
'configurable_variation_labels' => implode(
75+
self::CONFIGURABLE_VARIATIONS_COLUMN => implode(
76+
ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR,
77+
$variations
78+
),
79+
self::CONFIGURABLE_VARIATIONS_LABELS_COLUMN => implode(
5980
Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
6081
$variationsLabels
6182
)
@@ -71,17 +92,7 @@ public function prepareData($collection, $productIds)
7192
*/
7293
public function addHeaderColumns($columns)
7394
{
74-
// have we merge configurable products data
75-
if (!empty($this->configurableData)) {
76-
$columns = array_merge(
77-
$columns,
78-
[
79-
'configurable_variations',
80-
'configurable_variation_labels',
81-
]
82-
);
83-
}
84-
return $columns;
95+
return array_merge($columns, $this->configurableColumns);
8596
}
8697

8798
/**

app/code/Magento/Quote/Setup/UpgradeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
*/
4141
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4242
{
43-
if (version_compare($context->getVersion(), '2.0.4', '<')) {
43+
if (version_compare($context->getVersion(), '2.0.6', '<')) {
4444
$quoteSetup = $this->quoteSetupFactory->create(['setup' => $setup]);
4545
$this->convertSerializedDataToJsonFactory->create(['quoteSetup' => $quoteSetup])
4646
->convert();

app/code/Magento/Shipping/view/frontend/layout/shipping_tracking_popup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceContainer name="content">
11-
<block class="Magento\Shipping\Block\Tracking\Popup" name="shipping.tracking.popup" template="Magento_Shipping::tracking/popup.phtml"/>
11+
<block class="Magento\Shipping\Block\Tracking\Popup" name="shipping.tracking.popup" template="Magento_Shipping::tracking/popup.phtml" cacheable="false" />
1212
</referenceContainer>
1313
</body>
1414
</page>

app/code/Magento/Shipping/view/frontend/templates/tracking/popup.phtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ $results = $block->getTrackingInfo();
2222
<?php foreach ($result as $counter => $track): ?>
2323
<div class="table-wrapper">
2424
<?php
25-
$block->addChild('shipping.tracking.details.' . $counter, Template::class, [
25+
$shipmentBlockIdentifier = $shipId . '.' . $counter;
26+
$block->addChild('shipping.tracking.details.' . $shipmentBlockIdentifier, Template::class, [
2627
'track' => $track,
2728
'template' => 'Magento_Shipping::tracking/details.phtml',
2829
'storeSupportEmail' => $block->getStoreSupportEmail()
2930
]
3031
);
3132
?>
32-
<?= /* @noEscape */ $block->getChildHtml('shipping.tracking.details.' . $counter) ?>
33+
<?= /* @noEscape */ $block->getChildHtml('shipping.tracking.details.' . $shipmentBlockIdentifier) ?>
3334
</div>
3435
<?php if (is_object($track) && !empty($track->getProgressdetail())): ?>
3536
<?php
36-
$block->addChild('shipping.tracking.progress.' . $counter, Template::class, [
37+
$block->addChild('shipping.tracking.progress.' . $shipmentBlockIdentifier, Template::class, [
3738
'track' => $track,
3839
'template' => 'Magento_Shipping::tracking/progress.phtml'
3940
]);
4041
?>
41-
<?= /* @noEscape */ $block->getChildHtml('shipping.tracking.progress.' . $counter) ?>
42+
<?= /* @noEscape */ $block->getChildHtml('shipping.tracking.progress.' . $shipmentBlockIdentifier) ?>
4243
<?php endif; ?>
4344
<?php endforeach; ?>
4445
<?php else: ?>

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/AbstractProductExportImportTestCase.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CatalogImportExport\Model;
77

88
use Magento\Framework\App\Bootstrap;
9-
use Magento\Framework\App\Config;
109
use Magento\Framework\App\Filesystem\DirectoryList;
1110

1211
/**
@@ -16,11 +15,6 @@
1615
*/
1716
abstract class AbstractProductExportImportTestCase extends \PHPUnit\Framework\TestCase
1817
{
19-
/**
20-
* @var \Magento\CatalogImportExport\Model\Export\Product
21-
*/
22-
protected $model;
23-
2418
/**
2519
* @var \Magento\Framework\ObjectManagerInterface
2620
*/
@@ -61,8 +55,6 @@ abstract class AbstractProductExportImportTestCase extends \PHPUnit\Framework\Te
6155

6256
protected function setUp()
6357
{
64-
parent::setUp();
65-
6658
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
6759
$this->fileSystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
6860
$this->productResource = $this->objectManager->create(
@@ -262,9 +254,33 @@ public function testImportReplace($fixtures, $skus, $skippedAttributes = [])
262254
}
263255

264256
/**
257+
* @magentoAppArea adminhtml
258+
* @magentoDbIsolation enabled
259+
* @magentoAppIsolation enabled
260+
*
261+
* @param array $fixtures
262+
* @param string[] $skus
263+
* @param string[] $skippedAttributes
264+
* @dataProvider importReplaceDataProvider
265+
*/
266+
public function testImportReplaceWithPagination($fixtures, $skus, $skippedAttributes = [])
267+
{
268+
$this->fixtures = $fixtures;
269+
$this->executeFixtures($fixtures, $skus);
270+
$this->modifyData($skus);
271+
$skippedAttributes = array_merge(self::$skippedAttributes, $skippedAttributes);
272+
$this->executeImportReplaceTest($skus, $skippedAttributes, true);
273+
}
274+
275+
/**
276+
* @param string[] $skus
277+
* @param string[] $skippedAttributes
278+
* @param bool $usePagination
279+
*
265280
* @SuppressWarnings(PHPMD.NPathComplexity)
281+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
266282
*/
267-
protected function executeImportReplaceTest($skus, $skippedAttributes)
283+
protected function executeImportReplaceTest($skus, $skippedAttributes, $usePagination = false)
268284
{
269285
$replacedAttributes = [
270286
'row_id',
@@ -285,7 +301,18 @@ protected function executeImportReplaceTest($skus, $skippedAttributes)
285301
$index++;
286302
}
287303

288-
$csvfile = $this->exportProducts();
304+
$exportProduct = $this->objectManager->create(\Magento\CatalogImportExport\Model\Export\Product::class);
305+
if ($usePagination) {
306+
/** @var \ReflectionProperty $itemsPerPageProperty */
307+
$itemsPerPageProperty = $this->objectManager->create(\ReflectionProperty::class, [
308+
'class' => \Magento\CatalogImportExport\Model\Export\Product::class,
309+
'name' => '_itemsPerPage'
310+
]);
311+
$itemsPerPageProperty->setAccessible(true);
312+
$itemsPerPageProperty->setValue($exportProduct, 1);
313+
}
314+
315+
$csvfile = $this->exportProducts($exportProduct);
289316
$this->importProducts($csvfile, \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE);
290317

291318
while ($index > 0) {
@@ -326,13 +353,16 @@ protected function executeImportReplaceTest($skus, $skippedAttributes)
326353
/**
327354
* Export products in the system
328355
*
356+
* @param \Magento\CatalogImportExport\Model\Export\Product|null $exportProduct
329357
* @return string Return exported file name
330358
*/
331-
private function exportProducts()
359+
private function exportProducts(\Magento\CatalogImportExport\Model\Export\Product $exportProduct = null)
332360
{
333361
$csvfile = uniqid('importexport_') . '.csv';
334362

335-
$exportProduct = $this->objectManager->create(\Magento\CatalogImportExport\Model\Export\Product::class);
363+
$exportProduct = $exportProduct ?: $this->objectManager->create(
364+
\Magento\CatalogImportExport\Model\Export\Product::class
365+
);
336366
$exportProduct->setWriter(
337367
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
338368
\Magento\ImportExport\Model\Export\Adapter\Csv::class,

dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
8080
)->setWebsiteIds(
8181
[1]
82-
)->setCateroryIds(
83-
[]
8482
)->setStockData(
8583
['qty' => 100, 'is_in_stock' => 1]
8684
)->setCanSaveCustomOptions(

dev/tests/integration/testsuite/Magento/ConfigurableImportExport/Model/ConfigurableTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function exportImportDataProvider()
3939
*/
4040
protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
4141
{
42-
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $prooductType */
43-
$prooductType = $expectedProduct->getTypeInstance();
44-
$expectedAssociatedProducts = $prooductType->getUsedProductCollection($expectedProduct);
45-
$actualAssociatedProducts = iterator_to_array($prooductType->getUsedProductCollection($actualProduct));
42+
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productType */
43+
$productType = $expectedProduct->getTypeInstance();
44+
$expectedAssociatedProducts = $productType->getUsedProductCollection($expectedProduct);
45+
$actualAssociatedProducts = iterator_to_array($productType->getUsedProductCollection($actualProduct));
4646

4747
$expectedAssociatedProductSkus = [];
4848
$actualAssociatedProductSkus = [];
@@ -103,19 +103,4 @@ public function importReplaceDataProvider()
103103
}
104104
return $data;
105105
}
106-
107-
/**
108-
* @magentoAppArea adminhtml
109-
* @magentoDbIsolation enabled
110-
* @magentoAppIsolation enabled
111-
*
112-
* @param array $fixtures
113-
* @param string[] $skus
114-
* @param string[] $skippedAttributes
115-
* @dataProvider importReplaceDataProvider
116-
*/
117-
public function testImportReplace($fixtures, $skus, $skippedAttributes = [])
118-
{
119-
parent::testImportReplace($fixtures, $skus, $skippedAttributes);
120-
}
121106
}

0 commit comments

Comments
 (0)