@@ -120,7 +120,25 @@ public function setSettings($storeId)
120120 $ facets = $ this ->config ->getFacets ();
121121
122122 foreach ($ facets as $ facet )
123+ {
124+ if ($ facet ['attribute ' ] === 'price ' )
125+ {
126+ $ facet ['attribute ' ] = 'price.default ' ;
127+
128+ if ($ this ->config ->isCustomerGroupsEnabled ($ storeId ))
129+ {
130+ foreach ($ groups = Mage::getModel ('customer/group ' )->getCollection () as $ group )
131+ {
132+ $ group_id = (int )$ group ->getData ('customer_group_id ' );
133+
134+ $ attributesForFaceting [] = 'price.group_ ' . $ group_id ;
135+ }
136+ }
137+ }
138+
123139 $ attributesForFaceting [] = $ facet ['attribute ' ];
140+ }
141+
124142
125143 foreach ($ customRankings as $ ranking )
126144 $ customRankingsArr [] = $ ranking ['order ' ] . '( ' . $ ranking ['attribute ' ] . ') ' ;
@@ -156,21 +174,24 @@ public function setSettings($storeId)
156174 {
157175 if ($ this ->config ->isCustomerGroupsEnabled ($ storeId ))
158176 {
159- if (strpos ( $ values ['attribute ' ], ' price ' ) !== false )
177+ if ($ values ['attribute ' ] === ' price ' )
160178 {
161179 foreach ($ groups = Mage::getModel ('customer/group ' )->getCollection () as $ group )
162180 {
163181 $ group_id = (int )$ group ->getData ('customer_group_id ' );
164182
165183 $ suffix_index_name = 'group_ ' . $ group_id ;
166184
167- $ slaves [] = $ this ->getIndexName ($ storeId ) . '_ ' . $ suffix_index_name . '_ ' .$ values [ ' attribute ' ]. '_ ' . $ values ['sort ' ];
185+ $ slaves [] = $ this ->getIndexName ($ storeId ) . '_ ' .$ values [ ' attribute ' ]. '_ ' . $ suffix_index_name . '_ ' . $ values ['sort ' ];
168186 }
169187 }
170188 }
171189 else
172190 {
173- $ slaves [] = $ this ->getIndexName ($ storeId ) . '_ ' . 'default ' . '_ ' .$ values ['attribute ' ].'_ ' .$ values ['sort ' ];
191+ if ($ values ['attribute ' ] === 'price ' )
192+ $ slaves [] = $ this ->getIndexName ($ storeId ) . '_ ' .$ values ['attribute ' ]. '_default_ ' . $ values ['sort ' ];
193+ else
194+ $ slaves [] = $ this ->getIndexName ($ storeId ) . '_ ' .$ values ['attribute ' ]. '_ ' . $ values ['sort ' ];
174195 }
175196 }
176197
@@ -186,12 +207,13 @@ public function setSettings($storeId)
186207 {
187208 $ group_id = (int )$ group ->getData ('customer_group_id ' );
188209
189- $ suffix_index_name = '_group_ ' . $ group_id ;
210+ $ suffix_index_name = 'group_ ' . $ group_id ;
211+
212+ $ sort_attribute = strpos ($ values ['attribute ' ], 'price ' ) !== false ? $ values ['attribute ' ].'. ' .$ suffix_index_name : $ values ['attribute ' ];
190213
191- $ sort_attribute = strpos ($ values ['attribute ' ], 'price ' ) !== false ? $ values ['attribute ' ].'. ' .$ group_id : $ values ['attribute ' ];
192214 $ mergeSettings ['ranking ' ] = array ($ values ['sort ' ].'( ' .$ sort_attribute .') ' , 'typo ' , 'geo ' , 'words ' , 'proximity ' , 'attribute ' , 'exact ' , 'custom ' );
193215
194- $ this ->algolia_helper ->setSettings ($ this ->getIndexName ($ storeId ).$ suffix_index_name . '_ ' .$ values ['attribute ' ].'_ ' .$ values ['sort ' ], $ mergeSettings );
216+ $ this ->algolia_helper ->setSettings ($ this ->getIndexName ($ storeId ).'_ ' .$ values ['attribute ' ]. ' _ ' . $ suffix_index_name .'_ ' .$ values ['sort ' ], $ mergeSettings );
195217 }
196218 }
197219 }
@@ -201,56 +223,81 @@ public function setSettings($storeId)
201223
202224 $ mergeSettings ['ranking ' ] = array ($ values ['sort ' ].'( ' .$ sort_attribute .') ' , 'typo ' , 'geo ' , 'words ' , 'proximity ' , 'attribute ' , 'exact ' , 'custom ' );
203225
204- $ this ->algolia_helper ->setSettings ($ this ->getIndexName ($ storeId ) . '_ ' . ' default ' . '_ ' .$ values [ ' attribute ' ]. '_ ' .$ values ['sort ' ], $ mergeSettings );
226+ $ this ->algolia_helper ->setSettings ($ this ->getIndexName ($ storeId ) . '_ ' .$ values [ ' attribute ' ]. '_ ' . ' default ' . '_ ' .$ values ['sort ' ], $ mergeSettings );
205227 }
206228 }
207229 }
208230 }
209231
210- /**
211- * @param $product
212- * @param $sub_products
213- * @param $additionalAttributes
214- * @param $customData
215- * @param array $groups
216- * @param null $group_id
217- */
218- private function handlePrice (&$ product , $ sub_products , $ additionalAttributes , &$ customData , $ groups = array (), $ group_id = null )
232+ private function handlePrice (&$ product , $ sub_products , &$ customData , $ groups = array (), $ current_group_id = null )
219233 {
220- $ key = $ group_id === null ? 'default ' : $ group_id ;
221-
222234 $ customData ['price ' ] = array ();
223235
224- $ customData ['price ' ][$ key ] = (double ) Mage::helper ('tax ' )->getPrice ($ product , $ product ->getPrice (), null , null , null , null , $ product ->getStore (), null );
225- $ customData ['price ' ][$ key .'_formated ' ] = $ product ->getStore ()->formatPrice ($ customData ['price ' ][$ key ], false );
236+ $ customData ['price ' ]['default ' ] = (double ) Mage::helper ('tax ' )->getPrice ($ product , $ product ->getPrice (), null , null , null , null , $ product ->getStore (), null );
237+ $ customData ['price ' ]['default_formated ' ] = $ product ->getStore ()->formatPrice ($ customData ['price ' ]['default ' ], false );
238+
239+ if ($ this ->config ->isCustomerGroupsEnabled ($ product ->getStoreId ()))
240+ {
241+ foreach ($ groups as $ group )
242+ {
243+ $ group_id = (int )$ group ->getData ('customer_group_id ' );
244+
245+ $ customData ['price ' ]['group_ ' . $ group_id ] = $ customData ['price ' ]['default ' ];
246+ $ customData ['price ' ]['group_ ' . $ group_id . '_formated ' ] = $ customData ['price ' ]['default_formated ' ];
247+ }
248+ }
226249
227250 $ special_price = null ;
228251
229- if ($ group_id !== null ) // If fetch special price for groups
252+ if ($ current_group_id !== null ) // If fetch special price for groups
230253 {
231254 $ discounted_price = Mage::getResourceModel ('catalogrule/rule ' )->getRulePrice (
232255 Mage::app ()->getLocale ()->storeTimeStamp ($ product ->getStoreId ()),
233256 Mage::app ()->getStore ($ product ->getStoreId ())->getWebsiteId (),
234- $ group_id ,
257+ $ current_group_id ,
235258 $ product ->getId ()
236259 );
237260
238261 if ($ discounted_price !== false )
239262 $ special_price = $ discounted_price ;
263+
264+ if ($ this ->config ->isCustomerGroupsEnabled ($ product ->getStoreId ()))
265+ {
266+ foreach ($ groups as $ group )
267+ {
268+ $ group_id = (int )$ group ->getData ('customer_group_id ' );
269+
270+ $ discounted_price = Mage::getResourceModel ('catalogrule/rule ' )->getRulePrice (
271+ Mage::app ()->getLocale ()->storeTimeStamp ($ product ->getStoreId ()),
272+ Mage::app ()->getStore ($ product ->getStoreId ())->getWebsiteId (),
273+ $ group_id ,
274+ $ product ->getId ()
275+ );
276+
277+ if ($ discounted_price !== false )
278+ {
279+ $ customData ['price ' ]['group_ ' . $ group_id ] = (double ) Mage::helper ('tax ' )->getPrice ($ product , $ discounted_price , null , null , null , null , $ product ->getStore (), null );
280+ $ customData ['price ' ]['group_ ' . $ group_id . '_formated ' ] = $ product ->getStore ()->formatPrice ($ customData ['price ' ]['group_ ' . $ group_id ], false );
281+ }
282+ }
283+ }
284+
240285 }
241286 else // If fetch default special price
242287 {
243288 $ special_price = (double ) $ product ->getFinalPrice ();
244289 }
245290
246- if ($ special_price && $ special_price !== $ customData ['price ' ][$ key ])
291+ if ($ special_price && $ special_price !== $ customData ['price ' ][' default ' ])
247292 {
248293 $ customData ['price ' ]['special_from_date ' ] = strtotime ($ product ->getSpecialFromDate ());
249294 $ customData ['price ' ]['special_to_date ' ] = strtotime ($ product ->getSpecialToDate ());
250295
296+ $ customData ['price ' ]['default_old_formated ' ] = $ customData ['price ' ]['default ' .'_formated ' ];
297+
251298 $ special_price = (double ) Mage::helper ('tax ' )->getPrice ($ product , $ special_price , null , null , null , null , $ product ->getStore (), null );
252- $ customData ['price ' ][$ key . ' _special ' ] = $ special_price ;
253- $ customData ['price ' ][$ key . ' _special_formated ' ] = $ product ->getStore ()->formatPrice ($ special_price , false );
299+ $ customData ['price ' ][' default ' ] = $ special_price ;
300+ $ customData ['price ' ][' default_formated ' ] = $ product ->getStore ()->formatPrice ($ special_price , false );
254301 }
255302
256303 if ($ product ->getTypeId () == 'configurable ' || $ product ->getTypeId () == 'grouped ' || $ product ->getTypeId () == 'bundle ' )
@@ -262,9 +309,7 @@ private function handlePrice(&$product, $sub_products, $additionalAttributes, &$
262309 {
263310 $ _priceModel = $ product ->getPriceModel ();
264311
265- list ($ min , $ max ) = $ _priceModel ->getTotalPrices ($ product , null , null , false );
266- list ($ min_with_tax , $ max_with_tax ) = $ _priceModel ->getTotalPrices ($ product , null , true , false );
267-
312+ list ($ min , $ max ) = $ _priceModel ->getTotalPrices ($ product , null , null , true );
268313 }
269314
270315 if ($ product ->getTypeId () == 'grouped ' || $ product ->getTypeId () == 'configurable ' )
@@ -288,17 +333,15 @@ private function handlePrice(&$product, $sub_products, $additionalAttributes, &$
288333 {
289334 $ group_id = (int )$ group ->getData ('customer_group_id ' );
290335
291- $ customData ['price ' ]['group_ ' . $ group_id .'_formated ' ] = $ product ->getStore ()->formatPrice ($ min , false ) . ' ' . $ product ->getStore ()->formatPrice ($ max , false );
292-
293- $ customData ['price ' ]['default ' ] = 0 ; // will be reset just after
336+ $ customData ['price ' ]['group_ ' . $ group_id ] = 0 ;
337+ $ customData ['price ' ]['group_ ' . $ group_id . '_formated ' ] = $ product ->getStore ()->formatPrice ($ min , false ) . ' - ' . $ product ->getStore ()->formatPrice ($ max , false );
294338 }
295339 }
296340
297341 //// Do not keep special price that is already taken into account in min max
298342 unset($ customData ['price ' ]['special_from_date ' ]);
299343 unset($ customData ['price ' ]['special_to_date ' ]);
300- unset($ customData ['price ' ]['default_special ' ]);
301- unset($ customData ['price ' ]['default_special_formated ' ]);
344+ unset($ customData ['price ' ]['default_old_formated ' ]);
302345
303346 $ customData ['price ' ]['default ' ] = 0 ; // will be reset just after
304347 }
@@ -312,11 +355,7 @@ private function handlePrice(&$product, $sub_products, $additionalAttributes, &$
312355 foreach ($ groups as $ group )
313356 {
314357 $ group_id = (int )$ group ->getData ('customer_group_id ' );
315-
316- if ($ customData ['price ' ]['group_ ' . $ group_id ] == 0 )
317- {
318- $ customData ['price ' ]['group_ ' . $ group_id ] = $ min ;
319- }
358+ $ customData ['price ' ]['group_ ' . $ group_id ] = $ min ;
320359 }
321360 }
322361 }
@@ -557,7 +596,7 @@ public function getObject(Mage_Catalog_Model_Product $product)
557596 }
558597 }
559598
560- $ this ->handlePrice ($ product , $ sub_products , $ additionalAttributes , $ customData );
599+ $ this ->handlePrice ($ product , $ sub_products , $ customData );
561600
562601 if ($ this ->config ->isCustomerGroupsEnabled ())
563602 {
@@ -566,7 +605,7 @@ public function getObject(Mage_Catalog_Model_Product $product)
566605 foreach ($ groups as $ group )
567606 {
568607 $ group_id = (int )$ group ->getData ('customer_group_id ' );
569- $ this ->handlePrice ($ product , $ sub_products , $ additionalAttributes , $ customData , $ groups , $ group_id );
608+ $ this ->handlePrice ($ product , $ sub_products , $ customData , $ groups , $ group_id );
570609 }
571610 }
572611
0 commit comments