I want to override MagentoPageBuilderModelCatalogSortingSimpleOption.php file. Please check the code below,
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoPageBuilderModelCatalogSortingSimpleOption" type="CompanyNameModuleNameModelCatalogSortingSimpleOption" />
</config>
This is Model File,
<?php
namespace CompanyNameModuleNameModelCatalogSorting;
use MagentoFrameworkDBSelect;
class SimpleOption extends MagentoPageBuilderModelCatalogSortingSimpleOption
{
/**
* @var string
*/
private $label;
/**
* @var string
*/
private $sortDirection;
/**
* @var string
*/
private $secondarySortDirection;
/**
* @var string
*/
private $attributeField;
public function __construct(
string $label,
string $sortDirection = null,
string $attributeField = null,
string $secondarySortDirection = null
){
$this->secondarySortDirection = $secondarySortDirection ?? $sortDirection;
parent::__construct(
$label,
$sortDirection,
$attributeField
);
}
public function sort(
MagentoCatalogModelResourceModelProductCollection $collection
): MagentoCatalogModelResourceModelProductCollection {
if ($this->attributeField && $this->sortDirection) {
$collection->getSelect()->reset(Select::ORDER);
$collection->addAttributeToSort($this->attributeField, $this->sortDirection);
$collection->addAttributeToSort('test_id', $this->secondarySortDirection);
}
return $collection;
}
}
It seems not working.
Can you guys please check and let me know what is the wrong in this file or any alternate way?
Thanks,