Guest User

Untitled

a guest
Jan 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. [...] WHERE
  2. (
  3. attribute_1 LIKE '%foo%'
  4. AND
  5. attribute_2 LIKE '%bar%'
  6. )
  7. OR
  8. (
  9. attribute_1 LIKE '%foo%'
  10. AND
  11. attribute_2 is NULL
  12. )
  13.  
  14. $categories = Mage::getModel('catalog/category')
  15. ->getCollection()
  16. ->addAttributeToSelect('*')
  17. ->addAttributeToFilter(
  18. array(
  19. array(
  20. array(
  21. 'attribute' => 'attribute_1',
  22. 'like' => '%foo%'
  23. ),
  24. array(
  25. 'attribute' => 'attribute_2',
  26. 'like' => '%bar%'
  27. ),
  28. ),
  29. array(
  30. array(
  31. 'attribute' => 'attribute_1',
  32. 'like' => '%foo%'
  33. ),
  34. array(
  35. 'attribute' => 'attribute_2',
  36. 'null' => true
  37. ),
  38. ),
  39. )
  40. );
  41.  
  42. (
  43. attribute_1 LIKE '%foo%'
  44. AND
  45. attribute_2 LIKE '%bar%'
  46. )
  47. OR
  48. (
  49. attribute_1 LIKE '%foo%'
  50. AND
  51. attribute_2 is NULL
  52. )
  53.  
  54. attribute_1 LIKE '%foo%'
  55. AND
  56. (
  57. attribute_2 LIKE '%bar%'
  58. OR
  59. attribute_2 is NULL
  60. )
  61.  
  62. $collection->addAttributeToFilter('attribute_1', ['like' => '%foo%']);
  63. $collection->addAttributeToFilter('attribute_2', [['like' => '%bar%'], ['null' => true]]);
  64.  
  65. $collection->getSelect()->where(
  66. "(attribute_1 LIKE '%foo%' AND attribute_2 LIKE '%bar%') OR
  67. attribute_1 LIKE '%baz%' AND attribute_2 is NULL"
  68. );
  69.  
  70. WHERE (...)
  71. AND
  72. (
  73. (
  74. attribute_1 LIKE '%foo%'
  75. AND
  76. attribute_2 LIKE '%bar%'
  77. ) OR (
  78. attribute_1 LIKE '%baz%'
  79. AND
  80. attribute_2 is NULL
  81. )
  82. )
Add Comment
Please, Sign In to add comment