I am importing orders from a 3rd party application, and I need to be able to set a custom shipping amount, ignoring everything in Magento.
Here's what I tried, without success:
$quote = Mage::getModel('sales/quote')->setStoreId($storeId);
$shippingAddress = $quote->getShippingAddress();
$shippingAddress
->addData($addressDetails['shipping']) // shipping data I need to save - city, region, etc
->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('tablerate_bestway')
->setPaymentMethod('cashondelivery');
$shippingAmount = mt_rand(0, 20); // value doesn't matter
// basically everything I found related to the price in the shipping address
$shippingAddress->setBaseShippingAmount($shippingAmount);
$shippingAddress->setShippingAmount($shippingAmount);
$shippingAddress->setTotalAmount('subtotal', $shippingAmount);
$shippingAddress->setData('shipping_incl_tax', $shippingAmount);
$shippingAddress->setData('base_shipping_incl_tax', $shippingAmount);
$shippingAddress->setData('shipping_taxable', $shippingAmount);
$shippingAddress->setData('base_shipping_taxable', $shippingAmount);
$shippingAddress->setData('shipping_amount_for_discount', $shippingAmount);
$shippingAddress->setData('base_shipping_amount_for_discount', $shippingAmount);
// maybe the rates have something to do with this ...
foreach ($shippingAddress->getShippingRatesCollection() as $rate) {
$rate->setPrice($shippingAmount);
}
Regardless of the value of the shipping amount I want to set, the Magento calculated value is used.
What am I missing ?