0

I have bought a template from themeforest and I've noticed the entries in hot-sale tab stop showing a day before the special_to_date attribute is set ( meanwhile the general product listing is correct , and shows products on sale including the last day of campaign ).

So if we set a campain from 25th to 27th august, the hot-sale tab is empty ( today ) but the products are still on sale on general listings ( as they should ).

So I've looked into the template code and found this:

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
    ->addAttributeToFilter('special_from_date', array('or'=> array(
        0 => array('date' => true, 'to' => $todayDate),
        1 => array('is' => new Zend_Db_Expr('null')))
    ), 'left')
    ->addAttributeToFilter('special_to_date', array('or'=> array(
        0 => array('date' => true, 'from' => $todayDate),
        1 => array('is' => new Zend_Db_Expr('null')))
    ), 'left')
    ->addAttributeToFilter(
        array(
            array('attribute' => 'special_from_date', 'is'=>new Zend_Db_Expr('not null')),
            array('attribute' => 'special_to_date', 'is'=>new Zend_Db_Expr('not null'))
            )
      )
    ->addAttributeToSort('price', 'asc')
    ->addTaxPercents()
    ->addStoreFilter(); 

Now, I'm not that good of a programmer with Magento.. and I don't really understand these addAttributeToFilter but my best bet is that this is exclusive ( regarding the campaign ending date ):

->addAttributeToFilter('special_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $todayDate),
    1 => array('is' => new Zend_Db_Expr('null')))
), 'left')

So, if you can shed some light on this, please do. I only guess with my little knowledge this would be the problem which doesn't collect produdcts in their last day of special_to_date.

1 Answer 1

3

The issue is that $todayDate returns the full date AND time (e.g 2015-08-27 09:30:15), but in the database the date is saved without a time (e.g 2015-08-27 00:00:00). So the query is inclusive but it fails because the special_to_date is not greater or equal to $todayDate.

Change the first line to:

 $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATE_INTERNAL_FORMAT);

It should fix your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.