Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Product.php #1

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7069,8 +7069,10 @@ public function setWsPositionInCategory($position)
'WHERE `id_category` = ' . (int) $this->id_category_default . ' ' .
'ORDER BY `position`'
);

$product_count = count($result);

if ($position > count($result)) {
if ($position > $product_count && $product_count > 0) {
WebserviceRequest::getInstance()->setError(
500,
$this->trans(
Expand All @@ -7087,7 +7089,9 @@ public function setWsPositionInCategory($position)
// result is indexed by recordset order and not position. positions start at index 1 so we need an empty element
array_unshift($result, null);
foreach ($result as &$value) {
$value = $value['id_product'];
if($value != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just move the array unshift after the foreach would avoid getting for logic in here

$value = $value['id_product'];
}
}

$current_position = $this->getWsPositionInCategory();
Expand Down