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

Cannot add a position_in_category using webservices #14903

Open
Tracked by #10069 ...
lewis2413 opened this issue Jul 29, 2019 · 9 comments · May be fixed by Shoprunners/PrestaShop#1
Open
Tracked by #10069 ...

Cannot add a position_in_category using webservices #14903

lewis2413 opened this issue Jul 29, 2019 · 9 comments · May be fixed by Shoprunners/PrestaShop#1
Labels
1.7.5.2 Affects versions B2B Bug Type: Bug Detected by TE Issue detected by TE Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Old Products Page Concerns the old product page Ready Status: Issue is ready to be worked on Topwatchers Backlog prioritization: issue reported & followed by +6 people Verified The issue has been reproduced WS Category: Web Service

Comments

@lewis2413
Copy link

lewis2413 commented Jul 29, 2019

###Describe the bug
I´m trying to change the position of a product into category using the prestashop api but don´t working for me since that webservice generates a ramdon position skiping that i have done.

To reproduce this error I use the postman tool and the xml product structure

Expected behavior

If we have an empty category and we set position_in_category to 1, the product is added into the category.

Steps to reproduce

1 . have empty category
2 . call API to create a product into that category passing position_in_category equals to 1.

Acceptance Test

Unskip tests

Additional information

PrestaShop version: 1.7.5.0 & 1.7.8.8
PHP version: 7.0.33

@khouloudbelguith khouloudbelguith added WS Category: Web Service Old Products Page Concerns the old product page labels Jul 30, 2019
@khouloudbelguith
Copy link
Contributor

Hi @lewis2413,

I manage to reproduce the issue with PS1.7.6.0 & PS1.7.5.2.
I attached a screen record
https://drive.google.com/file/d/1kTDiNC19Xk5kd0m-vhijwK9axB8laymI/view
I used this script to update the position of a product

<title>CRUD Tutorial - Create example</title>
<?php
/**
 * Created by PhpStorm.
 * User: khouloud.belguith
 * Date: 30/09/17
 * Time: 11:58
 */
define('DEBUG', true);
ini_set('display_errors','on');
define('PS_SHOP_PATH', 'http://shop.com');
define('PS_WS_AUTH_KEY', 'Key');
require_once('PSWebServiceLibrary.php');
$webService= new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$id =  23; 
$category_id = 3;
$xml = $webService->get(array('resource' => 'products', 'id' => $id));
unset($xml->product->manufacturer_name);
unset($xml->product->quantity);

$product = $xml->children()->children();
$product->name->language[0][0] = "Produit webservice";

$product->description->language[0][0] = "Description produit webservice";

$product->price = 1.121;
$product->position_in_category = 1;
//I don't update XML, i just resend it here
$opt['putXml'] = $xml->asXML();                  
$opt['id'] = $id;
$opt['category_id'] = $category_id;
$opt['resource'] = 'products';

$xml = $webService->edit($opt);

echo "DONE";

I’ll add this to the debug roadmap so that it’s fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

@khouloudbelguith khouloudbelguith added 1.7.5.2 Affects versions 1.7.6.0 Affects versions Bug Type: Bug Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Ready Status: Issue is ready to be worked on labels Jul 30, 2019
@lewis2413
Copy link
Author

lewis2413 commented Jul 30, 2019 via email

@lewis2413
Copy link
Author

Hi good afternoon,

@khouloudbelguith Do you have any feedback about this problem? i´m contacting to you because we need some solution about this bug..

I'll hope your comments

thanks advance

@khouloudbelguith
Copy link
Contributor

Hi @lewis2413,

Sorry, this issue is not yet.
There are some major issues to solve before this one.
But PrestaShop is an open source project, so it can be solved before if someone submits a pull request to solve it.
Thanks!

@Jeydh
Copy link

Jeydh commented Oct 4, 2019

I'm not sure it's related to this problem but the function setWsCategories() in classes/Product.php looks to work in a wrong way to me.
No matter what you send in position_in_category, the datas in category_product table (sorted by product id) is deleted and recreated as if it was sorted by the category id.
Feel free to check that by yourself, it's only my observations, maybe I got something wrong.

I'm not a pro in PrestaShop code so I won't dare to submit a pull request but I hope those infos will help to fix this issue.

@TomLorenzi
Copy link
Contributor

I've made a PR normally handling this bug : #31342

@afdev82
Copy link

afdev82 commented Mar 12, 2024

I am getting this bug too... The category is not empty, and I can't set the position_in_category for the new product, because I get this error:

Error on creating product: This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error - (Code 135): Non puoi impostare una posizione maggiore del numero complessivo dei prodotti nella categoria, che comincia da 1.

Position in category is 4 and in the category I have already 3 products.
I have found why: the PR #16697 changed the condition in the Product.php class.
For a new product that cannot work, because its position will be always bigger of the current count.
I will try to fix it myself and see, but I am new to Prestashop.

The problem is that I get a new product without any position_in_category set and the result is that in the cart I can't update the quantity of that product, I get an error (in the developer console of the browser) that the product is not available. In the front end the quantity returns back to the previous value.
If I save the product in the backed, I can update the quantity in the cart and I notice that position_in_category has been set.

@prestashop-issue-bot prestashop-issue-bot bot added the Topwatchers Backlog prioritization: issue reported & followed by +6 people label Mar 12, 2024
@TomLorenzi
Copy link
Contributor

@afdev82 If you want to spend some times you can juste use my previous PR #31342 and fix the bug that was reported by the QA Team, the logic was already validated.

@afdev82
Copy link

afdev82 commented Mar 12, 2024

@TomLorenzi Yes, I have already seen that PR, but in my opinion the real problem in that function is that it cannot update a row that doesn't exist in the DB (in the case of a new product created with the Webservice: https://github.com/PrestaShop/PrestaShop/pull/31342/files#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R7195

I don't think I could find a general solution that could work, because I don't know so much Prestashop.
As I can see the problem with a completely new product is that in the setWsPositionInCategory function we don't have yet the product ID, then I can't create the row for the position in the category_product table.

Maybe someone with more experience could help here, for the moment I am just creating the row in my class, where I know (after the product creation) the product ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.5.2 Affects versions B2B Bug Type: Bug Detected by TE Issue detected by TE Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Old Products Page Concerns the old product page Ready Status: Issue is ready to be worked on Topwatchers Backlog prioritization: issue reported & followed by +6 people Verified The issue has been reproduced WS Category: Web Service
Projects
None yet
7 participants