Example #1
0
 /**
  * get Banner direct URL
  * 
  * @return string
  */
 public function getBannerUrl()
 {
     $banner = $this->getBanner();
     $store = Mage::app()->getStore($banner->getStoreId());
     $account = $this->getAccount();
     $url = Mage::helper('affiliateplus/url')->getUrlLink($banner->getLink());
     if (strpos($url, '?')) {
         $url .= '&acc=' . $account->getIdentifyCode();
     } else {
         $url .= '?acc=' . $account->getIdentifyCode();
     }
     if ($store->getId() != Mage::app()->getDefaultStoreView()->getId()) {
         $url .= '&___store=' . $store->getCode();
     }
     if ($banner->getId()) {
         $url .= '&bannerid=' . $banner->getId();
     }
     $urlParams = new Varien_Object(array('helper' => Mage::helper('affiliateplus/url'), 'params' => array()));
     Mage::dispatchEvent('affiliateplus_helper_get_banner_url', array('banner' => $banner, 'url_params' => $urlParams));
     $params = $urlParams->getParams();
     if (count($params)) {
         $url .= '&' . http_build_query($urlParams->getParams(), '', '&');
     }
     return $url;
 }
Example #2
0
 public function _getValue(Varien_Object $row)
 {
     $params = Mage::helper('core')->jsonDecode($row->getParams());
     if (isset($params['slide_thumb']) && $params['slide_thumb']) {
         return sprintf('<img src="%s" width="100"/>', $params['slide_thumb']);
     } elseif (isset($params['background_type'])) {
         switch ($params['background_type']) {
             case 'image':
                 if (isset($params['image_url']) && $params['image_url']) {
                     return sprintf('<img src="%s" width="100"/>', strpos($params['image_url'], 'http') === 0 ? $params['image_url'] : Mage::getBaseUrl('media') . $params['image_url']);
                 }
                 break;
             case 'solid':
                 if (isset($params['slide_bg_color']) && $params['slide_bg_color']) {
                     return sprintf('<div style="width:100px;height:80px;background:#%s;"></div>', $params['slide_bg_color']);
                 }
                 break;
             case 'trans':
                 return '<div style="width:100px;height:80px;background:url(' . $this->getSkinUrl('am/revslider/trans_tile2.png') . ');"></div>';
                 break;
             case 'external':
                 if (isset($params['bg_external']) && $params['bg_external']) {
                     return sprintf('<img src="%s" width="100"/>', strpos($params['bg_external'], 'http') === 0 ? $params['bg_external'] : Mage::getBaseUrl('media') . $params['bg_external']);
                 }
                 break;
         }
     }
     return '';
 }
Example #3
0
 public function _getValue(Varien_Object $row)
 {
     $params = Mage::helper('core')->jsonDecode($row->getParams());
     if (isset($params['title'])) {
         return $params['title'];
     }
     return '';
 }
Example #4
0
 /**
  * add account param to link
  *
  * @param string $url
  * @param Mage_Core_Model_Store $store
  * @return string
  */
 public function addAccToUrl($url, $store = null)
 {
     if (is_null($store)) {
         $store = Mage::app()->getStore();
     }
     $account = Mage::getSingleton('affiliateplus/session')->getAccount();
     $url = $this->getUrlLink($url);
     if (strpos($url, '?')) {
         $url .= '&acc=' . $account->getIdentifyCode();
     } else {
         $url .= '?acc=' . $account->getIdentifyCode();
     }
     if ($store->getId() != Mage::app()->getDefaultStoreView()->getId()) {
         $url .= '&___store=' . $store->getCode();
     }
     $urlParams = new Varien_Object(array('helper' => $this, 'params' => array()));
     Mage::dispatchEvent('affiliateplus_helper_add_acc_to_url', array('url_params' => $urlParams));
     $params = $urlParams->getParams();
     if (count($params)) {
         $url .= '&' . http_build_query($urlParams->getParams(), '', '&');
     }
     return $url;
 }
