I believe the simple products of a Grouped product are sorted by ID. I would like to sort them by name. In the file /vendor/magento/module-grouped-product/Model/Product/Type/Grouped.php there is
function getAssociatedProducts($product)
.
Would adding this work?
->addAttributeToSort('name', 'asc')
If so, where would I add it to not mess with core files?
Solved! Go to Solution.
Hello @mraccine
$collection = $this->getAssociatedProductCollection( $product )->addAttributeToSelect( ['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'] )->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter( $this->getStoreFilter($product) )->addAttributeToFilter( 'status', ['in' => $this->getStatusFilters($product)] );
need to change it
$collection = $this->getAssociatedProductCollection( $product )->addAttributeToSelect( ['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'] )->addFilterByRequiredOptions()->addStoreFilter( $this->getStoreFilter($product) )->addAttributeToFilter( 'status', ['in' => $this->getStatusFilters($product)] )->setOrder('name','ASC');
you need to create around plugin for same
if works then mark as solution
Hello @mraccine
$collection = $this->getAssociatedProductCollection( $product )->addAttributeToSelect( ['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'] )->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter( $this->getStoreFilter($product) )->addAttributeToFilter( 'status', ['in' => $this->getStatusFilters($product)] );
need to change it
$collection = $this->getAssociatedProductCollection( $product )->addAttributeToSelect( ['name', 'price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'] )->addFilterByRequiredOptions()->addStoreFilter( $this->getStoreFilter($product) )->addAttributeToFilter( 'status', ['in' => $this->getStatusFilters($product)] )->setOrder('name','ASC');
you need to create around plugin for same
if works then mark as solution
Thanks, that worked perfectly!