PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.23k stars 4.81k forks source link

Some product information are lost or altered using a simple ObjectModel save #17560

Open prestamodule opened 4 years ago

prestamodule commented 4 years ago

Describe the bug When using save() method on a product object, there are some issues

To Reproduce Into a module, or anywhere in a file... Use this simple code snippet:

$product = new Product(1);
$product->save();

After the save(), unit price value displayed into BackOffice is reset to 0.

Now, if you are using this code snippet:

// Let's use true as 2nd parameter to retrieve full product information
$product = new Product(1, true);
$product->save();

After the save():

khouloudbelguith commented 4 years ago

Hi @prestamodule,

Thanks for your report. I manage to reproduce the issue with PS1.7.6.3 & PS1.7.5.2. https://drive.google.com/file/d/1oGN0-ycdvMiu5wCUmR7YjzJtLd61KYjr/view I used this script

<?php
require dirname(__FILE__).'/config/config.inc.php';
$product = new Product();
$product->id = 1;
$product->active = 0;
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => 'testing');
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'test');
$force_ids = true;
//this will force ObjectModel to use your ID
$product->force_id = (bool) $force_ids;
$product->save();
echo "Done, pro well updated";
?>

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!

Related to: https://github.com/PrestaShop/PrestaShop/issues/17449

Hlavtox commented 1 year ago

Current behavior on develop.

Why

In ProductCore __construct, there is this line.. $this->price = Product::getPriceStatic((int) $this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice); then when you check getPriceStatic, there is $with_ecotax = true, parameter, which causes ecotax to be added to price.

Correct solution I see is to gradually remove everything from the constructor, so the object model really serves only as a data storage.

Ping @kpodemski

hibatallahAouadni commented 1 year ago

Ping @Hlavtox & @kpodemski did you reproduce this issue with 81x?