doulu1907 2015-11-12 18:28 采纳率: 100%
浏览 25
已采纳

Magento快速更改运费SQLSTATE [23000]

Hi I am trying to change shipping price on the flye with the following code but it crash when the rate try to save it:

$shippingprice = 20.00;
$address = $quote->getShippingAddress();
$address->setShippingAmount($shippingprice);
$address->setBaseShippingAmount($shippingprice);
$rates = $address->collectShippingRates()
         ->getGroupedAllShippingRates();
$address->setCollectShippingRates(false);
$address->save();
foreach ($rates as $carrier) {
    foreach ($carrier as $rate) {
        $rate->setPrice($shippingprice);
        $rate->save();//Right here it crash 
    }
}

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (sales_flat_quote_shipping_rate, CONSTRAINT FK_B1F177EFB73D3EDF5322BA64AC48D150 FOREIGN KEY (address_id) REFERENCES sales_flat_quote_address (address_id) ), query was: INSERT INTO sales_flat_quote_shipping_rate (created_at, updated_at, carrier, carrier_title, code, method, method_description, price, method_title) VALUES ('2015-11-12 18:22:52', '2015-11-12 18:22:52', ?, ?, ?, ?, ?, ?, ?)

Any Idea of this error?

Thanks

  • 写回答

1条回答 默认 最新

  • dongmei2956 2015-11-12 18:57
    关注

    It appears from the message that you are trying to insert a shipping rate row for a non-existent address. Add some debugging info to dump out the values you are inserting and hopefully that will make the problem obvious.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