0

I have added following code to change the collection. The issue is that when I print the sql query then I am getting correct result(in mysql ) but after that when I print getData on collection then the products are different.

  • Can someone please guide me on it?

Thanks

$collection->addAttributeToSelect('fan_motor_height_blades', 'catalog_product_entity_varchar');
            
            $zeroPriceLast = new \Zend_Db_Expr("fan_motor_height_blades = 0.000000 ASC, fan_motor_height_blades  ASC");

            $collection->getSelect()->order($zeroPriceLast);

            //echo $collection->getSelect()->__toString();die();
            echo '<pre>';print_r($collection->getData());die(); 
5
  • Are you updating for category list collection?
    – S.P
    Jun 3 at 7:44
  • @S.P No just want to sort via filter
    – Arjun
    Jun 3 at 9:38
  • did you check with reset order? $collection->getSelect()->reset(Zend_Db_Select::ORDER)->order($zeroPriceLast);
    – S.P
    Jun 3 at 10:04
  • @S.P I tried this $zeroPriceLast = new \Zend_Db_Expr("fan_motor_height_blades = '0.000000' ASC, fan_motor_height_blades ASC"); $subject->getCollection()->getSelect()->reset(\Zend_Db_Select::ORDER)->order($zeroPriceLast);
    – Arjun
    Jun 3 at 10:41
  • Not working as needed
    – Arjun
    Jun 3 at 10:41

1 Answer 1

0

Did you try like this?

foreach($collection as $key => $value)
{
   echo "<pre>"; print_r($value->getData()); die;
}
3
  • That is taking too much time
    – Arjun
    Jun 3 at 9:37
  • It shouldn't take much time as we have already applied the die function. Only will be fetched single record? Might be something you are doing wrong in collection
    – Dotsquares
    Jun 3 at 9:54
  • Die is fine it stopped, but not sure on how to will this add 0 valued attribute at last
    – Arjun
    Jun 3 at 10:43

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.