Example #5
0
    /**
     * Run PEAR command with html output console style
     *
     * @param array|Varien_Object $runParams command, options, params,
     *        comment, success_callback, failure_callback
     */
    public function runHtmlConsole($runParams)
    {
        ob_implicit_flush();
        $fe = $this->getFrontend();
        $oldLogStream = $fe->getLogStream();
        $fe->setLogStream('stdout');
        if ($runParams instanceof Varien_Object) {
            $run = $runParams;
        } elseif (is_array($runParams)) {
            $run = new Varien_Object($runParams);
        } elseif (is_string($runParams)) {
            $run = new Varien_Object(array('title' => $runParams));
        } else {
            throw Varien_Exception("Invalid run parameters");
        }
        ?>
<html><head><style type="text/css">
body { margin:0px; padding:3px; background:black; color:white; }
pre { font:normal 11px Courier New, serif; color:#2EC029; }
</style></head><body>
<?php 
        echo "<pre>" . $run->getComment();
        if ($command = $run->getCommand()) {
            $result = $this->run($command, $run->getOptions(), $run->getParams());
            if ($result instanceof PEAR_Error) {
                echo "\r\n\r\nPEAR ERROR: " . $result->getMessage();
            }
            echo '</pre><script type="text/javascript">';
            if ($result instanceof PEAR_Error) {
                if ($callback = $run->getFailureCallback()) {
                    call_user_func_array($callback, array($result));
                }
            } else {
                if ($callback = $run->getSuccessCallback()) {
                    call_user_func_array($callback, array($result));
                }
            }
            echo '</script>';
        } else {
            $result = false;
            echo '</pre>';
        }
        ?>
<script type="text/javascript">
if (!auto_scroll) {
    var auto_scroll = window.setInterval("document.body.scrollTop+=2", 10);
}
</script>
</body></html>
<?php 
        $fe->setLogStream($oldLogStream);
        return $result;
    }
Example #6
0
 /**
  * Draw packages block
  *
  * @param  Zend_Pdf_Page $page
  * @return Mage_Sales_Model_Order_Pdf_Shipment_Packaging
  */
 protected function _drawPackageBlock(Zend_Pdf_Page $page)
 {
     if ($this->getPackageShippingBlock()) {
         $packaging = $this->getPackageShippingBlock();
     } else {
         $packaging = Mage::getBlockSingleton('adminhtml/sales_order_shipment_packaging');
     }
     $packages = $packaging->getPackages();
     $packageNum = 1;
     foreach ($packages as $packageId => $package) {
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->drawRectangle(25, $this->y + 15, 190, $this->y - 35);
         $page->drawRectangle(190, $this->y + 15, 350, $this->y - 35);
         $page->drawRectangle(350, $this->y + 15, 570, $this->y - 35);
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $page->drawRectangle(520, $this->y + 15, 570, $this->y - 5);
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $packageText = Mage::helper('sales')->__('Package') . ' ' . $packageNum;
         $page->drawText($packageText, 525, $this->y, 'UTF-8');
         $packageNum++;
         $package = new Varien_Object($package);
         $params = new Varien_Object($package->getParams());
         $dimensionUnits = Mage::helper('usa')->getMeasureDimensionName($params->getDimensionUnits());
         $typeText = Mage::helper('sales')->__('Type') . ' : ' . $packaging->getContainerTypeByCode($params->getContainer());
         $page->drawText($typeText, 35, $this->y, 'UTF-8');
         if ($params->getLength() != null) {
             $lengthText = $params->getLength() . ' ' . $dimensionUnits;
         } else {
             $lengthText = '--';
         }
         $lengthText = Mage::helper('sales')->__('Length') . ' : ' . $lengthText;
         $page->drawText($lengthText, 200, $this->y, 'UTF-8');
         if ($params->getDeliveryConfirmation() != null) {
             $confirmationText = Mage::helper('sales')->__('Signature Confirmation') . ' : ' . $packaging->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation());
             $page->drawText($confirmationText, 355, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 10;
         if ($packaging->displayCustomsValue() != null) {
             $customsValueText = Mage::helper('sales')->__('Customs Value') . ' : ' . $packaging->displayPrice($params->getCustomsValue());
             $page->drawText($customsValueText, 35, $this->y, 'UTF-8');
         }
         if ($params->getWidth() != null) {
             $widthText = $params->getWidth() . ' ' . $dimensionUnits;
         } else {
             $widthText = '--';
         }
         $widthText = Mage::helper('sales')->__('Width') . ' : ' . $widthText;
         $page->drawText($widthText, 200, $this->y, 'UTF-8');
         if ($params->getContentType() != null) {
             if ($params->getContentType() == 'OTHER') {
                 $contentsValue = $params->getContentTypeOther();
             } else {
                 $contentsValue = $packaging->getContentTypeByCode($params->getContentType());
             }
             $contentsText = Mage::helper('sales')->__('Contents') . ' : ' . $contentsValue;
             $page->drawText($contentsText, 355, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 10;
         $weightText = Mage::helper('sales')->__('Total Weight') . ' : ' . $params->getWeight() . ' ' . Mage::helper('usa')->getMeasureWeightName($params->getWeightUnits());
         $page->drawText($weightText, 35, $this->y, 'UTF-8');
         if ($params->getHeight() != null) {
             $heightText = $params->getHeight() . ' ' . $dimensionUnits;
         } else {
             $heightText = '--';
         }
         $heightText = Mage::helper('sales')->__('Height') . ' : ' . $heightText;
         $page->drawText($heightText, 200, $this->y, 'UTF-8');
         $this->y = $this->y - 10;
         if ($params->getSize()) {
             $sizeText = Mage::helper('sales')->__('Size') . ' : ' . ucfirst(strtolower($params->getSize()));
             $page->drawText($sizeText, 35, $this->y, 'UTF-8');
         }
         if ($params->getGirth() != null) {
             $dimensionGirthUnits = Mage::helper('usa')->getMeasureDimensionName($params->getGirthDimensionUnits());
             $girthText = Mage::helper('sales')->__('Girth') . ' : ' . $params->getGirth() . ' ' . $dimensionGirthUnits;
             $page->drawText($girthText, 200, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 5;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $page->drawRectangle(25, $this->y, 570, $this->y - 30 - count($package->getItems()) * 12);
         $this->y = $this->y - 10;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $page->drawText(Mage::helper('sales')->__('Items in the Package'), 30, $this->y, 'UTF-8');
         $txtIndent = 5;
         $itemCollsNumber = $packaging->displayCustomsValue() ? 5 : 4;
         $itemCollsX[0] = 30;
         //  coordinate for Product name
         $itemCollsX[1] = 250;
         // coordinate for Product name
         $itemCollsXEnd = 565;
         $itemCollsXStep = round(($itemCollsXEnd - $itemCollsX[1]) / ($itemCollsNumber - 1));
         // calculate coordinates for all other cells (Weight, Customs Value, Qty Ordered, Qty)
         for ($i = 2; $i <= $itemCollsNumber; $i++) {
             $itemCollsX[$i] = $itemCollsX[$i - 1] + $itemCollsXStep;
         }
         $i = 0;
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsXEnd, $this->y - 15);
         $this->y = $this->y - 12;
         $i = 0;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $page->drawText(Mage::helper('sales')->__('Product'), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Weight'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         if ($packaging->displayCustomsValue()) {
             $page->drawText(Mage::helper('sales')->__('Customs Value'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         }
         $page->drawText(Mage::helper('sales')->__('Qty Ordered'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Qty'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         $i = 0;
         foreach ($package->getItems() as $itemId => $item) {
             $item = new Varien_Object($item);
             $i = 0;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsXEnd, $this->y - 15);
             $this->y = $this->y - 12;
             $i = 0;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
             $page->drawText($item->getName(), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
             $page->drawText($item->getWeight(), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             if ($packaging->displayCustomsValue()) {
                 $page->drawText($packaging->displayPrice($item->getCustomsValue()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             }
             $page->drawText($packaging->getQtyOrderedItem($item->getOrderItemId()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             $page->drawText($item->getQty() * 1, $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 30;
     }
     return $this;
 }
 public function getAffiliateLink($url, $identifyCode, $store = null)
 {
     if (is_null($store)) {
         $store = Mage::app()->getStore();
     }
     $url = Mage::helper('affiliateplus/url')->getUrlLink($url);
     //hainh 29-07-2014
     $referParam = Mage::helper('affiliateplus/url')->getPersonalUrlParameter();
     if (Mage::getStoreConfig('affiliateplus/general/url_param_value') == 2) {
         $account = Mage::getModel('affiliateplus/account')->loadByIdentifyCode($identifyCode);
         if ($account->getId()) {
             $identifyCode = $account->getAccountId();
         }
     }
     if (strpos($url, '?')) {
         $url .= '&' . $referParam . '=' . $identifyCode;
     } else {
         $url .= '?' . $referParam . '=' . $identifyCode;
     }
     //end editing
     // Changed By Adam: 10/11/2014: Fix loi khi chay multiple website nhung ko co default store view
     if (Mage::app()->getDefaultStoreView() && $store->getId() != Mage::app()->getDefaultStoreView()->getId()) {
         $url .= '&___store=' . $store->getCode();
     }
     $urlParams = new Varien_Object(array('helper' => $this, 'params' => array()));
     Mage::dispatchEvent('affiliateplus_helper_add_acc_to_url', array('url_params' => $urlParams));
     $params = $urlParams->getParams();
     if (count($params)) {
         $url .= '&' . http_build_query($urlParams->getParams(), '', '&');
     }
     return $url;
 }
 /**
  * Add by blanka 29/11/2012
  * 
  */
 public function confirmRequestAction()
 {
     // Changed By Adam 28/07/2014
     if (!Mage::helper('affiliateplus')->isAffiliateModuleEnabled()) {
         return $this->_redirectUrl(Mage::getBaseUrl());
     }
     if (!Mage::helper('magenotification')->checkLicenseKeyFrontController($this)) {
         return;
     }
     $session = Mage::getSingleton('affiliateplus/session');
     $account = $session->getAccount();
     $params = $this->getRequest()->getPost();
     if (!count($params)) {
         $params = $this->getRequest()->getParams();
     }
     if (Mage::getModel('affiliateplus/payment')->setAccountId($account->getId())->hasWaitingPayment()) {
         $this->_getCoreSession()->addError($this->__('You are having a pending request!'));
         return $this->_redirect('affiliateplus/index/payments');
     }
     if ($this->_getAccountHelper()->accountNotLogin()) {
         return $this->_redirect('affiliateplus/account/login');
     }
     if (!isset($params['payment_method'])) {
         $storeId = Mage::app()->getStore()->getId();
         $paymentMethods = Mage::helper('affiliateplus/payment')->getAvailablePayment($storeId);
         /* Changed By Adam 23/10/2013 - hainh update 24-04-2014 */
         if (count($paymentMethods) == 1) {
             foreach ($paymentMethods as $code => $value) {
                 $params['payment_method'] = $code;
             }
         } else {
             $params['payment_method'] = 'paypal';
         }
         if ($params['payment_method'] == 'paypal') {
             if (isset($params['paypal_email']) && $params['paypal_email']) {
                 $params['email'] = $params['paypal_email'];
             } else {
                 $params['email'] = $account->getPaypalEmail();
             }
         } else {
             if ($params['payment_method'] == 'moneybooker') {
                 if (isset($params['moneybooker_email']) && $params['moneybooker_email']) {
                     $params['email'] = $params['moneybooker_email'];
                 } else {
                     $params['email'] = $account->getMoneybookerEmail();
                 }
             }
         }
     } else {
         $params['payment_method'] = $params['payment_method'];
         if ($params['payment_method'] == 'paypal') {
             if (isset($params['paypal_email']) && $params['paypal_email']) {
                 $params['email'] = $params['paypal_email'];
             } else {
                 $params['email'] = $account->getPaypalEmail();
             }
         } else {
             if ($params['payment_method'] == 'moneybooker') {
                 if (isset($params['moneybooker_email']) && $params['moneybooker_email']) {
                     $params['email'] = $params['moneybooker_email'];
                 } else {
                     $params['email'] = $account->getMoneybookerEmail();
                 }
             }
         }
     }
     /* check email verify */
     if (isset($params['payment_method']) && $params['payment_method']) {
         $require = Mage::helper('affiliateplus/payment')->isRequireAuthentication($params['payment_method']);
         if ($require) {
             if (isset($params['email']) && $params['email']) {
                 $verify = Mage::getModel('affiliateplus/payment_verify')->loadExist($account->getId(), $params['email'], $params['payment_method']);
                 if (!$verify->isVerified()) {
                     $this->_getCoreSession()->addError('The email is not authenticated. Please verify authentication code.');
                     $url = Mage::getUrl('affiliates/index/paymentForm');
                     return $this->_redirectUrl($url);
                 }
             }
         }
     }
     /* end */
     $paramObject = new Varien_Object(array('params' => $params));
     Mage::dispatchEvent('affiliateplus_payment_prepare_data', array('payment_data' => $paramObject, 'file' => $_FILES));
     $params = $paramObject->getParams();
     $payment = Mage::getModel('affiliateplus/payment');
     $payment->setData($params);
     Mage::register('confirm_payment_data', $payment);
     $session->setPayment($payment);
     $session->setPaymentMethod($payment->getPaymentMethod());
     if ($payment->getAmount()) {
         $session->setPaymentAmount($payment->getAmount());
     }
     $this->loadLayout();
     $this->getLayout()->getBlock('head')->setTitle($this->__('Confirm'));
     $this->renderLayout();
 }
Example #9
0
 public function controllerActionPredispatch($observer)
 {
     $controller = $observer['controller_action'];
     $request = $controller->getRequest();
     /* Add event before run dispatch of affiliate system - added by David (01/11) */
     Mage::dispatchEvent('affiliateplus_controller_action_predispatch', array('request' => $request));
     /* magic add call funtion saveClickAction 23/10/2012 */
     $this->saveClickAction($observer);
     /* end */
     $accountCode = $request->getParam('acc');
     if (!$accountCode && $request->getParam('df08b0441bac900')) {
         $resource = Mage::getSingleton('core/resource');
         $read = $resource->getConnection('core_read');
         $write = $resource->getConnection('core_write');
         try {
             $select = $read->select()->from($resource->getTableName('affiliate_referral'), array('customer_id'))->where("identify_code=?", trim($request->getParam('df08b0441bac900')));
             $result = $read->fetchRow($select);
             $oldCustomerId = $result['customer_id'];
             if ($oldCustomerId) {
                 $accountCode = Mage::getModel('affiliateplus/account')->loadByCustomerId($oldCustomerId)->getIdentifyCode();
             }
         } catch (Exception $e) {
         }
     }
     if (!$accountCode) {
         return $this;
     }
     if ($account = Mage::getSingleton('affiliateplus/session')->getAccount()) {
         if ($account->getIdentifyCode() == $accountCode) {
             return $this;
         }
     }
     /* Magic 19/10/2012 */
     $account = Mage::getModel('affiliateplus/account')->loadByIdentifyCode($accountCode);
     if (!$account->getId()) {
         return $this;
     }
     $storeId = Mage::app()->getStore()->getId();
     if (!$storeId) {
         return $this;
     }
     /* David - remove storage tracking to referer table
             $ipAddress = $request->getClientIp();
             $refererModel = Mage::getModel('affiliateplus/referer');
     
             $refererCollection = $refererModel->getCollection()
                     ->addFieldToFilter('account_id', $account->getId());
             if (!in_array($ipAddress, $refererCollection->getIpListArray())) {
                 $account->setUniqueClicks($account->getUniqueClicks() + 1);
                 try {
                     $account->save();
                 } catch (Exception $e) {
                     
                 }
             }
     
             $account->setStoreId($storeId)->load($account->getId());
             $refererCollection->addFieldToFilter('store_id', $storeId);
             if (!in_array($ipAddress, $refererCollection->getIpListArray()))
                 if ($account->getUniqueClicksInStore())
                     $account->setUniqueClicks($account->getUniqueClicks() + 1);
                 else
                     $account->setUniqueClicks(1);
             $account->setTotalClicks($account->getTotalClicks() + 1);
             try {
                 $account->save();
             } catch (Exception $e) {
                 
             }
     
             $httpReferrerInfo = parse_url($request->getServer('HTTP_REFERER'));
             $referer = isset($httpReferrerInfo['host']) ? $httpReferrerInfo['host'] : '';
             $refererModel->loadExistReferer($account->getId(), $referer, $storeId, $request->getOriginalRequest()->getPathInfo());
             //Zend_Debug::dump($refererModel->getData());die('1');
             Mage::dispatchEvent('affiliateplus_referrer_load_existed', array(
                 'referrer_model' => $refererModel,
                 'controller_action' => $controller,
             ));
     
             try {
                 $refererModel->setIpAddress($ipAddress)->save();
             } catch (Exception $e) {
                 
             }
             */
     /*
      * end
      */
     $expiredTime = $this->_getConfigHelper()->getGeneralConfig('expired_time');
     $cookie = Mage::getSingleton('core/cookie');
     if ($expiredTime) {
         $cookie->setLifeTime(intval($expiredTime) * 86400);
     }
     $current_index = $cookie->get('affiliateplus_map_index');
     $addCookie = new Varien_Object(array('existed' => false));
     for ($i = intval($current_index); $i > 0; $i--) {
         if ($cookie->get("affiliateplus_account_code_{$i}") == $accountCode) {
             $addCookie->setExisted(true);
             $addCookie->setIndex($i);
             Mage::dispatchEvent('affiliateplus_controller_action_predispatch_add_cookie', array('request' => $request, 'add_cookie' => $addCookie, 'cookie' => $cookie));
             if ($addCookie->getExisted()) {
                 // change latest account
                 $curI = intval($current_index);
                 for ($j = $i; $j < $curI; $j++) {
                     $cookie->set("affiliateplus_account_code_{$j}", $cookie->get("affiliateplus_account_code_" . intval($j + 1)));
                 }
                 $cookie->set("affiliateplus_account_code_{$curI}", $accountCode);
                 return $this;
             }
         }
     }
     $current_index = $current_index ? intval($current_index) + 1 : 1;
     $cookie->set('affiliateplus_map_index', $current_index);
     $cookie->set("affiliateplus_account_code_{$current_index}", $accountCode);
     $cookieParams = new Varien_Object(array('params' => array()));
     Mage::dispatchEvent('affiliateplus_controller_action_predispatch_observer', array('controller_action' => $controller, 'cookie_params' => $cookieParams, 'cookie' => $cookie));
     foreach ($cookieParams->getParams() as $key => $value) {
         $cookie->set("affiliateplus_{$key}" . "_{$current_index}", $value);
     }
     /* Magic comment 19/10/2012 and put upward  */
     /*
      $account = Mage::getModel('affiliateplus/account')->loadByIdentifyCode($accountCode);
      if (!$account->getId())
      return $this;
      $storeId = Mage::app()->getStore()->getId();
      if (!$storeId)
      return $this;
      $ipAddress = $request->getClientIp();
      $refererModel = Mage::getModel('affiliateplus/referer');
     
      $refererCollection = $refererModel->getCollection()
      ->addFieldToFilter('account_id', $account->getId());
      if (!in_array($ipAddress, $refererCollection->getIpListArray())) {
      $account->setUniqueClicks($account->getUniqueClicks() + 1);
      try {
      $account->save();
      } catch (Exception $e) {
     
      }
      }
     
      $account->setStoreId($storeId)->load($account->getId());
      $refererCollection->addFieldToFilter('store_id', $storeId);
      if (!in_array($ipAddress, $refererCollection->getIpListArray()))
      if ($account->getUniqueClicksInStore())
      $account->setUniqueClicks($account->getUniqueClicks() + 1);
      else
      $account->setUniqueClicks(1);
      $account->setTotalClicks($account->getTotalClicks() + 1);
      try {
      $account->save();
      } catch (Exception $e) {
     
      }
     
      $httpReferrerInfo = parse_url($request->getServer('HTTP_REFERER'));
      $referer = isset($httpReferrerInfo['host']) ? $httpReferrerInfo['host'] : '';
      $refererModel->loadExistReferer($account->getId(), $referer, $storeId, $request->getOriginalRequest()->getPathInfo());
      //Zend_Debug::dump($refererModel->getData());die('1');
      Mage::dispatchEvent('affiliateplus_referrer_load_existed', array(
      'referrer_model' => $refererModel,
      'controller_action' => $controller,
      ));
     
      try {
      $refererModel->setIpAddress($ipAddress)->save();
      } catch (Exception $e) {
     
      }
     */
     return $this;
 }
Example #10
0
 public function controllerActionPredispatch($observer)
 {
     $controller = $observer['controller_action'];
     $request = $controller->getRequest();
     $accountCode = $request->getParam('acc');
     if (!$accountCode && $request->getParam('df08b0441bac900')) {
         $resource = Mage::getSingleton('core/resource');
         $read = $resource->getConnection('core_read');
         $write = $resource->getConnection('core_write');
         try {
             $select = $read->select()->from($resource->getTableName('affiliate_referral'), array('customer_id'))->where("identify_code=?", trim($request->getParam('df08b0441bac900')));
             $result = $read->fetchRow($select);
             $oldCustomerId = $result['customer_id'];
             if ($oldCustomerId) {
                 $accountCode = Mage::getModel('affiliateplus/account')->loadByCustomerId($oldCustomerId)->getIdentifyCode();
             }
         } catch (Exception $e) {
         }
     }
     if (!$accountCode) {
         return $this;
     }
     if ($account = Mage::getSingleton('affiliateplus/session')->getAccount()) {
         if ($account->getIdentifyCode() == $accountCode) {
             return $this;
         }
     }
     $expiredTime = $this->_getConfigHelper()->getGeneralConfig('expired_time');
     $cookie = Mage::getSingleton('core/cookie');
     if ($expiredTime) {
         $cookie->setLifeTime(intval($expiredTime) * 86400);
     }
     $current_index = $cookie->get('affiliateplus_map_index');
     $addCookie = new Varien_Object(array('existed' => false));
     for ($i = intval($current_index); $i > 0; $i--) {
         if ($cookie->get("affiliateplus_account_code_{$i}") == $accountCode) {
             $addCookie->setExisted(true);
             $addCookie->setIndex($i);
             Mage::dispatchEvent('affiliateplus_controller_action_predispatch_add_cookie', array('request' => $request, 'add_cookie' => $addCookie, 'cookie' => $cookie));
             if ($addCookie->getExisted()) {
                 return $this;
             }
         }
     }
     $current_index = $current_index ? intval($current_index) + 1 : 1;
     $cookie->set('affiliateplus_map_index', $current_index);
     $cookie->set("affiliateplus_account_code_{$current_index}", $accountCode);
     $cookieParams = new Varien_Object(array('params' => array()));
     Mage::dispatchEvent('affiliateplus_controller_action_predispatch_observer', array('controller_action' => $controller, 'cookie_params' => $cookieParams, 'cookie' => $cookie));
     foreach ($cookieParams->getParams() as $key => $value) {
         $cookie->set("affiliateplus_{$key}" . "_{$current_index}", $value);
     }
     $account = Mage::getModel('affiliateplus/account')->loadByIdentifyCode($accountCode);
     if (!$account->getId()) {
         return $this;
     }
     $storeId = Mage::app()->getStore()->getId();
     if (!$storeId) {
         return $this;
     }
     $ipAddress = $request->getClientIp();
     $refererModel = Mage::getModel('affiliateplus/referer');
     $refererCollection = $refererModel->getCollection()->addFieldToFilter('account_id', $account->getId());
     if (!in_array($ipAddress, $refererCollection->getIpListArray())) {
         $account->setUniqueClicks($account->getUniqueClicks() + 1);
         try {
             $account->save();
         } catch (Exception $e) {
         }
     }
     $account->setStoreId($storeId)->load($account->getId());
     $refererCollection->addFieldToFilter('store_id', $storeId);
     if (!in_array($ipAddress, $refererCollection->getIpListArray())) {
         if ($account->getUniqueClicksInStore()) {
             $account->setUniqueClicks($account->getUniqueClicks() + 1);
         } else {
             $account->setUniqueClicks(1);
         }
     }
     $account->setTotalClicks($account->getTotalClicks() + 1);
     try {
         $account->save();
     } catch (Exception $e) {
     }
     $httpReferrerInfo = parse_url($request->getServer('HTTP_REFERER'));
     $referer = $httpReferrerInfo['host'];
     $refererModel->loadExistReferer($account->getId(), $referer, $storeId, $request->getOriginalRequest()->getPathInfo());
     Mage::dispatchEvent('affiliateplus_referrer_load_existed', array('referrer_model' => $refererModel, 'controller_action' => $controller));
     try {
         $refererModel->setIpAddress($ipAddress)->save();
     } catch (Exception $e) {
     }
     return $this;
 }