1

We are actually upgrade our version magento (1.7 to 1.9) but we have an issue when we try to use this function :

->addFieldToFilter('CHAR_LENGTH(review)', array('gteq' => 20))

This work in magento 1.7 but doesn't in 1.9. Do you have solution ? Here the complet request :

$collection = $content_database->getCollection()
        ->addFieldToSelect(array('firstname', 'lastname', 'review_date', 'review', 'rate'))
        ->addFieldToFilter('rate', array('gteq' => $this->_rating))
        ->addFieldToFilter('CHAR_LENGTH(review)', array('gteq' => 20))
        ->addFieldToFilter('store_id', Mage::app()->getStore()->getStoreId())
        ->setOrder("review_date", "desc")
        ->setPageSize($size);

    return $collection;

Here is the error message :

'CHAR_LENGTH(review)' in 'where clause', query was: SELECT COUNT(*) FROM upecom_reviews AS main_table WHERE (rate >= 4) AND (CHAR_LENGTH(review) >= 20) AND (store_id = '1')'

Thank you !

1 Answer 1

0

Apparently in magento 1.9 you can't use anymore sql function in the first parameter. So you should use regex like this :

$collection = $content_database->getCollection()
            ->addFieldToSelect(array('firstname', 'lastname', 'review_date', 'review', 'rate'))
            ->addFieldToFilter('rate', array('gteq' => $this->_rating))
            ->addFieldToFilter("review", array('regexp' => '^.{20,}$'))
            ->addFieldToFilter('store_id', Mage::app()->getStore()->getStoreId())
            ->setOrder("review_date", "desc")
            ->setPageSize($size);

Good luck Cem:)

0

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.