News:

Support the VirtueMart project and become a member

Main Menu

Filtering coupon codes doesn't work

Started by sandomatyas, January 28, 2017, 14:31:15 PM

Previous topic - Next topic

sandomatyas

I can't filter coupons on admin. There is a search field but its name is filter_ratings and the model doesn't do anything with that.
I applied a quick fix for myself but it should be fixed generally.

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

Changed filter_ratings to filter_coupon in administrator/components/com_virtuemart/views/coupon/tmpl/default.php (line 33 and 35)
Old:
<input type="text" name="filter_ratings" value="<?php echo vRequest::getVar('filter_ratings'''); ?>" />
<button class="btn btn-small" onclick="this.form.submit();"><?php echo vmText::_('COM_VIRTUEMART_GO'); ?></button>
<button class="btn btn-small" onclick="document.adminForm.filter_ratings.value='';"><?php echo vmText::_('COM_VIRTUEMART_RESET'); ?></button>

New:

<input type="text" name="filter_coupon" value="<?php echo vRequest::getVar('filter_coupon'''); ?>" />
<button class="btn btn-small" onclick="this.form.submit();"><?php echo vmText::_('COM_VIRTUEMART_GO'); ?></button>
<button class="btn btn-small" onclick="document.adminForm.filter_coupon.value='';"><?php echo vmText::_('COM_VIRTUEMART_RESET'); ?></button>


Changed the view.html.php
From:

$coupons = $model->getCoupons();

To:

$filter_coupon = vRequest::getCmd('filter_coupon', false);
$coupons = $model->getCoupons($filter_coupon);


Changed the VirtueMartModelCoupon class
From

function getCoupons() {

$virtuemart_vendor_id = vmAccess::getVendorId();
$whereString = '';
if(!empty($virtuemart_vendor_id)){
$whereString = 'WHERE virtuemart_vendor_id="'.$virtuemart_vendor_id.'"';
}
$filter = JFactory::getApplication()->input->get('filter_ratings', '');
if(!empty($filter)) $whereString .= 'AND coupon_code LIKE "%'.$filter.'%"';

return $this->_data = $this->exeSortSearchListQuery(0,'*',' FROM `#__virtuemart_coupons`',$whereString,'',$this->_getOrdering());
}


To:

function getCoupons($filterCoupon) {

$virtuemart_vendor_id = vmAccess::getVendorId();
$where = array();

if(!empty($virtuemart_vendor_id)){
$where[] = '`virtuemart_vendor_id`="'.$virtuemart_vendor_id.'"';
}
if($filterCoupon) {
$db = JFactory::getDBO();
$filterCouponS = '"%' . $db->escape( $filterCoupon, true ) . '%"' ;
$where[] = '`coupon_code` LIKE '.$filterCouponS;

}

$whereString = '';
if (count($where) > 0) $whereString = ' WHERE '.implode(' AND ', $where) ;

return $this->_data = $this->exeSortSearchListQuery(0,'*',' FROM `#__virtuemart_coupons`',$whereString,'',$this->_getOrdering());
}

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

Max,
perhaps
$filter_coupon = vRequest::getCmd('filter_coupon', false);
to
$filter_coupon = vRequest::getString('filter_coupon', false);
And
$db = JFactory::getDBO();
$filterCouponS = '"%' . $db->escape( $filterCoupon, true ) . '%"' ;

to
$filterCouponS = '"%' . $this->_db->escape( $filterCoupon, true ) . '%"' ;
In Joomla $this->_db is in the parent model class

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/