carttHistoryFactory = $carttHistoryFactory; parent::__construct($context, $data); } public function getCarttHistories($customerId) { $current_page = (int) $this->getRequest()->getParam('current_page'); if ($current_page == 0) { $current_page = 1; } $size = (int) $this->getRequest()->getParam('size'); if ($size == 0) { $size = 20; } $collection = $this->carttHistoryFactory->create()->getCollection(); $data = $collection->addFieldToFilter('customer_id', ['eq' => $customerId]) ->setOrder('date','DESC') ->setPageSize($size) ->setCurPage($current_page) ->getData(); $collection = $this->carttHistoryFactory->create()->getCollection(); $total = $collection->addFieldToFilter('customer_id', ['eq' => $customerId]) ->count(); $result = array( "data" => $data, "total" => $total, "current_page" => $current_page, "size" => $size ); return $result; } } ?>