douweinu8562 2018-04-17 17:19
浏览 73

Prestashop $ product-> save()并不总是保存

I'm sending some data via cURL to PS SitemapController i overwrote :

With that data i proceed in a custom function like that :

$product = new Product($_POST['id']);
$product->price = $_POST['price'];
$product->wholesale_price = $_POST['wholesale_price'];
$product->unity = $_POST['unity'];
$product->save();

Then my problem happens : sometimes it will save my changes to the product, sometimes not.

To be sure i was always sending the data to the controller, i'm creating a log.txt file right before the $product->save() line, with data written in there. I checked, and my wordpress plugin is systematically sending the data to the controller and the function. The problem really seems to appear on save() function because a fputs right after product->save() won't do anything (when it is not saved btw).

Hopefully someone will know more about this and be a light on my path!

  • 写回答

1条回答 默认 最新

  • douan7529 2018-04-18 08:03
    关注

    Thanks to TheDrot and Alexander Grosul, for giving me paths to resolve my problem.

    I replaced my save() action by the update() action and wrapped the whole thing with try catch block, logged the thrown exception, and turned PS on debug mode.

    After doing some maths to calculate price with taxes, in certain cases, the result was a long float and prestashop couldn't accept that as a product price. The exception thrown was 'price not valid'. So i solved it with round() and everything works well now, updating product each time. I was so unsure about the prestashop cache system i didn't think of it... Thanks again ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。