function fn_affiliate_pre_promotion_check_coupon(&$coupon_code) { if (empty($coupon_code) || !defined('CHECKOUT')) { return false; } $orig_coupon = $coupon_code; $prefix = Registry::get('addons.affiliate.coupon_prefix_delim'); $delim_len = strlen($prefix); if (Registry::get('addons.affiliate.use_affiliate_id') == 'Y' && !empty($delim_len)) { if (($delim_idx = strpos($coupon_code, $prefix)) != false) { $delim_chr = substr($coupon_code, $delim_idx, $delim_len); if ($delim_chr == $prefix) { $partner_id = intval(substr($coupon_code, 0, $delim_idx)); if (!empty($partner_id)) { $coupon_code = substr($coupon_code, $delim_idx + $delim_len); } } } } else { $prefix_length = 10; $delim_chr = substr($coupon_code, $prefix_length, $delim_len); if ($delim_chr == $prefix) { $partner_code = substr($coupon_code, 0, $prefix_length); $partner_id = fn_any2dec($partner_code); if (!empty($partner_id)) { if ($partner_code == fn_dec2any($partner_id)) { $coupon_code = substr($coupon_code, $prefix_length + $delim_len); } else { $partner_id = 0; } } } } if (!empty($partner_id)) { $plans_data = fn_get_affiliate_plan_data_by_partner_id($partner_id, true); $valid_coupon = false; if (!empty($plans_data['promotion_ids'])) { $params = array('promotion_id' => array_keys($plans_data['promotion_ids']), 'expand' => true); list($coupons) = fn_get_promotions($params); foreach ($coupons as $coupon_data) { foreach ($coupon_data['conditions']['conditions'] as $cnd) { if ($cnd['condition'] == 'coupon_code' && $coupon_code == $cnd['value']) { $valid_coupon = true; break; } } if ($valid_coupon) { break; } } } if (!$valid_coupon) { $partner_id = 0; $coupon_code = $orig_coupon; } } if (!empty($partner_id)) { Registry::set('affiliate_partner_id', $partner_id); return true; } else { return false; } }
<?php // // $Id: order_management.post.php 7932 2009-09-02 08:18:08Z lexa $ // if (!defined('AREA')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($mode == 'update_totals') { $cart =& $_SESSION['cart']; // Update Affiliate code if (Registry::get('addons.affiliate.show_affiliate_code') == 'Y' || !empty($cart['order_id']) && $cart['affiliate']['is_payouts'] != 'Y') { $cart['affiliate']['code'] = empty($_REQUEST['affiliate_code']) ? '' : $_REQUEST['affiliate_code']; $_partner_id = fn_any2dec($cart['affiliate']['code']); $_partner_data = db_get_row("SELECT firstname, lastname, user_id as partner_id FROM ?:users WHERE user_id = ?i AND user_type = 'P'", $_partner_id); if (!empty($_partner_data)) { $cart['affiliate'] = $_partner_data + $cart['affiliate']; $_SESSION['partner_data'] = array('partner_id' => $cart['affiliate']['partner_id'], 'is_payouts' => 'N'); } else { unset($cart['affiliate']['partner_id']); unset($cart['affiliate']['firstname']); unset($cart['affiliate']['lastname']); unset($_SESSION['partner_data']); } } } return; }