Skip to content

Commit 620abb4

Browse files
author
Oleksandr Dubovyk
committed
MC-30255: In Stock Alert Email Shows Incorrect Item Pricing
- fixed - modified tests - remove redundant ImageProvider
1 parent 189dc56 commit 620abb4

File tree

6 files changed

+11
-199
lines changed

6 files changed

+11
-199
lines changed

app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
namespace Magento\ProductAlert\Block\Email;
77

88
use Magento\Framework\Pricing\PriceCurrencyInterface;
9-
use Magento\Framework\App\ObjectManager;
10-
use Magento\ProductAlert\Block\Product\ImageProvider;
119

1210
/**
1311
* Product Alert Abstract Email Block
@@ -43,32 +41,23 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
4341
*/
4442
protected $imageBuilder;
4543

46-
/**
47-
* @var ImageProvider
48-
*/
49-
private $imageProvider;
50-
5144
/**
5245
* @param \Magento\Framework\View\Element\Template\Context $context
5346
* @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
5447
* @param PriceCurrencyInterface $priceCurrency
5548
* @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
5649
* @param array $data
57-
* @param ImageProvider $imageProvider
5850
*/
5951
public function __construct(
6052
\Magento\Framework\View\Element\Template\Context $context,
6153
\Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
6254
PriceCurrencyInterface $priceCurrency,
6355
\Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
64-
array $data = [],
65-
ImageProvider $imageProvider = null
56+
array $data = []
6657
) {
6758
$this->imageBuilder = $imageBuilder;
6859
$this->priceCurrency = $priceCurrency;
6960
$this->_maliciousCode = $maliciousCode;
70-
$this->imageProvider = $imageProvider ?: ObjectManager::getInstance()->get(ImageProvider::class);
71-
7261
parent::__construct($context, $data);
7362
}
7463

@@ -227,6 +216,6 @@ public function getProductPriceHtml(
227216
*/
228217
public function getImage($product, $imageId, $attributes = [])
229218
{
230-
return $this->imageProvider->getImage($product, $imageId, $attributes);
219+
return $this->imageBuilder->create($product, $imageId, $attributes);
231220
}
232221
}

app/code/Magento/ProductAlert/Block/Product/ImageProvider.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

app/code/Magento/ProductAlert/Model/Observer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ protected function _processPrice(\Magento\ProductAlert\Model\Email $email)
242242
);
243243

244244
$product->setCustomerGroupId($customer->getGroupId());
245+
$this->_storeManager->getStore()->setWebsiteId($website->getId());
245246
if ($alert->getPrice() > $product->getFinalPrice()) {
246247
$productPrice = $product->getFinalPrice();
247248
$product->setFinalPrice($this->_catalogData->getTaxPrice($product, $productPrice));

app/code/Magento/ProductAlert/Test/Unit/Block/Email/StockTest.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class StockTest extends \PHPUnit\Framework\TestCase
2525
*/
2626
protected $imageBuilder;
2727

28-
/**
29-
* @var \Magento\ProductAlert\Block\Product\ImageProvider|\PHPUnit_Framework_MockObject_MockObject
30-
*/
31-
private $imageProviderMock;
32-
3328
protected function setUp()
3429
{
3530
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -39,16 +34,11 @@ protected function setUp()
3934
->disableOriginalConstructor()
4035
->getMock();
4136

42-
$this->imageProviderMock = $this->getMockBuilder(\Magento\ProductAlert\Block\Product\ImageProvider::class)
43-
->disableOriginalConstructor()
44-
->getMock();
45-
4637
$this->_block = $objectManager->getObject(
4738
\Magento\ProductAlert\Block\Email\Stock::class,
4839
[
4940
'maliciousCode' => $this->_filter,
50-
'imageBuilder' => $this->imageBuilder,
51-
'imageProvider' => $this->imageProviderMock
41+
'imageBuilder' => $this->imageBuilder
5242
]
5343
);
5444
}
@@ -88,8 +78,7 @@ public function testGetImage()
8878
->disableOriginalConstructor()
8979
->getMock();
9080

91-
$this->imageProviderMock->expects($this->atLeastOnce())->method('getImage')->willReturn($productImageMock);
92-
81+
$this->imageBuilder->expects($this->atLeastOnce())->method('create')->willReturn($productImageMock);
9382
$this->assertInstanceOf(
9483
\Magento\Catalog\Block\Product\Image::class,
9584
$this->_block->getImage($productMock, $imageId, $attributes)

app/code/Magento/ProductAlert/Test/Unit/Block/Product/ImageProviderTest.php

Lines changed: 0 additions & 99 deletions
This file was deleted.

app/code/Magento/ProductAlert/Test/Unit/Model/ObserverTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
/**
1313
* Class ObserverTest
14+
*
15+
* Is used to test Product Alert Observer
16+
*
1417
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1518
* @SuppressWarnings(PHPMD.TooManyFields)
1619
*/
@@ -168,7 +171,7 @@ protected function setUp()
168171
);
169172
$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
170173
->disableOriginalConstructor()
171-
->setMethods(['getDefaultStore', 'getId'])
174+
->setMethods(['getDefaultStore', 'getId', 'setWebsiteId'])
172175
->getMock();
173176
$this->customerRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\CustomerRepositoryInterface::class)
174177
->getMock();
@@ -285,12 +288,13 @@ public function testProcessPriceEmailThrowsException()
285288
$this->storeMock->expects($this->any())->method('getDefaultStore')->willReturnSelf();
286289
$this->websiteMock->expects($this->once())->method('getDefaultStore')->willReturn($this->storeMock);
287290
$this->storeMock->expects($this->any())->method('getId')->willReturn(2);
291+
$this->storeMock->expects($this->any())->method('setWebsiteId')->willReturnSelf();
288292

289293
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(true);
290294

291295
$this->priceColFactoryMock->expects($this->once())->method('create')->willReturnSelf();
292296
$this->priceColFactoryMock->expects($this->once())->method('addWebsiteFilter')->willReturnSelf();
293-
297+
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
294298
$items = [
295299
new \Magento\Framework\DataObject([
296300
'customer_id' => $id

0 commit comments

Comments
 (0)