|
32 | 32 | import org.broadleafcommerce.common.util.BLCSystemProperty;
|
33 | 33 | import org.broadleafcommerce.common.web.BroadleafRequestContext;
|
34 | 34 | import org.broadleafcommerce.core.catalog.domain.Product;
|
| 35 | +import org.broadleafcommerce.core.catalog.domain.ProductAttribute; |
35 | 36 | import org.broadleafcommerce.core.catalog.domain.Sku;
|
| 37 | +import org.broadleafcommerce.core.catalog.domain.SkuAttribute; |
36 | 38 | import org.broadleafcommerce.core.search.domain.Field;
|
37 | 39 | import org.broadleafcommerce.core.search.domain.solr.FieldType;
|
38 | 40 | import org.springframework.stereotype.Service;
|
@@ -204,28 +206,50 @@ protected ExtensionResultStatusType getLocalePrefix(Field field, List<String> pr
|
204 | 206 | */
|
205 | 207 | @Override
|
206 | 208 | public ExtensionResultStatusType startBatchEvent(List<Product> products) {
|
207 |
| - List<String> defaultSkuIds = new ArrayList<String>(products.size()); |
208 |
| - List<String> productIds = new ArrayList<String>(products.size()); |
209 |
| - for (Product product : products) { |
210 |
| - productIds.add(product.getId().toString()); |
211 |
| - defaultSkuIds.add(product.getDefaultSku().getId().toString()); |
| 209 | + List<String> skuIds = new ArrayList<String>(products.size()); |
| 210 | + List<String> productIds = new ArrayList<String>(); |
| 211 | + List<String> skuAttributeIds = new ArrayList<String>(); |
| 212 | + List<String> productAttributeIds = new ArrayList<String>(); |
| 213 | + for (Product indexable : products) { |
| 214 | + Sku sku = null; |
| 215 | + if (Product.class.isAssignableFrom(indexable.getClass())) { |
| 216 | + Product product = indexable; |
| 217 | + productIds.add(product.getId().toString()); |
| 218 | + for (Map.Entry<String, ProductAttribute> attributeEntry : product.getProductAttributes().entrySet()) { |
| 219 | + ProductAttribute attribute = attributeEntry.getValue(); |
| 220 | + productAttributeIds.add(attribute.getId().toString()); |
| 221 | + } |
| 222 | + sku = product.getDefaultSku(); |
| 223 | + } |
| 224 | + |
| 225 | + if (sku != null) { |
| 226 | + skuIds.add(sku.getId().toString()); |
| 227 | + for (Map.Entry<String, SkuAttribute> attributeEntry : sku.getSkuAttributes().entrySet()) { |
| 228 | + SkuAttribute attribute = attributeEntry.getValue(); |
| 229 | + skuAttributeIds.add(attribute.getId().toString()); |
| 230 | + } |
| 231 | + } |
212 | 232 | }
|
213 |
| - |
214 |
| - List<Translation> defaultSkuTranslations = translationDao.readAllTranslationEntries(TranslatedEntity.SKU, ResultType.STANDARD, defaultSkuIds); |
215 |
| - TranslationBatchReadCache.addToCache(defaultSkuTranslations); |
216 |
| - |
217 |
| - List<Translation> productTranslations = translationDao.readAllTranslationEntries(TranslatedEntity.PRODUCT, ResultType.STANDARD, productIds); |
218 |
| - TranslationBatchReadCache.addToCache(productTranslations); |
219 |
| - |
| 233 | + |
| 234 | + addEntitiesToTranslationCache(skuIds, TranslatedEntity.SKU); |
| 235 | + addEntitiesToTranslationCache(productIds, TranslatedEntity.PRODUCT); |
| 236 | + addEntitiesToTranslationCache(skuAttributeIds, TranslatedEntity.SKU_ATTRIBUTE); |
| 237 | + addEntitiesToTranslationCache(productAttributeIds, TranslatedEntity.PRODUCT_ATTRIBUTE); |
| 238 | + |
220 | 239 | return ExtensionResultStatusType.HANDLED_CONTINUE;
|
221 | 240 | }
|
222 |
| - |
| 241 | + |
| 242 | + private void addEntitiesToTranslationCache(List<String> entityIds, TranslatedEntity translatedEntity) { |
| 243 | + List<Translation> translations = translationDao.readAllTranslationEntries(translatedEntity, ResultType.STANDARD, entityIds); |
| 244 | + TranslationBatchReadCache.addToCache(translations); |
| 245 | + } |
| 246 | + |
223 | 247 | @Override
|
224 | 248 | public ExtensionResultStatusType endBatchEvent() {
|
225 | 249 | TranslationBatchReadCache.clearCache();
|
226 | 250 | return ExtensionResultStatusType.HANDLED_CONTINUE;
|
227 | 251 | }
|
228 |
| - |
| 252 | + |
229 | 253 | @Override
|
230 | 254 | public int getPriority() {
|
231 | 255 | return 1000;
|
|
0 commit comments