Magento快速更改运费SQLSTATE [23000]

时间:2015-11-12 18:28:53

标签: php mysql magento

您好我正在尝试使用以下代码更改flye上的运费,但是当费率尝试保存时会崩溃:

$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]:完整性约束违规:1452无法添加或更新子行:外键约束失败(sales_flat_quote_shipping_rate,CONSTRAINT FK_B1F177EFB73D3EDF5322BA64AC48D150 FOREIGN KEY(address_id)REFERENCES { {1}}(sales_flat_quote_address)),查询为:INSERT INTO address_idsales_flat_quote_shipping_ratecreated_atupdated_atcarrier,{{ 1}},carrier_titlecodemethodmethod_description)价值观('2015-11-12 18:22:52','2015-11-12 18 :22:52',?,?,?,?,?,?,?)

对此错误的任何想法?

由于

1 个答案:

答案 0 :(得分:1)

从邮件中可以看出,您正在尝试为不存在的地址插入运费率行。添加一些调试信息以转储您正在插入的值,并希望这会使问题变得明显。