Created
June 19, 2013 10:00
-
-
Save gunjanpatel/5813173 to your computer and use it in GitHub Desktop.
redSHOP discount for shopper group is not working. Apply this patch to fix discount for shopper group issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: components/com_redshop/helpers/product.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- components/com_redshop/helpers/product.php (revision ) | |
+++ components/com_redshop/helpers/product.php (revision ) | |
@@ -188,53 +188,78 @@ | |
public function getProductSpecialPrice($product_price, $discount_product_id, $product_id = 0) | |
{ | |
- $result = array(); | |
+ $result = array(); | |
- | |
- $where = ' WHERE 1=1'; | |
$categoryProduct = ''; | |
if ($product_id) | |
+ { | |
$categoryProduct = $this->getCategoryProduct($product_id); | |
+ } | |
- $q = "SELECT * FROM " . $this->_table_prefix . "discount_product "; | |
+ // Get shopper group Id | |
+ $userArr = $this->_session->get('rs_user'); | |
- $where .= " AND (discount_product_id IN ('" . $discount_product_id . "') OR FIND_IN_SET('" . $categoryProduct | |
- . "',category_ids) )"; | |
+ if (empty($userArr)) | |
+ { | |
+ $user = JFactory::getUser(); | |
+ $userArr = $this->_userhelper->createUserSession($user->id); | |
+ } | |
- $where .= " AND published =1 AND `start_date` <= " . time() . " AND `end_date` >= " . time(); | |
+ // Shopper Group Id from user session | |
+ $shopperGroupId = $userArr['rs_user_shopperGroup']; | |
- $orderby = " ORDER BY `amount` DESC LIMIT 0,1"; | |
+ $query = $this->_db->getQuery(true); | |
- $sel = $q . $where . $orderby; | |
+ // Prepare query. | |
+ $query->select('*'); | |
+ $query->from('#__redshop_discount_product'); | |
+ $query->where('published = 1'); | |
+ $query->where('(discount_product_id IN ("' . $discount_product_id . '") OR FIND_IN_SET("' . $categoryProduct . '",category_ids) )'); | |
+ $query->where('`start_date` <= ' . time()); | |
+ $query->where('`end_date` >= ' . time()); | |
+ $query->where('`discount_product_id` IN (SELECT `discount_product_id` FROM `#__redshop_discount_product_shoppers` WHERE `shopper_group_id` = "' . $shopperGroupId . '")'); | |
+ $query->order('`amount` DESC'); | |
- $this->_db->setQuery($sel); | |
+ // Inject the query and load the result. | |
+ $this->_db->setQuery($query); | |
$result = $this->_db->loadObject(); | |
- if (count($result) > 0) | |
+ // Check for a database error. | |
+ if ($this->_db->getErrorNum()) | |
{ | |
+ JError::raiseWarning(500, $db->getErrorMsg()); | |
+ | |
+ return array(); | |
+ } | |
+ | |
+ // Result is empty then return blank | |
+ if (count($result) <= 0) | |
+ { | |
+ return array(); | |
+ } | |
+ | |
- switch ($result->condition) | |
- { | |
- case 1: | |
+ switch ($result->condition) | |
+ { | |
+ case 1: | |
- $where .= ' AND `amount` >= "' . $product_price . '"'; | |
+ $query->where('`amount` >= "' . $product_price . '"'); | |
- break; | |
- case 2: | |
+ break; | |
+ case 2: | |
- $where .= ' AND `amount` = "' . $product_price . '"'; | |
+ $query->where('`amount` = "' . $product_price . '"'); | |
- break; | |
- case 3: | |
+ break; | |
+ case 3: | |
- $where .= ' AND `amount` <= "' . $product_price . '"'; | |
+ $query->where('`amount` <= "' . $product_price . '"'); | |
- break; | |
- } | |
+ break; | |
+ } | |
- $qry = $q . $where . $orderby; | |
- | |
- $this->_db->setQuery($qry); | |
+ $this->_db->setQuery($query); | |
- $result = $this->_db->loadObject(); | |
+ $result = $this->_db->loadObject(); | |
- return $result; | |
- } | |
- else | |
+ // Check for a database error. | |
+ if ($this->_db->getErrorNum()) | |
{ | |
- return; | |
+ JError::raiseWarning(500, $db->getErrorMsg()); | |
+ | |
+ return array(); | |
} | |
return $result; | |
@@ -279,7 +304,7 @@ | |
for ($i = 0; $i < count($res); $i++) | |
{ | |
- if ($res[$i]->discount_product_id != "" && $res[$i]->discount_product_id != 0) | |
+ if ($res[$i]->discount_product_id != "" && (int) $res[$i]->discount_product_id != 0) | |
{ | |
$discount_product_id .= "," . $res[$i]->discount_product_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment