public function applySplitCommission(Pap_Common_TransactionCompoundContext $transactionCompoundContext) {
        if ($transactionCompoundContext->getContext()->isManualAddMode()) {
            return;
        }

        if ($transactionCompoundContext->getContext()->getActionType() != Pap_Common_Constants::TYPE_ACTION &&
        $transactionCompoundContext->getContext()->getActionType() != Pap_Common_Constants::TYPE_SALE) {
            return;
        }

        if ($transactionCompoundContext->getContext()->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_DEFAULT_AFFILIATE) {
            $transactionCompoundContext->getContext()->debug('SplitCommissions - default affiliate - not splitting commission. STOPPED');
            return;
        }

        if ($transactionCompoundContext->getContext()->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_COUPON) {
            $transactionCompoundContext->getContext()->debug('SplitCommissions - coupon - not splitting commission. STOPPED');
            return;
        }

        if ($transactionCompoundContext->getContext()->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_FORCED_PARAMETER) {
            $transactionCompoundContext->getContext()->debug('SplitCommissions - forced parameter - not splitting commission. STOPPED');
            return;
        }

        $userId = $transactionCompoundContext->getContext()->getUserObject()->getId();
        if (!isset($this->splitCommissions[$userId])) {
            $transactionCompoundContext->setSaveTransaction(false);
            return;
        }

        if ($this->splitCommissions[$userId] == 0) {
            unset($this->splitCommissions[$userId]);
            $transactionCompoundContext->setSaveTransaction(false);
            return;
        }

        $commission = $this->splitCommissions[$userId] * $transactionCompoundContext->getTransaction()->getCommission() / 100;
        if ($this->minCommission != 0 && $commission < $this->minCommission) {
            unset($this->splitCommissions[$userId]);
            $transactionCompoundContext->setSaveTransaction(false);
            return;
        }

        $transactionCompoundContext->getTransaction()->setCommission($commission);

        $transactionCompoundContext->getTransaction()->setSaleId($this->saleId);

        $transactionCompoundContext->getTransaction()->setSplit($this->splitCommissions[$userId] / 100);

        $this->setFirstAndLastClick($transactionCompoundContext->getTransaction(), $transactionCompoundContext->getContext()->getVisitorAffiliate()->getUserId());
    }
예제 #2
0
 public function beforeSave(Pap_Common_TransactionCompoundContext $transactionCompoundContext){
     $user =  Pap_Affiliates_User::loadFromId($transactionCompoundContext->getTransaction()->getUserId());
     if ($user->getParentUserId() != '') {
         $transactionCompoundContext->setSaveTransaction(false);
     }
 }