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); } }