Skip to content

Commit 3c56883

Browse files
committed
Merge pull request #5 from philwinkle/master
Performance fixes
2 parents c220fc2 + c8d09a0 commit 3c56883

File tree

1 file changed

+13
-8
lines changed
  • src/app/code/community/Hackathon/PromoCodeMessages/Model

1 file changed

+13
-8
lines changed

src/app/code/community/Hackathon/PromoCodeMessages/Model/Validator.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,13 @@ protected function _processRule($condition = array())
303303
if ($attribute == 'category_ids') {
304304
$categoryIds = explode(',', $value);
305305
$values = array();
306-
foreach ($categoryIds as $categoryId) {
307-
$category = Mage::getModel('catalog/category')->load($categoryId);
308-
$values[] = $category->getName();
309-
}
310-
$value = implode(', ', $values);
306+
307+
//get collection and filter by cat ids
308+
$catCollection = Mage::getModel('catalog/category')->getCollection();
309+
$catCollection->addAttributeToFilter('entity_id', array('in' => $categoryIds));
310+
311+
$categoryIds = $catCollection->load()->getColumnValues('name');
312+
$value = implode(', ', $categoryIds);
311313
}
312314

313315
// product attributes
@@ -327,9 +329,12 @@ protected function _processRule($condition = array())
327329
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')// TODO: better way?
328330
->setAttributeFilter($attributeId)
329331
->setStoreFilter($storeId, false)
330-
->addFieldToFilter('tsv.option_id', array('in' => $value));
331-
if ($collection->getSize() > 0) {
332-
$value = $collection->getFirstItem()->getValue();
332+
->addFieldToFilter('tsv.option_id', array('in' => $value))
333+
->getSelect()
334+
->limit(1);
335+
336+
if ($collection->getSize()) {
337+
$value = $collection->getResource()->fetchOne($collection->getSelect());
333338
}
334339
}
335340
}

0 commit comments

Comments
 (0)