Skip to content

Commit 4381a6b

Browse files
author
Sergii Kovalenko
authored
Merge pull request #1436 from magento-honey-badgers/MAGETWO-71289
Fixed issues: [] MAGETWO-71179 Customers are unsubscribed from the newsletter after confirming their account [] MAGETWO-71289 No such entity exception is thrown when trying to create a Scheduled update for Product with custom option
2 parents fd81f51 + 09ce2c0 commit 4381a6b

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
172172
$originalValues = $persistedOption->getValues();
173173
$newValues = $option->getData('values');
174174
if ($newValues) {
175-
$newValues = $this->markRemovedValues($newValues, $originalValues);
175+
if (isset($originalValues)) {
176+
$newValues = $this->markRemovedValues($newValues, $originalValues);
177+
}
176178
$option->setData('values', $newValues);
177179
}
178180
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,29 @@ public function testSave()
267267
]);
268268
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
269269
}
270+
271+
public function testSaveWhenOptionTypeWasChanged()
272+
{
273+
$productSku = 'simple_product';
274+
$optionId = 1;
275+
$this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku);
276+
$this->productRepositoryMock
277+
->expects($this->once())
278+
->method('get')
279+
->with($productSku)
280+
->willReturn($this->productMock);
281+
$this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId);
282+
$this->productMock->expects($this->once())->method('getOptions')->willReturn([]);
283+
$this->optionMock->expects($this->once())->method('getData')->with('values')->willReturn([
284+
['option_type_id' => 4],
285+
['option_type_id' => 5]
286+
]);
287+
$optionCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Collection::class)
288+
->disableOriginalConstructor()
289+
->getMock();
290+
$optionCollection->expects($this->once())->method('getProductOptions')->willReturn([$this->optionMock]);
291+
$this->optionCollectionFactory->expects($this->once())->method('create')->willReturn($optionCollection);
292+
$this->optionMock->expects($this->once())->method('getValues')->willReturn(null);
293+
$this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock));
294+
}
270295
}

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
554554
} elseif ($isConfirmNeed) {
555555
$status = self::STATUS_NOT_ACTIVE;
556556
}
557+
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
558+
$status = self::STATUS_SUBSCRIBED;
559+
$sendInformationEmail = true;
557560
} else {
558561
$status = self::STATUS_UNSUBSCRIBED;
559562
}

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,35 @@ public function testSubscribeCustomerById1()
273273
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
274274
}
275275

276+
public function testSubscribeCustomerByIdAfterConfirmation()
277+
{
278+
$customerId = 1;
279+
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
280+
->getMock();
281+
$this->customerRepository->expects($this->atLeastOnce())
282+
->method('getById')
283+
->with($customerId)->willReturn($customerDataMock);
284+
$this->resource->expects($this->atLeastOnce())
285+
->method('loadByCustomerData')
286+
->with($customerDataMock)
287+
->willReturn(
288+
[
289+
'subscriber_id' => 1,
290+
'subscriber_status' => 4
291+
]
292+
);
293+
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
294+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
295+
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
296+
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
297+
$this->sendEmailCheck();
298+
$this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus');
299+
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
300+
301+
$this->subscriber->updateSubscription($customerId);
302+
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
303+
}
304+
276305
public function testUnsubscribe()
277306
{
278307
$this->resource->expects($this->once())->method('save')->willReturnSelf();

0 commit comments

Comments
 (0)