/**
     * @param Pap_Db_VisitorAffiliate
     * @return Pap_Db_VisitorAffiliate
     */
    public function recognizeAffiliate(Pap_Db_VisitorAffiliate $visitorAffiliate) {
        $user = $this->getUserById($visitorAffiliate->getUserId());

        if ($user == null) {
            $this->isValid = false;
            return;
        }
        
        $this->context->setUserObject($user);

        $campaign = $this->getCampaignById($visitorAffiliate->getCampaignId());
        if ($campaign != null && $this->context->getCampaignObject() == null) {
            $this->context->setCampaignObject($campaign);
        }

        $banner = $this->getBannerById($visitorAffiliate->getBannerId());
        if ($banner != null && $this->context->getBannerObject() == null) {
            $this->context->setBannerObject($banner);
        }

        $channel = $this->getChannelById($visitorAffiliate->getChannelId());
        if ($channel != null) {
            $this->context->setChannelObject($channel);
        }
        $this->context->setVisitorAffiliate($visitorAffiliate);

        $this->isValid = true;
    }
    protected function prepareContextForSave(Pap_Contexts_Action $context) {
        $transaction = $context->getTransaction();
        $transaction->setOrderId($context->getOrderIdFromRequest());
        $transaction->setProductId($context->getProductIdFromRequest());
        $transaction->setTotalCost($context->getRealTotalCost());
        $transaction->setFixedCost($context->getFixedCost());
        $transaction->setCountryCode($context->getCountryCode());

        if($context->getChannelObject() !== null) {
            $transaction->setChannel($context->getChannelObject()->getId());
        }
        if($context->getBannerObject() !== null) {
            $transaction->setBannerId($context->getBannerObject()->getId());
        }

        $transaction->setData1($context->getExtraDataFromRequest(1));
        $transaction->setData2($context->getExtraDataFromRequest(2));
        $transaction->setData3($context->getExtraDataFromRequest(3));
        $transaction->setData4($context->getExtraDataFromRequest(4));
        $transaction->setData5($context->getExtraDataFromRequest(5));

        $transaction->setDateInserted($context->getVisitDateTime());

        $transaction->setVisitorId($context->getVisitorId());
        $transaction->setTrackMethod($context->getTrackingMethod());
        $transaction->setIp($context->getIp());
        try {
            $transaction->setRefererUrl($context->getVisitorAffiliate()->getReferrerUrl());
        } catch (Gpf_Exception $e) {
            $transaction->setRefererUrl($context->getReferrerUrl());
        }

        try {
            $visitorId = $context->getVisitorAffiliate()->getVisitorId();
        } catch (Exception $e) {
            $visitorId = $this->_('unknown');
        }
        
        try {
            $this->setFirstAndLastClick($transaction, $this->getVisitorAffiliatesCollection($context));
        } catch (Gpf_Exception $e) {
            $context->debug('First and Last click can not be recognized for visitorId: ' . $visitorId . '. ' . $e->getMessage());
        }
    }