heaven dweller
Total Posts: 18
Joined: 2009-11-10
Hi,
I want to use lower case function for name in product collection. For example
Mage :: getModel ( 'catalog/product' )-> getCollection ()-> addAttributeExpressionToFilter (new Zend_Db_Expr ( '"LCASE(TRIM(name))' ), 'test' );
But this is not working. Can anyone help ?
Signature
Posted: September 24 2012
| top
kiatng
Total Posts: 870
Joined: 2008-09-03
Kuala Lumpur, Malaysia
Why not do it PHP
Mage :: getModel ( 'catalog/product' )-> getCollection ()-> addAttributeExpressionToFilter (new Zend_Db_Expr ( strtolower ( trim ( $name )), 'test' );
Posted: September 24 2012
| top
| # 1
heaven dweller
Total Posts: 18
Joined: 2009-11-10
Actually I need to do it in query as filter for example
select * from product where lcase ( trim ( name )) = \ 'testname\'
Signature
Posted: September 24 2012
| top
| # 2
kiatng
Total Posts: 870
Joined: 2008-09-03
Kuala Lumpur, Malaysia
MySQL is case insensitive. For example I have extra spaces and wrong case in the following select statement which works
SELECT * FROM ` catalog_product_entity_varchar ` where VaLUe_iD = 5
Posted: September 24 2012
| top
| # 3
heaven dweller
Total Posts: 18
Joined: 2009-11-10
kiatng, mysql is case insensitive but spaces are not trimmed
Signature
Posted: September 24 2012
| top
| # 4
kiatng
Total Posts: 870
Joined: 2008-09-03
Kuala Lumpur, Malaysia
Try this:
Mage :: getModel ( 'catalog/product' )-> getCollection ()-> addAttributeExpressionToFilter (new Zend_Db_Expr ( 'LCASE(TRIM(name))' ), 'test' );
You have an extra “ in your original statement.
Posted: September 24 2012
| top
| # 5
heaven dweller
Total Posts: 18
Joined: 2009-11-10
I think addExpressionAttributeToFilter is not available
Signature
Posted: September 24 2012
| top
| # 6
ilm_abhishek
Total Posts: 4
Joined: 2012-05-03
hi
try this
addFieldToFilter ( $field , $condition = null )
or
$collection -> addAttributeToFilter ( 'field_name' , array( 'in' => array( 1 , 2 , 3 ), ));
Thanks,
ilm_abhishek
Signature
Abhishek
===========
http://iLoveMage.com
a super extension development company for magento
Posted: September 24 2012
| top
| # 7
heaven dweller
Total Posts: 18
Joined: 2009-11-10
I need to trim column value also
Signature
Posted: September 24 2012
| top
| # 8
ilm_abhishek
Total Posts: 4
Joined: 2012-05-03
$write = Mage::getSingleton(’core/resource’)->getConnection(’core_write’);
// now $write is an instance of Zend_Db_Adapter_Abstract
$readresult=$write->query("SELECT *
FROM `pepitashop_catalog_product_super_attribute_pricing` , `pepitashop_catalog_product_entity`,`pepitashop_catalog_product_super_attribute`
WHERE
`pepitashop_catalog_product_super_attribute`.product_super_attribute_id = `pepitashop_catalog_product_super_attribute_pricing`.product_super_attribute_id
AND
pepitashop_catalog_product_super_attribute.product_id = `pepitashop_catalog_product_entity`.entity_id
AND pepitashop_catalog_product_super_attribute.product_id = ‘“.$_id.”’
ORDER BY `pepitashop_catalog_product_super_attribute_pricing`.pricing_value DESC
LIMIT 0 , 30 “);
while ($row = $readresult->fetch() ) {
$categoryIds[]=$row[’id’];
}
Signature
Abhishek
===========
http://iLoveMage.com
a super extension development company for magento
Posted: September 25 2012
| top
| # 9
heaven dweller
Total Posts: 18
Joined: 2009-11-10
I have come up with this solution :
$collection1 = Mage :: getModel ( 'catalog/product' )-> getCollection (); $collection1 -> getSelect ()-> columns (array( 'name' =>new Zend_Db_Expr ( 'lcase(trim(name))' ))); $collection2 = Mage :: getModel ( 'catalog/product' )-> getCollection (); $collection2 -> getSelect ()-> joinInner (array( 'e1' => $collection1 -> getSelectSql ()), 'e1.entity_id=e.entity_id' ); $collection2 -> getSelect ()-> where ( "e1.name = 'test'" );
Signature
Posted: October 5 2012
| top
| # 10