Skip to content

Commit 806039a

Browse files
committed
Merge pull request #4 from magento-hackathon/datefix
Datefix
2 parents 3c56883 + 59ff631 commit 806039a

File tree

1 file changed

+16
-12
lines changed
  • src/app/code/community/Hackathon/PromoCodeMessages/Model

1 file changed

+16
-12
lines changed

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

+16-12
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,16 @@ protected function _validateGeneral($rule, $coupon)
146146
));
147147
}
148148

149+
// check dates
150+
$now = new Zend_Date(Mage::getModel('core/date')->timestamp(time()), Zend_Date::TIMESTAMP);
151+
149152
// check from date
150153
if ($rule->getFromDate()) {
151154
$fromDate = new Zend_Date($rule->getFromDate(), Varien_Date::DATE_INTERNAL_FORMAT);
152-
if (Zend_Date::now()->isEarlier($fromDate)) {
155+
if ($now->isEarlier($fromDate)) {
153156
Mage::throwException($this->_formatMessage(
154157
'Your coupon is not valid yet. It will be active on %s.',
155-
Mage::helper('core')->formatDate($fromDate),
158+
Mage::helper('core')->formatDate($fromDate, Mage_Core_Model_Locale::FORMAT_TYPE_LONG),
156159
''
157160
));
158161
}
@@ -161,10 +164,10 @@ protected function _validateGeneral($rule, $coupon)
161164
// check to date
162165
if ($rule->getToDate()) {
163166
$toDate = new Zend_Date($rule->getToDate(), Varien_Date::DATE_INTERNAL_FORMAT);
164-
if (Zend_Date::now()->isLater($toDate)) {
167+
if ($now->isLater($toDate)) {
165168
Mage::throwException($this->_formatMessage(
166169
'Your coupon is no longer valid. It expired on %s.',
167-
Mage::helper('core')->formatDate($toDate),
170+
Mage::helper('core')->formatDate($toDate, Mage_Core_Model_Locale::FORMAT_TYPE_LONG),
168171
''
169172
));
170173
}
@@ -302,14 +305,14 @@ protected function _processRule($condition = array())
302305
// categories
303306
if ($attribute == 'category_ids') {
304307
$categoryIds = explode(',', $value);
305-
$values = array();
306308

307-
//get collection and filter by cat ids
309+
// get collection and filter by cat ids
308310
$catCollection = Mage::getModel('catalog/category')->getCollection();
309311
$catCollection->addAttributeToFilter('entity_id', array('in' => $categoryIds));
312+
$catCollection->addAttributeToSelect('name');
310313

311-
$categoryIds = $catCollection->load()->getColumnValues('name');
312-
$value = implode(', ', $categoryIds);
314+
$categories = $catCollection->load()->getColumnValues('name');
315+
$value = implode(', ', $categories);
313316
}
314317

315318
// product attributes
@@ -326,15 +329,16 @@ protected function _processRule($condition = array())
326329
// attribute may use a source model
327330
if ($attributeModel->usesSource()) {
328331
$attributeId = $attributeModel->getAttributeId();
329-
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')// TODO: better way?
330-
->setAttributeFilter($attributeId)
332+
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
333+
->setAttributeFilter($attributeId)
331334
->setStoreFilter($storeId, false)
332-
->addFieldToFilter('tsv.option_id', array('in' => $value))
335+
->addFieldToFilter('tsv.option_id', array('in' => $value));
336+
$collection
333337
->getSelect()
334338
->limit(1);
335339

336340
if ($collection->getSize()) {
337-
$value = $collection->getResource()->fetchOne($collection->getSelect());
341+
$value = $collection->getFirstItem()->getValue();
338342
}
339343
}
340344
}

0 commit comments

Comments
 (0)