Пример #1
0
    public function process(Pap_Common_TransactionCompoundContext $context) {

        $transaction = $context->getTransaction();
        $context->getContext()->debug("SubaffiliateFirstSaleBonus started");
        if($transaction->getTier() != 2) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Not 2. tier");
            return;
        }

        $row = $this->getChildAffiliateInfo($transaction);

        $date = new Gpf_DateTime(time());
        $date->addDay(-Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::VALIDITY_DAYS));

        if(Gpf_Common_DateUtils::getDateTime($date->toTimeStamp()) > $row->get(Pap_Db_Table_Users::DATEINSERTED)) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Date Inserted is older than defined days.");
            return;
        }

        if($this->getChildAffiliateTransactionsCount($row->get(Pap_Db_Table_Transactions::USER_ID)) > 1) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Not user's first transaction.");
            return;
        }

        if(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_TYPE) == '%') {
            $transaction->setCommission($transaction->getCommission()+(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_AMOUNT)/100)*$transaction->getTotalCost());
        } else{
            $transaction->setCommission(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_AMOUNT)+$transaction->getCommission());
        }
        $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Success.");
        return;
    }
    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());
    }
Пример #3
0
 public function saveCommission(Pap_Common_TransactionCompoundContext $transactionCompoundContext) {
     $context = $transactionCompoundContext->getContext();
     $transaction = $transactionCompoundContext->getTransaction();
     
     $context->debug('BonusCommissions started');
     
     if ($transaction->getTier() != 1) {
         $context->debug('BonusCommissions - transaction is not tier 1. STOPPED');
         return;
     }
     
     $minCommissionSaleValue = $this->getMinSaleValueForBonus($transaction->getCommissionTypeId());
     if ($minCommissionSaleValue == -1) {
         $context->debug('BonusCommissions - minimum Commission Value = -1. STOPPED');
         return;
     }
     
     $bonusValue = $this->getBonusValue($transaction->getCommissionTypeId());
     if ($bonusValue == 0) {
         $context->debug('BonusCommissions - bonus value = 0. STOPPED');
         return;
     }
     
     if ($transaction->getTotalCost() >= $minCommissionSaleValue) {
         $transaction->setCommission($transaction->getCommission() + $bonusValue);
     }
     $context->debug('BonusCommissions - commission added. Ended');
 }