function generateCoupon(&$allresults, $i, &$user) { list($percent, $gift, $value, $name) = explode('|', $allresults[1][$i]); $db =& JFactory::getDBO(); $key = JUserHelper::genrandompassword(5); $value = str_replace(',', '.', $value); $name = str_replace(array('[name]', '[subid]', '[email]', '[key]', '[value]'), array($user->name, $user->subid, $user->email, $key, $value), $name); $db->setQuery('INSERT INTO ' . acymailing::table('vm_coupons', false) . '(`coupon_code`,`percent_or_total`,`coupon_type`,`coupon_value`) VALUES (' . $db->Quote($name) . ',' . $db->Quote($percent) . ',' . $db->Quote($gift) . ',' . $db->Quote($value) . ')'); $db->query(); return $name; }
function generateCoupon(&$allresults, $i, &$user) { list($minimum_order, $quota, $start, $end, $percent_amount, $flat_amount, $currency_id, $code, $product_id) = explode('|', $allresults[1][$i]); jimport('joomla.user.helper'); $key = JUserHelper::genrandompassword(5); if (!hikashop_level(1)) { $minimum_order = 0; $quota = ''; $product_id = ''; } if ($percent_amount > 0) { $value = $percent_amount; } else { $value = $flat_amount; } $value = str_replace(',', '.', $value); if ($start) { $start = hikashop_getTime($start); } if ($end) { $end = hikashop_getTime($end); } $clean_name = strtoupper($user->name); $space = strpos($clean_name, ' '); if (!empty($space)) { $clean_name = substr($clean_name, 0, $space); } $code = str_replace(array('[name]', '[clean_name]', '[subid]', '[email]', '[key]', '[flat]', '[percent]', '[value]', '[prodid]'), array($user->name, $clean_name, $user->subid, $user->email, $key, $flat_amount, $percent_amount, $value, $product_id), $code); $this->db->setQuery('INSERT IGNORE INTO ' . acymailing_table('hikashop_discount', false) . '( `discount_code`, `discount_percent_amount`, `discount_flat_amount`, `discount_type`, `discount_start`, `discount_end`, `discount_minimum_order`, `discount_quota`, `discount_currency_id`, `discount_product_id`, `discount_published` ) VALUES (' . $this->db->Quote($code) . ',' . $this->db->Quote($percent_amount) . ',' . $this->db->Quote($flat_amount) . ',\'coupon\',' . $this->db->Quote($start) . ',' . $this->db->Quote($end) . ',' . $this->db->Quote($minimum_order) . ',' . $this->db->Quote($quota) . ',' . $this->db->Quote(hikashop_getCurrency()) . ',' . $this->db->Quote($product_id) . ', 1)'); $this->db->query(); return $code; }