public function saveCommissions(Pap_Common_ActionProcessorCompoundContext $actionProcessorCompoundContext) {
        $context = $actionProcessorCompoundContext->getContext();
        $cache = $actionProcessorCompoundContext->getActionProcessor()->getVisitorAffiliatesCache();

        $context->debug('SplitCommissions save started');

        $commType = $this->getCommissionType($context);

        if ($context->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_DEFAULT_AFFILIATE) {
            $context->debug('SplitCommissions - default affiliate. STOPPED');
            return;
        }

        if ($context->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_FORCED_PARAMETER) {
            $context->debug('SplitCommissions - forced parameter. STOPPED');
            return;
        }

        if ($context->getTrackingMethod() == Pap_Common_Transaction::TRACKING_METHOD_COUPON) {
            $context->debug('SplitCommissions - coupon. STOPPED');
            return;
        }

        $this->saleId = Gpf_Common_String::generateId();

        $firstAffBonus = $this->loadCommissionTypeAttributeValue($commType->getId(), Pap_Features_SplitCommissions_SplitCommissionsForm::FIRST_AFF_BONUS);
        $lastAffBonus = $this->loadCommissionTypeAttributeValue($commType->getId(), Pap_Features_SplitCommissions_SplitCommissionsForm::LAST_AFF_BONUS);
        $this->minCommission = $this->loadCommissionTypeAttributeValue($commType->getId(), Pap_Features_SplitCommissions_SplitCommissionsForm::MIN_COMMISSION);

        Pap_Features_SplitCommissions_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $cache);

        $visitorAffiliates = $cache->getVisitorAffiliateAllRows($context->getVisitorId());

        Pap_Tracking_Visit_VisitorAffiliateCache::sortVisitorAffiliatesByDateVisit($visitorAffiliates);

        $this->setSplitCommissions($this->getSplitCommissions($firstAffBonus, $lastAffBonus, $visitorAffiliates));

        $this->visitorAffiliateCollection = $visitorAffiliates;

        $this->processVisitorAffiliates($visitorAffiliates, $actionProcessorCompoundContext);

        $context->debug('SplitCommissions save finished');
        $actionProcessorCompoundContext->setCommissionsAlreadySaved(true);
    }
    public function saveVisitorAffiliate(Pap_Common_VisitorAffiliateCacheCompoundContext $cacheCompoundContext) {
        $cacheCompoundContext->setVisitorAffiliateAlreadySaved(true);

        $context = $cacheCompoundContext->getContext();
        $cache = $cacheCompoundContext->getVisitorAffilliateCache();
        $context->debug('Saving VisitorAffiliate by SplitCommissions started');

        Pap_Features_SplitCommissions_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $cache);

        $rows = $cache->getVisitorAffiliateAllRows($context->getVisitorId());
        $oldVisitorAffiliate = null;

        $lastClickVisitorAffiliate = null;
        $firstClickVisitorAffiliate = null;

        foreach ($rows as $row) {
            if (!$row->isValid()) {
                continue;
            }
            if ($firstClickVisitorAffiliate == null ||
            $firstClickVisitorAffiliate->getDateVisit() > $row->getDateVisit()) {
                $firstClickVisitorAffiliate = $row;
            }

            if ($lastClickVisitorAffiliate == null ||
            $lastClickVisitorAffiliate->getDateVisit() < $row->getDateVisit()) {
                $lastClickVisitorAffiliate = $row;
            }

            if ($row->isActual()) {
                $row->setActual(false);
            }
        }

        $oldVisitorAffiliate = $this->findAlreadyStoredVisitorAffiliate($rows, $firstClickVisitorAffiliate, $context);

        if ($firstClickVisitorAffiliate == null) {
            $firstVisitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId());
            Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($firstVisitorAffiliate, $context);
            $rows->add($firstVisitorAffiliate);

            $visitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId());
        } else {
            $visitorAffiliate = $this->getVisitorAffiliate($firstClickVisitorAffiliate,
            $oldVisitorAffiliate, $cache, $context);

            if ($oldVisitorAffiliate == null && 
            $visitorAffiliate === $firstClickVisitorAffiliate) {
                Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($visitorAffiliate, $context);
                $visitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId()); 
            }
        }

        if ($visitorAffiliate == null) {
            $context->debug('SplitCommission VisitorAffiliate no updated - not actual data');
            return;
        }

        Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($visitorAffiliate, $context);

        if ($oldVisitorAffiliate == null && $firstClickVisitorAffiliate !== $visitorAffiliate) {
            $rows->add($visitorAffiliate);
        }

        $context->debug('New visitorAffiliate added/saved by SplitCommissions');
    }
 /**
  * @return Pap_Features_SplitCommissions_VisitorAffiliateCheckCompatibility
  */
 public static function getHandlerInstance() {
     if(!self::$instance)  {
         return self::$instance = new Pap_Features_SplitCommissions_VisitorAffiliateCheckCompatibility();
     }
     return self::$instance;
 }