@@ -146,13 +146,16 @@ protected function _validateGeneral($rule, $coupon)
146
146
));
147
147
}
148
148
149
+ // check dates
150
+ $ now = new Zend_Date (Mage::getModel ('core/date ' )->timestamp (time ()), Zend_Date::TIMESTAMP );
151
+
149
152
// check from date
150
153
if ($ rule ->getFromDate ()) {
151
154
$ fromDate = new Zend_Date ($ rule ->getFromDate (), Varien_Date::DATE_INTERNAL_FORMAT );
152
- if (Zend_Date:: now () ->isEarlier ($ fromDate )) {
155
+ if ($ now ->isEarlier ($ fromDate )) {
153
156
Mage::throwException ($ this ->_formatMessage (
154
157
'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 ),
156
159
''
157
160
));
158
161
}
@@ -161,10 +164,10 @@ protected function _validateGeneral($rule, $coupon)
161
164
// check to date
162
165
if ($ rule ->getToDate ()) {
163
166
$ toDate = new Zend_Date ($ rule ->getToDate (), Varien_Date::DATE_INTERNAL_FORMAT );
164
- if (Zend_Date:: now () ->isLater ($ toDate )) {
167
+ if ($ now ->isLater ($ toDate )) {
165
168
Mage::throwException ($ this ->_formatMessage (
166
169
'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 ),
168
171
''
169
172
));
170
173
}
@@ -302,14 +305,14 @@ protected function _processRule($condition = array())
302
305
// categories
303
306
if ($ attribute == 'category_ids ' ) {
304
307
$ categoryIds = explode (', ' , $ value );
305
- $ values = array ();
306
308
307
- //get collection and filter by cat ids
309
+ // get collection and filter by cat ids
308
310
$ catCollection = Mage::getModel ('catalog/category ' )->getCollection ();
309
311
$ catCollection ->addAttributeToFilter ('entity_id ' , array ('in ' => $ categoryIds ));
312
+ $ catCollection ->addAttributeToSelect ('name ' );
310
313
311
- $ categoryIds = $ catCollection ->load ()->getColumnValues ('name ' );
312
- $ value = implode (', ' , $ categoryIds );
314
+ $ categories = $ catCollection ->load ()->getColumnValues ('name ' );
315
+ $ value = implode (', ' , $ categories );
313
316
}
314
317
315
318
// product attributes
@@ -326,15 +329,16 @@ protected function _processRule($condition = array())
326
329
// attribute may use a source model
327
330
if ($ attributeModel ->usesSource ()) {
328
331
$ 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 )
331
334
->setStoreFilter ($ storeId , false )
332
- ->addFieldToFilter ('tsv.option_id ' , array ('in ' => $ value ))
335
+ ->addFieldToFilter ('tsv.option_id ' , array ('in ' => $ value ));
336
+ $ collection
333
337
->getSelect ()
334
338
->limit (1 );
335
339
336
340
if ($ collection ->getSize ()) {
337
- $ value = $ collection ->getResource ()->fetchOne ( $ collection -> getSelect () );
341
+ $ value = $ collection ->getFirstItem ()->getValue ( );
338
342
}
339
343
}
340
344
}
0 commit comments