Commit ad348101313a18a8a165a7a2eb3c4e14b0741d3a

Authored by Administrator
1 parent 4fd39cf0

add variantSku

Showing 1 changed file with 66 additions and 25 deletions   Show diff stats
helpers/FilterHelper.php
... ... @@ -108,7 +108,9 @@
108 108  
109 109 return $filterView;
110 110 }
111   -
  111 +
  112 +
  113 +
112 114 /**
113 115 * Fill query with filter conditions
114 116 *
... ... @@ -121,28 +123,33 @@
121 123 foreach ($params as $key => $param) {
122 124 switch ($key) {
123 125 case 'special':
  126 + unset($params[$key]);
124 127 self::filterSpecial($param, $query);
125 128 break;
126 129 case 'brands':
  130 + unset($params[$key]);
127 131 self::filterBrands($param, $query);
128 132 break;
129 133 case 'keywords':
  134 + unset($params[$key]);
130 135 self::filterKeywords($param, $query);
131 136 break;
132 137 case 'prices':
  138 + unset($params[$key]);
133 139 self::filterPrices($param, $query);
134 140 break;
135   - default:
136   - $last_query = self::filterOptions($param, $last_query);
137   - break;
138 141 }
139 142 }
  143 + $last_query = self::filterOptions($params, $last_query);
140 144 // If tax option filters were provided filter query with them
141 145 if (!empty( $last_query )) {
142 146 $query->andWhere([ 'product.id' => $last_query ]);
143 147 }
144 148 }
145   -
  149 +
  150 +
  151 +
  152 +
146 153 /**
147 154 * Tax Option filter
148 155 *
... ... @@ -160,31 +167,65 @@
160 167 ->innerJoin(
161 168 'product_variant',
162 169 'product_variant_option.product_variant_id = product_variant.id'
163   - )
164   - ->innerJoin(
165   - 'tax_option',
166   - 'tax_option.id = product_variant_option.option_id'
167   - )
168   - ->innerJoin(
169   - 'tax_option_lang',
170   - 'tax_option_lang.tax_option_id = tax_option.id'
171   - )
172   - ->where([ 'tax_option_lang.alias' => $params ]);
  170 + );
  171 +
  172 + foreach ($params as $key=>$param){
  173 + $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id')
  174 + ->from('product_variant_option')
  175 + ->innerJoin(
  176 + 'tax_option',
  177 + 'tax_option.id = product_variant_option.option_id'
  178 + )
  179 + ->innerJoin(
  180 + 'tax_option_lang',
  181 + 'tax_option_lang.tax_option_id = tax_option.id'
  182 + )
  183 + ->innerJoin(
  184 + 'tax_group',
  185 + 'tax_group.id = tax_option.tax_group_id'
  186 + )
  187 + ->innerJoin(
  188 + 'tax_group_lang',
  189 + 'tax_group_lang.tax_group_id = tax_group.id'
  190 + )
  191 + ->where([ 'tax_group_lang.alias' => $key ])
  192 + ->andWhere([ 'tax_option_lang.alias' => $param ]);
  193 + $variant_query->andWhere(['product_variant_option.product_variant_id'=>$product_variant_id]);
  194 +
  195 + }
  196 +
  197 +
173 198 if($in_stock) {
174 199 $variant_query->andWhere(['!=', 'product_variant.stock', 0]);
175 200 }
176 201 $product_query = ( new Query() )->distinct()
177 202 ->select('product_option.product_id as products')
178   - ->from('product_option')
179   - ->innerJoin('tax_option', 'product_option.option_id = tax_option.id')
180   - ->innerJoin(
181   - 'tax_option_lang',
182   - 'tax_option_lang.tax_option_id = tax_option.id'
183   - )
184   - ->where(
185   - [ 'tax_option_lang.alias' => $params ]
186   - )
187   - ->union($variant_query);
  203 + ->from('product_option');
  204 + foreach ($params as $key=>$param){
  205 + $product_id = ( new Query() )->distinct()->select('product_option.product_id as id')
  206 + ->from('product_option')
  207 + ->innerJoin(
  208 + 'tax_option',
  209 + 'tax_option.id = product_option.option_id'
  210 + )
  211 + ->innerJoin(
  212 + 'tax_option_lang',
  213 + 'tax_option_lang.tax_option_id = tax_option.id'
  214 + )
  215 + ->innerJoin(
  216 + 'tax_group',
  217 + 'tax_group.id = tax_option.tax_group_id'
  218 + )
  219 + ->innerJoin(
  220 + 'tax_group_lang',
  221 + 'tax_group_lang.tax_group_id = tax_group.id'
  222 + )
  223 + ->where([ 'tax_group_lang.alias' => $key ])
  224 + ->andWhere([ 'tax_option_lang.alias' => $param ]);
  225 + $product_query->andWhere(['product_option.product_id'=>$product_id]);
  226 +
  227 + }
  228 + $product_query->union($variant_query);
188 229 $query = ( new Query() )->select('products')
189 230 ->from([ 'result_table' => $product_query ]);
190 231 if (!empty( $last_query )) {
... ...