Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

make sql query based on collection using OR /search by custom option SKU
 
SAM-I-AM
Jr. Member
 
Total Posts:  15
Joined:  2009-05-31
 

below is the code that is used to list the custom option id of the products whose option ‘s sku is like 66705

right now i can only filter the result based on the sku of custom option. How can i filter the resultset based on two fields title and sku by using an or statement

$collection Mage::getModel('catalog/product_option_value')->getCollection();
$collection->getSelect()->join(
array(
'title_table'=>Mage::getSingleton('core/resource')
->
getTableName('catalog_product_option_type_title')),
'main_table.option_type_id = title_table.option_type_id',
array(
'title_table.*')
);

$collection->addFieldToFilter('sku',array('like'=> '%'.$this->getQueryText().'%'));

gives me the sql

SELECT `main_table`.*, `title_table`.* FROM  `catalog_product_option_type_value` AS `main_table
 
INNER JOIN `catalog_product_option_type_title` AS `title_tableON  
main_table
.option_type_id title_table.option_type_id WHERE (sku like  '66705')
now if i add one more line

$collection->addFieldToFilter('title',array('like'=> '%'.$this->getQueryText().'%'));

i get the sql as

SELECT `main_table`.*, `title_table`.* FROM  `catalog_product_option_type_value` AS `main_table`  
INNER JOIN `catalog_product_option_type_title` AS `title_tableON  
main_table
.option_type_id title_table.option_type_id 
WHERE 
(sku like  '66705') and (title like  '66705')
now my question is how do i make query using OR in the two fields

where “66705” is my search term
thanks in advance smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top