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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度