Skip to content

Commit ffd683c

Browse files
committed
MAGETWO-57569: [Backport] Functional upgrade test fail 2.1.x --> 2.2.x - 2.2
2 parents 9bc2a1c + 1e823a2 commit ffd683c

File tree

71 files changed

+2135
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2135
-350
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)
13171317

13181318
$select = $this->_connection->select()->from(
13191319
$entityTable,
1320-
$this->getNewSkuFieldsForSelect()
1320+
array_merge($this->getNewSkuFieldsForSelect(), $this->getOldSkuFieldsForSelect())
13211321
)->where(
13221322
'sku IN (?)',
13231323
array_keys($entityRowsIn)
@@ -1330,10 +1330,45 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)
13301330
$this->skuProcessor->setNewSkuData($sku, $key, $value);
13311331
}
13321332
}
1333+
1334+
$this->updateOldSku($newProducts);
13331335
}
1336+
13341337
return $this;
13351338
}
13361339

1340+
/**
1341+
* Return additional data, needed to select.
1342+
* @return array
1343+
*/
1344+
private function getOldSkuFieldsForSelect()
1345+
{
1346+
return ['type_id', 'attribute_set_id'];
1347+
}
1348+
1349+
/**
1350+
* Adds newly created products to _oldSku
1351+
* @param array $newProducts
1352+
* @return void
1353+
*/
1354+
private function updateOldSku(array $newProducts)
1355+
{
1356+
$oldSkus = [];
1357+
foreach ($newProducts as $info) {
1358+
$typeId = $info['type_id'];
1359+
$sku = $info['sku'];
1360+
$oldSkus[$sku] = [
1361+
'type_id' => $typeId,
1362+
'attr_set_id' => $info['attribute_set_id'],
1363+
$this->getProductIdentifierField() => $info[$this->getProductIdentifierField()],
1364+
'supported_type' => isset($this->_productTypeModels[$typeId]),
1365+
$this->getProductEntityLinkField() => $info[$this->getProductEntityLinkField()],
1366+
];
1367+
}
1368+
1369+
$this->_oldSku = array_replace($this->_oldSku, $oldSkus);
1370+
}
1371+
13371372
/**
13381373
* Get new SKU fields for select
13391374
*
@@ -1718,6 +1753,7 @@ protected function _saveProducts()
17181753
['adapter' => $this, 'bunch' => $bunch]
17191754
);
17201755
}
1756+
17211757
return $this;
17221758
}
17231759

@@ -2452,6 +2488,7 @@ protected function _saveValidatedBunches()
24522488
{
24532489
$source = $this->_getSource();
24542490
$source->rewind();
2491+
24552492
while ($source->valid()) {
24562493
try {
24572494
$rowData = $source->current();
@@ -2465,6 +2502,7 @@ protected function _saveValidatedBunches()
24652502
$rowData = $this->_customFieldsMapping($rowData);
24662503

24672504
$this->validateRow($rowData, $source->key());
2505+
24682506
$source->next();
24692507
}
24702508
$this->checkUrlKeyDuplicates();

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,13 @@ protected function getProductEntityLinkField()
567567
}
568568
return $this->productEntityLinkField;
569569
}
570+
571+
/**
572+
* Clean cached values
573+
*/
574+
public function __destruct()
575+
{
576+
self::$attributeCodeToId = [];
577+
self::$commonAttributesCache = [];
578+
}
570579
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Pricing\Render;
7+
8+
use Magento\Catalog\Pricing\Price\FinalPrice;
9+
use Magento\Catalog\Pricing\Price\RegularPrice;
10+
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
11+
use Magento\Framework\Pricing\Price\PriceInterface;
12+
use Magento\Framework\Pricing\Render\RendererPool;
13+
use Magento\Framework\Pricing\SaleableInterface;
14+
use Magento\Framework\View\Element\Template\Context;
15+
16+
class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
17+
{
18+
/**
19+
* @var ConfigurableOptionsProviderInterface
20+
*/
21+
private $configurableOptionsProvider;
22+
23+
/**
24+
* @param Context $context
25+
* @param SaleableInterface $saleableItem
26+
* @param PriceInterface $price
27+
* @param RendererPool $rendererPool
28+
* @param ConfigurableOptionsProviderInterface $configurableOptionsProvider
29+
* @param array $data
30+
*/
31+
public function __construct(
32+
Context $context,
33+
SaleableInterface $saleableItem,
34+
PriceInterface $price,
35+
RendererPool $rendererPool,
36+
ConfigurableOptionsProviderInterface $configurableOptionsProvider,
37+
array $data = []
38+
) {
39+
$this->configurableOptionsProvider = $configurableOptionsProvider;
40+
parent::__construct($context, $saleableItem, $price, $rendererPool, $data);
41+
}
42+
43+
/**
44+
* Define if the special price should be shown
45+
*
46+
* @return bool
47+
*/
48+
public function hasSpecialPrice()
49+
{
50+
$product = $this->getSaleableItem();
51+
foreach ($this->configurableOptionsProvider->getProducts($product) as $subProduct) {
52+
$regularPrice = $subProduct->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getValue();
53+
$finalPrice = $subProduct->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue();
54+
if ($finalPrice < $regularPrice) {
55+
return true;
56+
}
57+
}
58+
return false;
59+
}
60+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;
7+
8+
use Magento\Catalog\Pricing\Price\FinalPrice;
9+
use Magento\Catalog\Pricing\Price\RegularPrice;
10+
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
11+
use Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;
12+
13+
class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $context;
19+
20+
/**
21+
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $saleableItem;
24+
25+
/**
26+
* @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $price;
29+
30+
/**
31+
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $rendererPool;
34+
35+
/**
36+
* @var ConfigurableOptionsProviderInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $configurableOptionsProvider;
39+
40+
/**
41+
* @var FinalPriceBox
42+
*/
43+
private $model;
44+
45+
protected function setUp()
46+
{
47+
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
51+
$this->saleableItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
52+
->disableOriginalConstructor()
53+
->getMock();
54+
55+
$this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
56+
->getMockForAbstractClass();
57+
58+
$this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
62+
$this->configurableOptionsProvider = $this->getMockBuilder(ConfigurableOptionsProviderInterface::class)
63+
->getMockForAbstractClass();
64+
65+
$this->model = new FinalPriceBox(
66+
$this->context,
67+
$this->saleableItem,
68+
$this->price,
69+
$this->rendererPool,
70+
$this->configurableOptionsProvider
71+
);
72+
}
73+
74+
/**
75+
* @param float $regularPrice
76+
* @param float $finalPrice
77+
* @param bool $expected
78+
* @dataProvider hasSpecialPriceDataProvider
79+
*/
80+
public function testHasSpecialPrice(
81+
$regularPrice,
82+
$finalPrice,
83+
$expected
84+
) {
85+
$priceMockOne = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
86+
->getMockForAbstractClass();
87+
88+
$priceMockOne->expects($this->once())
89+
->method('getValue')
90+
->willReturn($regularPrice);
91+
92+
$priceMockTwo = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
93+
->getMockForAbstractClass();
94+
95+
$priceMockTwo->expects($this->once())
96+
->method('getValue')
97+
->willReturn($finalPrice);
98+
99+
$priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
103+
$priceInfoMock->expects($this->exactly(2))
104+
->method('getPrice')
105+
->willReturnMap([
106+
[RegularPrice::PRICE_CODE, $priceMockOne],
107+
[FinalPrice::PRICE_CODE, $priceMockTwo],
108+
]);
109+
110+
$productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
111+
->setMethods(['getPriceInfo'])
112+
->getMockForAbstractClass();
113+
114+
$productMock->expects($this->exactly(2))
115+
->method('getPriceInfo')
116+
->willReturn($priceInfoMock);
117+
118+
$this->configurableOptionsProvider->expects($this->once())
119+
->method('getProducts')
120+
->with($this->saleableItem)
121+
->willReturn([$productMock]);
122+
123+
$this->assertEquals($expected, $this->model->hasSpecialPrice());
124+
}
125+
126+
/**
127+
* @return array
128+
*/
129+
public function hasSpecialPriceDataProvider()
130+
{
131+
return [
132+
[10., 20., false],
133+
[10., 10., false],
134+
[20., 10., true],
135+
];
136+
}
137+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<referenceBlock name="render.product.prices">
10+
<arguments>
11+
<argument name="configurable" xsi:type="array">
12+
<item name="prices" xsi:type="array">
13+
<item name="final_price" xsi:type="array">
14+
<item name="render_class" xsi:type="string">Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox</item>
15+
<item name="render_template" xsi:type="string">Magento_ConfigurableProduct::product/price/final_price.phtml</item>
16+
</item>
17+
</item>
18+
</argument>
19+
</arguments>
20+
</referenceBlock>
21+
</layout>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
?>
10+
11+
<?php
12+
/** @var \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox$block */
13+
14+
/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
15+
$priceModel = $block->getPriceType('regular_price');
16+
17+
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
18+
$finalPriceModel = $block->getPriceType('final_price');
19+
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
20+
$schema = ($block->getZone() == 'item_view') ? true : false;
21+
?>
22+
<?php if ($block->hasSpecialPrice()): ?>
23+
<span class="special-price">
24+
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
25+
'display_label' => __('Special Price'),
26+
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
27+
'price_type' => 'finalPrice',
28+
'include_container' => true,
29+
'schema' => $schema
30+
]); ?>
31+
</span>
32+
<span class="old-price sly-old-price no-display">
33+
<?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
34+
'display_label' => __('Regular Price'),
35+
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
36+
'price_type' => 'oldPrice',
37+
'include_container' => true,
38+
'skip_adjustments' => true
39+
]); ?>
40+
</span>
41+
<?php else: ?>
42+
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
43+
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
44+
'price_type' => 'finalPrice',
45+
'include_container' => true,
46+
'schema' => $schema
47+
]); ?>
48+
<?php endif; ?>
49+
50+
<?php if ($block->showMinimalPrice()): ?>
51+
<?php if ($block->getUseLinkForAsLowAs()):?>
52+
<a href="<?php /* @escapeNotVerified */ echo $block->getSaleableItem()->getProductUrl(); ?>" class="minimal-price-link">
53+
<?php /* @escapeNotVerified */ echo $block->renderAmountMinimal(); ?>
54+
</a>
55+
<?php else:?>
56+
<span class="minimal-price-link">
57+
<?php /* @escapeNotVerified */ echo $block->renderAmountMinimal(); ?>
58+
</span>
59+
<?php endif?>
60+
<?php endif; ?>

0 commit comments

Comments
 (0)