From 0a4275a3646f12ef4e3ba456d3e3c3f50492b051 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Wed, 9 Aug 2017 12:48:30 +0300 Subject: [PATCH 1/2] MAGETWO-71179: Customers are unsubscribed from the newsletter after confirming their account --- .../Magento/Newsletter/Model/Subscriber.php | 3 ++ .../Test/Unit/Model/SubscriberTest.php | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index f69f26a8d64ed..0e0c0dd1b6ac4 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -555,6 +555,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe) } elseif ($isConfirmNeed) { $status = self::STATUS_NOT_ACTIVE; } + } elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) { + $status = self::STATUS_SUBSCRIBED; + $sendInformationEmail = true; } else { $status = self::STATUS_UNSUBSCRIBED; } diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php index 52b087cf0a0e5..7716f4744a922 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php @@ -273,6 +273,35 @@ public function testSubscribeCustomerById1() $this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus()); } + public function testSubscribeCustomerByIdAfterConfirmation() + { + $customerId = 1; + $customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class) + ->getMock(); + $this->customerRepository->expects($this->atLeastOnce()) + ->method('getById') + ->with($customerId)->willReturn($customerDataMock); + $this->resource->expects($this->atLeastOnce()) + ->method('loadByCustomerData') + ->with($customerDataMock) + ->willReturn( + [ + 'subscriber_id' => 1, + 'subscriber_status' => 4 + ] + ); + $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); + $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); + $customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id'); + $customerDataMock->expects($this->once())->method('getEmail')->willReturn('email'); + $this->sendEmailCheck(); + $this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus'); + $this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true); + + $this->subscriber->updateSubscription($customerId); + $this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus()); + } + public function testUnsubscribe() { $this->resource->expects($this->once())->method('save')->willReturnSelf(); From 4b85f3af090f583ea72e1194a6a6daa6a2d60818 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Wed, 23 Aug 2017 17:44:01 +0300 Subject: [PATCH 2/2] MAGETWO-71289: No such entity exception is thrown when trying to create a Scheduled update for Product with custom option - support option value recreation in case if we schedule new update --- .../Model/Product/Option/Repository.php | 4 ++- .../Model/Product/Option/RepositoryTest.php | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Repository.php b/app/code/Magento/Catalog/Model/Product/Option/Repository.php index 2f39618ce4a2b..c2d7781b37ad8 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Repository.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Repository.php @@ -172,7 +172,9 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt $originalValues = $persistedOption->getValues(); $newValues = $option->getData('values'); if ($newValues) { - $newValues = $this->markRemovedValues($newValues, $originalValues); + if (isset($originalValues)) { + $newValues = $this->markRemovedValues($newValues, $originalValues); + } $option->setData('values', $newValues); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php index ad37e5bbe6eef..ec6aa9d8db83a 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/RepositoryTest.php @@ -267,4 +267,29 @@ public function testSave() ]); $this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock)); } + + public function testSaveWhenOptionTypeWasChanged() + { + $productSku = 'simple_product'; + $optionId = 1; + $this->optionMock->expects($this->once())->method('getProductSku')->willReturn($productSku); + $this->productRepositoryMock + ->expects($this->once()) + ->method('get') + ->with($productSku) + ->willReturn($this->productMock); + $this->optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId); + $this->productMock->expects($this->once())->method('getOptions')->willReturn([]); + $this->optionMock->expects($this->once())->method('getData')->with('values')->willReturn([ + ['option_type_id' => 4], + ['option_type_id' => 5] + ]); + $optionCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Option\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + $optionCollection->expects($this->once())->method('getProductOptions')->willReturn([$this->optionMock]); + $this->optionCollectionFactory->expects($this->once())->method('create')->willReturn($optionCollection); + $this->optionMock->expects($this->once())->method('getValues')->willReturn(null); + $this->assertEquals($this->optionMock, $this->optionRepository->save($this->optionMock)); + } }