Skip to content

Commit

Permalink
Fix the issue with dash in sql
Browse files Browse the repository at this point in the history
  • Loading branch information
aytackokus committed Nov 25, 2020
1 parent 3c8a5f0 commit b7f8c89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions model/product-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function queryAttributesOrder() {
/**
* @var $v \WC_Product_Attribute
*/
if( $v->get_variation() ) {
if ( $v->get_variation() ) {
$keys[ 'attribute_' . $k ] = array();
}

Expand Down Expand Up @@ -270,13 +270,16 @@ public function queryTotalVariations( $filterAttributes ) {
* @return string
*
* @since 1.0.0
* @version 1.1.4
*/
private function select_filter_attributes( $filter_attributes ) {
$select = '';

foreach ( array_keys( $filter_attributes ) as $attribute_key ) {
$select .= ", table_$attribute_key.meta_value as '$attribute_key'";
$select .= ", {$attribute_key}_terms.name as '{$attribute_key}_value'";
$manipulated_key = str_replace( '-', '_', $attribute_key );

$select .= ", table_$manipulated_key.meta_value as '$attribute_key'";
$select .= ", {$manipulated_key}_terms.name as '{$attribute_key}_value'";
}

return $select;
Expand All @@ -290,6 +293,7 @@ private function select_filter_attributes( $filter_attributes ) {
* @return string
*
* @since 1.0.0
* @version 1.1.4
*/
private function select_group_concat_filter_attributes( $filterAttributes ) {
$select = '';
Expand All @@ -311,18 +315,19 @@ private function select_group_concat_filter_attributes( $filterAttributes ) {
* @return string
*
* @since 1.0.0
* @version 1.0.5
* @version 1.1.4
*/
private function inner_join_filter_attributes( $filter_attributes ) {
$inner_join = '';

foreach ( $filter_attributes as $key => $attribute_value ) {
$short_key = str_replace( 'attribute_', '', $key );
$key_meta_key = $key;
$key = str_replace( '-', '_', $key );

$inner_join .= ' INNER JOIN ' . $this->wpdb->postmeta . " as table_$key
ON table_$key.post_id = ID
AND table_$key.meta_key = '" . $key . "' ";

AND table_$key.meta_key = '" . $key_meta_key . "' ";


if ( $attribute_value !== false && ! is_array( $attribute_value ) ) {
Expand All @@ -349,7 +354,7 @@ private function inner_join_filter_attributes( $filter_attributes ) {
* @return string
*
* @since 1.0.0
* @version 1.0.5
* @version 1.1.4
*/
private function sort( array $filterAttributes ) {
if ( count( $filterAttributes ) == 0 ) {
Expand All @@ -359,7 +364,7 @@ private function sort( array $filterAttributes ) {
$sort = " ORDER BY ";

foreach ( array_keys( $filterAttributes ) as $attribute_key ) {
$sort .= "CAST({$attribute_key}_value as DEC),";
$sort .= "CAST(`{$attribute_key}_value` as DEC),";
}

$sort = substr( $sort, 0, - 1 );
Expand Down
6 changes: 3 additions & 3 deletions woo-product-variations-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
Requires PHP: 7.0
Requires at least: 5.0
Tested up to: 5.5
Stable tag: 1.1.3
Version: 1.1.3
Stable tag: 1.1.4
Version: 1.1.4
*/

namespace woo_pvt;
Expand All @@ -36,7 +36,7 @@
/**
* Plugin version
*/
define( 'WOO_PVT_VERSION', '1.1.3');
define( 'WOO_PVT_VERSION', '1.1.4');

/**
* Rest API namespace
Expand Down

0 comments on commit b7f8c89

Please sign in to comment.