Example #1
0
 /**
  * Send out new invite email
  * 
  */
 public function sendEmailNewInvite()
 {
     \Base::instance()->set('invite', $this);
     \Base::instance()->set('settings', \Affiliates\Models\Settings::fetch());
     $html = \Dsc\System::instance()->get('theme')->renderView('Affiliates/Views::emails_html/invite.php');
     $text = \Dsc\System::instance()->get('theme')->renderView('Affiliates/Views::emails_text/invite.php');
     $subject = $this->sender_name . ' has sent you an invitation';
     $this->__sendEmailNewInvite = \Dsc\System::instance()->get('mailer')->send($this->recipient_email, $subject, array($html, $text));
     return $this;
 }
Example #2
0
 public function index()
 {
     $settings = \Affiliates\Models\Settings::fetch();
     $flash_filled = \Dsc\System::instance()->getUserState('invite_friends.email.flash_filled');
     if (!$flash_filled) {
         $this->flash->store(array('sender_name' => $this->auth->getIdentity()->fullName(), 'sender_email' => $this->auth->getIdentity()->email, 'message' => $settings->{'general.default_message'}));
     }
     \Dsc\System::instance()->setUserState('invite_friends.email.flash_filled', false);
     $invites = (new \Affiliates\Models\Invites())->setState('list.limit', 10)->setState('filter.affiliate_id', $this->auth->getIdentity()->id)->getItems();
     $this->app->set('invites', $invites);
     $this->app->set('meta.title', 'Affiliate Dashboard');
     echo $this->theme->renderTheme('Affiliates/Site/Views::dashboard.php');
 }
Example #3
0
 public function onShopAcceptOrder($event)
 {
     $order = $event->getArgument('order');
     $settings = \Affiliates\Models\Settings::fetch();
     // are conversion commissions enabled?
     if ($settings->{'commissions.for_conversion'}) {
         // is the order customer a referral?
         $referral = (new \Affiliates\Models\Referrals())->setState('filter.referral_user_id', $order->user_id)->getItem();
         if (!empty($referral->id)) {
             $affiliate = $referral->affiliate();
             // How long does the affiliate earn conversion commissions?
             // does this affiliate still get to earn conversion commissions for this referral?
             $can_earn_commission = $referral->triggersConversionCommission();
             if ($can_earn_commission) {
                 $auto_issue = (bool) $settings->{'commissions.auto_issue'};
                 try {
                     $commission = (new \Affiliates\Models\Commissions())->bind(array('referral_id' => $referral->id, 'referral_name' => $referral->referral()->fullName(), 'affiliate_id' => $affiliate->id, 'affiliate_name' => $affiliate->fullName(), 'shop_order_id' => $order->id, 'shop_order_amount' => (double) $order->grand_total, 'type' => \Affiliates\Models\Commissions::TYPE_CONVERSION))->set('__issue', $auto_issue)->save();
                 } catch (\Exception $e) {
                 }
             }
         }
     }
 }
Example #4
0
<?php

$settings = \Affiliates\Models\Settings::fetch();
$link = $SCHEME . '://' . $HOST . $BASE . '/affiliate/' . $this->auth->getIdentity()->id;
$encoded_link = urlencode($link);
?>

<h4>
    Share your order with your friends
    <small>and earn store credit for your next purchase</small>
</h4>

<ul class="list-group">
    <li class="list-group-item">
        <a class="btn btn-default" href="./affiliate/invite-friends/email" target="_blank"><i class="fa fa-envelope"></i> <span>Send an email</span></a>
    </li>
    
    <?php 
if ($settings->isSocialProviderEnabled('facebook')) {
    ?>
    <?php 
    $fb_app_id = $settings->{'social.providers.Facebook.keys.id'};
    ?>
    <?php 
    $fb_redirect_uri = $SCHEME . '://' . $HOST . $BASE . '/affiliate/share/thanks';
    ?>
    <li class="list-group-item">
        <a class="btn btn-default" href="javascript:void(0);" onclick="window.open('https://www.facebook.com/dialog/share?app_id=<?php 
    echo $fb_app_id;
    ?>
&display=popup&href=<?php 
Example #5
0
 /**
  * Does this referral trigger a conversion commission?
  * 
  * @return boolean
  */
 public function triggersConversionCommission()
 {
     $settings = \Affiliates\Models\Settings::fetch();
     if (!$settings->{'commissions.for_conversion'}) {
         return false;
     }
     // How long does the affiliate earn conversion commissions?
     // does this affiliate still get to earn conversion commissions for this referral?
     $conversion_number = $settings->{'shop.conversion_number'};
     $conversion_period = $settings->{'shop.conversion_period'};
     if ($conversion_period == 'forever') {
         return true;
     }
     if ($conversion_period == 'order') {
         // is the count of created commissions for this referral < the $conversion_number?
         $commissions_count = \Affiliates\Models\Commissions::collection()->count(array('referral_id' => $this->id, 'type' => \Affiliates\Models\Commissions::TYPE_CONVERSION));
         // if so, $return = true;
         if ($commissions_count < $conversion_number) {
             return true;
         }
     } else {
         // $conversion_period == month | year
         // $period_expiration_date = $referral_created_date + ($conversion_number $conversion_period)
         $period_expiration_date = date('Y-m-d', strtotime($this->{'metadata.created.local'} . "+ {$conversion_number} {$conversion_period}"));
         if (date('Y-m-d') < $period_expiration_date) {
             return true;
         }
     }
     return false;
 }
Example #6
0
 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();
 }
Example #7
0
 public function link()
 {
     $settings = \Affiliates\Models\Settings::fetch();
     $this->app->set('meta.title', 'Share your personal link | Affiliates');
     echo $this->theme->renderTheme('Affiliates/Site/Views::invite/link.php');
 }