1

I have a custom module which I load data with following code inside list.phtml:

foreach ($_productCollection as $_product){
$_id = $_product->getId();
$event = Mage::getModel('aw_eventbooking/event');
$event = $event->loadByProductId($_id);
$eventStartDate = $event->getEventStartDate();
}

I want to create a way to filter products based on event start date, I modified List.php on Mage_Catalog_Block_Product_List to do something like this:

$now = new DateTime();
$now = $now->format('Y-m-d H:i:s');
$strnow = strtotime($now);

$this->_productCollection = $layer->getProductCollection();
$this->_productCollection
            ->getSelect()
            ->where('ATTRIBUTE START DATE > $now');
}

The problem is, how can I get the "ATTRIBUTE START DATE", the $event->getEventStartDate(); to make the filter possible? Please help, I am new to magento

I want something like this:

$eventcollection=$this->getLoadedProductCollection();
    $eventcollection = $eventcollection
    ->getSelect()
    ->where('$event->getEventStartDate() > $strnow');

Is this somehow possible?

0
$now = new DateTime();
$now = $now->format('Y-m-d H:i:s');
$strnow = strtotime($now);

$this->_productCollection = $layer->getProductCollection();
$products = $this->_productCollection
->addAttributeToSort('created_at', 'desc')
->addAttributeToFilter('created_at', array('gteq' =>$now));

I do not quite understand where(**'ATTRIBUTE START DATE > $ now'**); , but I hope that I will push you to the right decision.

I assume that this attribute is a product creation 'ATTRIBUTE START DATE'.

More information on the filters you can see here addFilter vs addFieldToFilter

  • "ATTRIBUTE START DATE" is a attribute from custom model, it is a attribute which is not in the flat table. I know how to call the model and get its data, but how can I use filter with custom model? – Gabriel G May 15 '18 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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