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)); + } } diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index ac5563f56801c..7847098083949 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -554,6 +554,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();