0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: coupon.php.tar
home/academiac/www/administrator/components/com_virtuemart/models/coupon.php 0000604 00000005547 15137220072 0023621 0 ustar 00 <?php /** * * Data module for shop coupons * * @package VirtueMart * @subpackage Coupon * @author RickG * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id$ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); if(!class_exists('VmModel'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php'); /** * Model class for shop coupons * * @package VirtueMart * @subpackage Coupon * @author RickG */ class VirtueMartModelCoupon extends VmModel { /** * constructs a VmModel * setMainTable defines the maintable of the model * @author Max Milbers */ function __construct() { parent::__construct(); $this->setMainTable('coupons'); } /** * Retrieve the detail record for the current $id if the data has not already been loaded. * * @author RickG */ function getCoupon() { $db = JFactory::getDBO(); if (empty($this->_data)) { $this->_data = $this->getTable('coupons'); $this->_data->load((int)$this->_id); } if (!$this->_data) { $this->_data = new stdClass(); $this->_id = 0; $this->_data = null; } return $this->_data; } /** * Bind the post data to the coupon table and save it * * @author RickG, Oscar van Eijk * @return mixed False if the save was unsuccessful, the coupon ID otherwise. */ function store(&$data) { $table = $this->getTable('coupons'); //$data = JRequest::get('post'); $table->bindChecknStore($data); // Convert selected dates to MySQL format for storing. if ($data['coupon_start_date']) { $startDate = JFactory::getDate($data['coupon_start_date']); $data['coupon_start_date'] = $startDate->toMySQL(); } if ($data['coupon_expiry_date']) { $expireDate = JFactory::getDate($data['coupon_expiry_date']); $data['coupon_expiry_date'] = $expireDate->toMySQL(); } parent::store($data); return $table->virtuemart_coupon_id; } /** * Retireve a list of coupons from the database. * * @author RickG * @return object List of coupon objects */ function getCoupons() { $whereString = ''; // if (count($where) > 0) $whereString = ' WHERE '.implode(' AND ', $where) ; return $this->_data = $this->exeSortSearchListQuery(0,'*',' FROM `#__virtuemart_coupons`',$whereString,'',$this->_getOrdering()); } } // pure php no closing tag home/academiac/www/administrator/components/com_virtuemart/controllers/coupon.php 0000604 00000002357 15137441262 0024706 0 ustar 00 <?php /** * * Coupon controller * * @package VirtueMart * @subpackage Coupon * @author RickG * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: coupon.php 5399 2012-02-08 19:29:45Z Milbo $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); // Load the controller framework jimport('joomla.application.component.controller'); if(!class_exists('VmController'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmcontroller.php'); /** * Coupon Controller * * @package VirtueMart * @subpackage Coupon * @author RickG */ class VirtuemartControllerCoupon extends VmController { /** * Method to display the view * * @access public * @author */ function __construct() { parent::__construct(); } } // pure php no closing tag home/academiac/www/components/com_virtuemart/helpers/coupon.php 0000604 00000013425 15140113763 0021114 0 ustar 00 <?php /** * Front-end Coupon handling functions * * @package VirtueMart * @subpackage Helpers * @author Oscar van Eijk * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses * @version $Id: coupon.php 5460 2012-02-16 16:38:34Z alatak $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); abstract class CouponHelper { /** * Check if the given coupon code exists, is (still) valid and valid for the total order amount * @param string $_code Coupon code * @param float $_billTotal Total amount for the order * @author Oscar van Eijk * @author Max Milbers * @return string Empty when the code is valid, otherwise the error message */ static public function ValidateCouponCode($_code, $_billTotal) { $couponData = 0; JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmValidateCouponCode', array($_code, $_billTotal)); if(!empty($returnValues)){ foreach ($returnValues as $returnValue) { if ($returnValue !== null ) { //Take a look on this seyi, I am not sure about that, but it should work at least simular note by Max return $returnValue; } } } if(empty($couponData)){ $_db = JFactory::getDBO(); $_q = 'SELECT IF( NOW() >= `coupon_start_date` , 1, 0 ) AS started ' . ', `coupon_start_date` ' . ', IFNULL(0, IF( NOW() > `coupon_expiry_date`, 1, 0 ) ) AS ended' . ', `coupon_value_valid` ' . ', `coupon_used` ' . 'FROM `#__virtuemart_coupons` ' . 'WHERE `coupon_code` = "' . $_db->getEscaped($_code) . '"'; $_db->setQuery($_q); $couponData = $_db->loadObject(); } if (!$couponData) { return JText::_('COM_VIRTUEMART_COUPON_CODE_INVALID'); } if ($couponData->coupon_used) { $session = JFactory::getSession(); $session_id = $session->getId(); if ($couponData->coupon_used != $session_id) { return JText::_('COM_VIRTUEMART_COUPON_CODE_INVALID'); } } if (!$couponData->started) { return JText::_('COM_VIRTUEMART_COUPON_CODE_NOTYET') . $couponData->coupon_start_date; } if ($couponData->ended) { self::RemoveCoupon($_code, true); return JText::_('COM_VIRTUEMART_COUPON_CODE_EXPIRED'); } if ($_billTotal < $couponData->coupon_value_valid) { if (!class_exists('CurrencyDisplay')) require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); $currency = CurrencyDisplay::getInstance(); $coupon_value_valid = $currency->priceDisplay($couponData->coupon_value_valid); return JText::_('COM_VIRTUEMART_COUPON_CODE_TOOLOW') . " ".$coupon_value_valid; } return ''; } /** * Get the details for a given coupon * @param string $_code Coupon code * @author Oscar van Eijk * @return object Coupon details */ static public function getCouponDetails($_code) { $_db = JFactory::getDBO(); $_q = 'SELECT `percent_or_total` ' . ', `coupon_type` ' . ', `coupon_value` ' . 'FROM `#__virtuemart_coupons` ' . 'WHERE `coupon_code` = "' . $_db->getEscaped($_code) . '"'; $_db->setQuery($_q); return $_db->loadObject(); } /** * Remove a coupon from the database * @param $_code Coupon code * @param $_force True if the remove is forced. By default, only gift coupons are removed * @author Oscar van Eijk * @return boolean True on success */ static public function RemoveCoupon($_code, $_force = false) { JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmRemoveCoupon', array($_code, $_force)); if(!empty($returnValues)){ foreach ($returnValues as $returnValue) { if ($returnValue !== null ) { //Take a look on this seyi, I am not sure about that, but it should work at least simular note by Max //$couponData = $returnValue; return $returnValue; } } } if ($_force !== true) { $_data = self::getCouponDetails($_code); if ($_data->coupon_type != 'gift') { return true; } } $_db = JFactory::getDBO(); $_q = 'DELETE FROM `#__virtuemart_coupons` ' . 'WHERE `coupon_code` = "' . $_db->getEscaped($_code) . '"'; $_db->setQuery($_q); return ($_db->query() !== false); } /** * Remove a coupon from the database * @param $_code Coupon code * @param $_force True if the remove is forced. By default, only gift coupons are removed * @author Valérie Isaksen * @return boolean True on success */ static public function setInUseCoupon($code, $in_use=true){ JPluginHelper::importPlugin('vmcoupon'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmCouponInUse', array($code)); if(!empty($returnValues)){ foreach ($returnValues as $returnValue) { if ($returnValue !== null ) { return $returnValue; } } } $session = JFactory::getSession(); $coupon_used = $session->getId(); $db = JFactory::getDBO(); if (!$in_use) { $db = JFactory::getDBO(); $q = 'SELECT `coupon_used` ' . 'FROM `#__virtuemart_coupons` ' . 'WHERE `coupon_code` = "' . $db->getEscaped($code) . '"'; $db->setQuery($q); $coupon_session_id=$db->loadResult(); if ($coupon_used !=$coupon_session_id) { return; } $coupon_used=0; } $q = 'UPDATE `#__virtuemart_coupons` SET `coupon_used` = "' . $coupon_used . '" WHERE `coupon_type`= \'gift\' AND `coupon_code` = "' . $db->getEscaped($code) . '"'; $db->setQuery($q); return ($db->query() !== false); } }
©
2018.