private function addCpmCommissionToCampaigns() { $campaign = new Pap_Db_Campaign(); $campaigns = $campaign->loadCollection(); foreach ($campaigns as $campaign) { $commissionType = new Pap_Db_CommissionType(); $commissionType->setCampaignId($campaign->getId()); $commissionType->setType(Pap_Common_Constants::TYPE_CPM); try { $commissionType->loadFromData(); } catch (Gpf_DbEngine_NoRowException $e) { $commissionType->setStatus(Pap_Db_CommissionType::STATUS_DISABLED); $commissionType->setRecurrencePresetId(Pap_Db_CommissionType::RECURRENCE_NONE); $commissionType->setApproval(Pap_Db_CommissionType::APPROVAL_AUTOMATIC); $commissionType->setZeroOrdersCommission(Gpf::NO); $commissionType->setSaveZeroCommission(Gpf::NO); $commissionType->insert(); } } }
/** * Load commissionType from campaignId and type * * @throws Gpf_DbEngine_NoRowException * @throws Gpf_DbEngine_TooManyRowsException * * @return Pap_Db_CommissionType */ public function getCommissionType($campaignId, $type) { $commissionType = new Pap_Db_CommissionType(); $commissionType->setCampaignId($campaignId); $commissionType->setType($type); $commissionType->loadFromData(array(Pap_Db_Table_CommissionTypes::CAMPAIGNID, Pap_Db_Table_CommissionTypes::TYPE)); return $commissionType; }
private function setSplitCommissionsBonus(Pap_Db_Campaign $campaign) { $commissionType = new Pap_Db_CommissionType(); $commissionType->setCampaignId($campaign->getId()); $commissionType->setType(Pap_Common_Constants::TYPE_SALE); $commissionType->loadFromData(array(Pap_Db_Table_CommissionTypes::CAMPAIGNID, Pap_Db_Table_CommissionTypes::TYPE)); $overwriteCookie = $campaign->getOverwriteCookie(); if ($overwriteCookie != Gpf::YES && $overwriteCookie != Gpf::NO) { $overwriteCookie = $this->isGeneralOverwriteAllowed(); } if ($overwriteCookie == Gpf::YES) { $firstClickBonus = 0; $lastClickBonus = 100; } else { $firstClickBonus = 100; $lastClickBonus = 0; } Pap_Db_Table_CommissionTypeAttributes::getInstance()->setCommissionTypeAttributeValue($commissionType->getId(), Pap_Features_SplitCommissions_SplitCommissionsForm::FIRST_AFF_BONUS, $firstClickBonus); Pap_Db_Table_CommissionTypeAttributes::getInstance()->setCommissionTypeAttributeValue($commissionType->getId(), Pap_Features_SplitCommissions_SplitCommissionsForm::LAST_AFF_BONUS, $lastClickBonus); }
private function getCommissionTypeAndValue($campaignId, $userId, $commissionTypeId, $tier = null) { if (is_null($tier) || $tier == '') { $tier = 1; } // getting user if($userId == '') { $this->errorMsg = $this->_("User is not valid!"); return false; } $user = new Pap_Common_User(); $user->setPrimaryKeyValue($userId); try { $user->load(); } catch (Gpf_DbEngine_NoRowException $e) { $this->errorMsg = $this->_("User is not valid!"); return false; } // getting campaign $campaign = new Pap_Common_Campaign(); $campaign->setId($campaignId); try { $campaign->load(); } catch (Gpf_DbEngine_NoRowException $e) { $this->errorMsg = $this->_("Campaign is not valid!"); return false; } // getting commission type try { $commissionType = new Pap_Db_CommissionType(); $commissionType->setId($commissionTypeId); $commissionType->setStatus(Pap_Db_CommissionType::STATUS_ENABLED); $commissionType->loadFromData(); } catch (Gpf_DbEngine_NoRowException $e) { $this->errorMsg = $this->_("Transaction type is not valid or doesn't exist in this campaign!"); return false; } $fixedcostType = $commissionType->getFixedcostType(); $fixedcostValue = $commissionType->getFixedcostValue(); // getting commission group $commGroupId = $campaign->getCommissionGroupForUser($userId); if($commGroupId == false) { $this->errorMsg = $this->_("Cannot recognize commission group for this user in campaign!"); return false; } $rsCommissions = $campaign->getCommissionsCollection($commGroupId, $commissionType->getId()); $commType = null; $commValue = null; foreach($rsCommissions as $record) { if($record->get('tier') == $tier && $record->get('subtype') == 'N') { $commType = $record->get('commissiontype'); $commValue = $record->get('commissionvalue'); break; } } if($commType == null) { $this->errorMsg = $this->_("Error getting commission settings!"); return false; } return array('type' => $commType, 'value' => $commValue, 'fixedcostValue' => $fixedcostValue, 'fixedcostType' => $fixedcostType); }
/** * @return Pap_Db_CommissionType */ protected function getCommTypeFromCampaignAndRtype($campaignId, $rtype) { $commObj = new Pap_Db_CommissionType(); $commObj->setCampaignId($campaignId); $commObj->setType($rtype); $commObj->loadFromData(array(Pap_Db_Table_CommissionTypes::CAMPAIGNID, Pap_Db_Table_CommissionTypes::TYPE)); return $commObj; }