public function beforeCreate() { // Prevent the same email from receiving multiple requests from this affiliate $invited = (new static())->setState('filter.recipient_email', $this->recipient_email)->setState('filter.affiliate_id', $this->affiliate_id)->getItem(); if (!empty($invited->id)) { $this->setError('An invite has already been sent to this recipient'); } return parent::beforeCreate(); }
protected function beforeCreate() { if (empty($this->messages)) { if (!is_array($this->messages)) { $this->messages = array(); } // TODO Allow admins to set this $system_message = 'Hello, thanks for starting a support session. One of our operators will be with you momentarily. Feel free to continue browsing through our site while you wait.'; $this->messages[] = (new \Support\Models\ChatMessages(array('sender_type' => 'system', 'sender_name' => 'System Bot', 'timestamp' => time(), 'text' => $system_message)))->cast(); } $exists = static::collection()->findOne(array('session_id_user' => $this->session_id_user)); if (isset($exists['_id'])) { $this->setError('Only one session per user'); } return parent::beforeCreate(); }
protected function beforeCreate() { // if invite_id is empty but referral_email exists, try to lookup the affiliate's invite_id to match this referral to it if (empty($this->invite_id) && !empty($this->referral_email)) { $invite = (new \Affiliates\Models\Invites())->setState('filter.affiliate_id', $this->affiliate_id)->setState('filter.recipient_email', $this->referral_email)->getItem(); if (!empty($invite->id)) { $this->invite_id = $invite->id; } } return parent::beforeCreate(); }
protected function beforeCreate() { if (class_exists('\\Shop\\Models\\Orders')) { // shop exists, do the integration $settings = \Affiliates\Models\Settings::fetch(); $referral_credit = (double) $settings->{'shop.store_credit_per_referral'}; if ($referral_credit && $this->type == self::TYPE_REFERRAL) { // affiliate earns a shop.credit for the referral, so push it into the actions stack $this->actions[] = (new \Affiliates\Models\CommissionActions())->bind(array('amount' => $referral_credit, 'type' => 'shop.credit', 'issued' => false))->cast(); } $conversion_credit = (double) $settings->{'shop.store_credit_per_conversion'}; $conversion_credit_type = (double) $settings->{'shop.store_credit_per_conversion_type'}; // flat-rate or percentage if ($conversion_credit && $this->type == self::TYPE_CONVERSION) { $amount = $conversion_credit_type == 'flat-rate' ? $conversion_credit : $conversion_credit / 100 * $this->shop_order_amount; // affiliate earns a shop.credit for the referral, so push it into the actions stack $this->actions[] = (new \Affiliates\Models\CommissionActions())->bind(array('amount' => (double) $amount, 'type' => 'shop.credit', 'issued' => false))->cast(); } } parent::beforeCreate(); }
protected function beforeCreate() { $this->balance = $this->initial_value; return parent::beforeCreate(); }