Skip to content

Commit 7568f7a

Browse files
committed
MAGETWO-33654: Unable to save newsletter subscription information of customer in backend
1 parent bee47f0 commit 7568f7a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,25 @@ public function initForm()
154154
[
155155
'label' => __('Subscribed to Newsletter'),
156156
'name' => 'subscription',
157-
'data-form-part' => $this->getData('target_form')
157+
'data-form-part' => $this->getData('target_form'),
158+
'onchange' => 'this.value = this.checked;'
158159
]
159160
);
160161

161162
if ($this->customerAccountManagement->isReadOnly($customerId)) {
162163
$form->getElement('subscription')->setReadonly(true, true);
163164
}
164-
165-
$form->getElement('subscription')->setIsChecked($subscriber->isSubscribed());
165+
$isSubscribed = $subscriber->isSubscribed();
166+
$form->setValues(['subscription' => $isSubscribed ? 'true' : 'false']);
167+
$form->getElement('subscription')->setIsChecked($isSubscribed);
166168

167169
$changedDate = $this->getStatusChangedDate();
168170
if ($changedDate) {
169171
$fieldset->addField(
170172
'change_status_date',
171173
'label',
172174
[
173-
'label' => $subscriber->isSubscribed() ? __('Last Date Subscribed') : __('Last Date Unsubscribed'),
175+
'label' => $isSubscribed ? __('Last Date Subscribed') : __('Last Date Unsubscribed'),
174176
'value' => $changedDate,
175177
'bold' => true
176178
]

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ public function execute()
236236
$customerId = $customer->getId();
237237
}
238238

239-
$isSubscribed = false;
239+
$isSubscribed = null;
240240
if ($this->_authorization->isAllowed(null)) {
241-
$isSubscribed = $this->getRequest()->getPost('subscription') !== null;
241+
$isSubscribed = $this->getRequest()->getPost('subscription');
242242
}
243-
if ($isSubscribed) {
244-
$this->_subscriberFactory->create()->subscribeCustomerById($customerId);
245-
} else {
246-
$this->_subscriberFactory->create()->unsubscribeCustomerById($customerId);
243+
if ($isSubscribed !== null) {
244+
if ($isSubscribed !== 'false') {
245+
$this->_subscriberFactory->create()->subscribeCustomerById($customerId);
246+
} else {
247+
$this->_subscriberFactory->create()->unsubscribeCustomerById($customerId);
248+
}
247249
}
248250

249251
// After save

0 commit comments

Comments
 (0)