getRequest()->getParam('customer_id'); $redirect = $this->resultRedirectFactory->create()->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]); try { $points = abs((int)$this->getRequest()->getParam('points')); $operation = (string)$this->getRequest()->getParam('operation'); $reason = trim((string)$this->getRequest()->getParam('reason')); $evidence = trim((string)$this->getRequest()->getParam('evidence')); if ($customerId <= 0 || $points <= 0) { throw new LocalizedException(__('Enter a positive number of points.')); } if ($reason === '') { throw new LocalizedException(__('A reason is required.')); } $adjustmentType = (string)$this->getRequest()->getParam('adjustment_type'); $type = $adjustmentType === 'social_share' ? 'social_share' : 'admin_adjustment'; $delta = $operation === 'subtract' ? -$points : $points; $customer = $this->customers->getById($customerId); $admin = $this->authSession->getUser(); $this->balanceManager->change($customerId, (int)$customer->getWebsiteId(), $delta, $type, $type . ':' . $this->random->getUniqueHash(), [ 'reference_type' => 'admin', 'reference_id' => $admin ? (int)$admin->getId() : null, 'reason' => $reason, 'admin_user_id' => $admin ? (int)$admin->getId() : null, 'metadata' => $evidence === '' ? [] : ['evidence' => $evidence] ]); $this->messageManager->addSuccessMessage(__('The reward points were adjusted.')); } catch (\Throwable $e) { $this->messageManager->addErrorMessage($e->getMessage()); } return $redirect; } }