0

I am getting product options by using below code.

$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);

Now I want to sort them in Desc order so the last inserted will render first.

Is there anyway to do the same.

1

well you basically are retrieving a collection, so you should be able to sort it as you wish, by using setOrder():

$customOptionsCollection = clone customOptions;
$customOptionsCollection->setOrder(
    'option_id',
    'desc'
)

sidenote you should avoid instantiation via object manager as it is a bad practice.

1
  • This is not working as the collection already sorting by title. I need to override the function. – urfusion Mar 13 at 6:24

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.