/** * Analyze referral code and get parent for the customer. * * @param int $customerId * @param int $parentId * @return int */ public function getReferredParentId($customerId, $parentId) { /* use customer ID as parent ID if parent ID is missed */ $result = $parentId ? $parentId : $customerId; $code = $this->_toolReferral->getReferralCode(); if ($code) { $parentDo = $this->_repoCustomer->getByReferralCode($code); if ($parentDo) { $result = $parentDo->getCustomerId(); } } return $result; }