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