GX-Bug #55186 » RestAPIProductLimitFix.patch
src/GXMainComponents/Services/Core/Product/ProductReadService.inc.php (revision ) | ||
---|---|---|
91 | 91 |
*/ |
92 | 92 |
public function getProductList(LanguageCode $languageCode, |
93 | 93 |
IdType $categoryId = null, |
94 |
IdType $customerStatusLimit = null) |
|
94 |
IdType $customerStatusLimit = null, |
|
95 |
IntType $offset = null, |
|
96 |
IntType $limit = null) |
|
95 | 97 |
{ |
96 | 98 |
$conditions = array(); |
97 | 99 |
|
... | ... | |
108 | 110 |
} |
109 | 111 |
else |
110 | 112 |
{ |
111 |
$collection = $productListProvider->getAll(); |
|
113 |
$collection = $productListProvider->getAll($offset, $limit);
|
|
112 | 114 |
} |
113 | 115 | |
114 | 116 |
return $collection; |
... | ... | |
204 | 206 |
public function findUrlRewritesByRewriteUrl(NonEmptyStringType $rewriteUrl) |
205 | 207 |
{ |
206 | 208 |
return $this->urlRewriteStorage->findByRewriteUrl($rewriteUrl); |
209 |
} |
|
210 | ||
211 |
/** |
|
212 |
* Get the total count of all products |
|
213 |
* |
|
214 |
* @return int |
|
215 |
*/ |
|
216 |
public function getProductListCount(LanguageCode $languageCode) |
|
217 |
{ |
|
218 | ||
219 |
$productListProvider = $this->listProviderFactory->createProductListProvider($languageCode); |
|
220 | ||
221 |
return $productListProvider->getProductListCount(); |
|
207 | 222 |
} |
208 | 223 |
} |
src/GXMainComponents/Services/Core/Product/Providers/Interfaces/ProductListProviderInterface.inc.php (revision ) | ||
---|---|---|
34 | 34 |
* |
35 | 35 |
* @return ProductListItemCollection |
36 | 36 |
*/ |
37 |
public function getAll(); |
|
37 |
public function getAll(IntType $offset, IntType $limit);
|
|
38 | 38 |
} |
src/GXMainComponents/Services/Core/Product/Providers/ProductListProvider.inc.php (revision ) | ||
---|---|---|
212 | 212 |
* |
213 | 213 |
* @return ProductListItemCollection |
214 | 214 |
*/ |
215 |
public function getAll() |
|
215 |
public function getAll(IntType $offset = null, IntType $limit = null)
|
|
216 | 216 |
{ |
217 | 217 |
// Build select part of query. |
218 | 218 |
$this->db->select('products.*, products_description.*') |
... | ... | |
220 | 220 |
->join('languages', 'languages.languages_id = products_description.language_id', 'inner') |
221 | 221 |
->where('products_description.products_id = products.products_id') |
222 | 222 |
->where('languages.code', $this->languageCode->asString()); |
223 |
|
|
223 | ||
224 | 224 |
$this->_applyExtraConditions(); |
225 |
|
|
225 | ||
226 |
$this->_setLimit($offset, $limit); |
|
227 |
//var_dump($this->db->get_compiled_select()); |
|
228 |
//die(); |
|
229 | ||
226 | 230 |
$result = $this->db->get()->result_array(); |
227 | 231 |
|
228 | 232 |
return $this->_prepareCollection($result); |
233 |
} |
|
234 | ||
235 |
protected function _setLimit(IntType $offset = null, IntType $limit = null) |
|
236 |
{ |
|
237 |
if($offset !== null && $limit !== null) |
|
238 |
{ |
|
239 |
$offset = $offset->asInt(); |
|
240 |
$limit = $limit->asInt(); |
|
241 |
$this->db->limit($limit, $offset); |
|
242 |
} |
|
243 |
} |
|
244 | ||
245 |
public function getProductListCount() |
|
246 |
{ |
|
247 |
$rows = $this->db->count_all('products'); |
|
248 | ||
249 |
return $rows; |
|
229 | 250 |
} |
230 | 251 |
} |
src/GXMainComponents/Controllers/Api/v2/ProductsApiV2Controller.inc.php (revision ) | ||
---|---|---|
473 | 473 |
return; |
474 | 474 |
} |
475 | 475 | |
476 |
$page = $this->api->request->get('page'); |
|
477 |
$perPage = $this->api->request->get('per_page') |
|
478 |
!= null ? new IntType($this->api->request->get('per_page')) : new IntType(self::DEFAULT_PAGE_ITEMS); |
|
479 |
$startIndex = $page !== null ? new IntType($page * $perPage->asInt() - $perPage->asInt()) : null; |
|
480 | ||
476 | 481 |
if($this->uri[1] && is_numeric($this->uri[1])) // Get Single Record |
477 | 482 |
{ |
478 | 483 |
try |
479 | 484 |
{ |
480 | 485 |
$products = array($this->productReadService->getProductById(new IdType($this->uri[1]))); |
486 |
$productCount = 1; |
|
481 | 487 |
} |
482 | 488 |
catch(UnexpectedValueException $e) |
483 | 489 |
{ |
... | ... | |
490 | 496 | |
491 | 497 |
$languageCode = new LanguageCode(new NonEmptyStringType($langParameter)); |
492 | 498 | |
493 |
$products = $this->productReadService->getProductList($languageCode)->getArray(); |
|
499 |
$products = $this->productReadService->getProductList($languageCode,null, null, $startIndex, $perPage)->getArray(); |
|
500 |
$productCount = $this->productReadService->getProductListCount($languageCode); |
|
501 | ||
494 | 502 |
} |
495 | 503 | |
496 | 504 |
$response = array(); |
... | ... | |
515 | 523 |
} |
516 | 524 | |
517 | 525 |
$this->_sortResponse($response); |
518 |
$this->_paginateResponse($response); |
|
526 |
$this->_paginateResponse($response,$productCount);
|
|
519 | 527 |
$this->_minimizeResponse($response); |
520 | 528 |
$this->_linkResponse($response); |
521 | 529 |