I want to get only the first item from the SearchCriteriaBuilder result is there any method that gives direct first item? currently using getList()->getItems() then for loop forget single item.... so I just want to know is there any shortcut method which gives the first record.....
class Promo extends \Magento\Framework\View\Element\Template{
protected $sales_rule;
protected $search_builder;
public function __construct(Template\Context $context,\Magento\SalesRule\Api\RuleRepositoryInterface $sales_rule,\Magento\Framework\Api\SearchCriteriaBuilder $search_builder,array $data = array()){
$this->sales_rule=$sales_rule;
$this->search_builder=$search_builder;
parent::__construct($context, $data);
}
public function getPromoDetail(){
$sales_rule=array();
$searchCriteria = $this->search_builder->addFilter('is_active',1,'eq')->addFilter('is_popup_rule',1,'eq')->create();
$items = $this->sales_rule->getList($searchCriteria);
foreach ($items->getItems() as $value) {
$sales_rule[]=$value;
}
return $sales_rule[0] ;
}
}