1

I have made a script for migration orders from prestashop to magento 1.8.1.0. All orders were imported successfully. I have just one problem. I don't know how to apply discount amount on order and how to show discount amount and description in customer order history list.

I tried to create cart price rule and apply it on quote with this tutorial but without success.

    ...   
    $quote = Mage::getModel('sales/quote')->load($order_no);                  
$quote->getShippingAddress()->setCollectShippingRates(false);
    $quote->collectTotals();
    $quote->setCouponCode('my_discount_code')
    $quote->save();
    ....

I tried to apply discount amount on order object with bellow code:

...
$order->setDiscount($total_discount);
...

Does anyone have any experiences with importing orders in magento and how to apply discount?

1
  • Be careful with the date the tutorials you're looking at were released. A lot happened in magento between now and then. Btw, you didn't tag your Magento version. Commented Jul 11, 2014 at 13:54

1 Answer 1

1

Ok, it is quite simple:

$orderObj->setDiscountDescription('description');
$orderObj->setDiscountAmount(-$total_discount);
$orderObj->setBaseDiscountAmount(-$total_discount);
$orderObj->setCouponRuleName('rule');
$orderObj->setCouponCode('code');
2
  • Magento normally also distributes the discount amounts across the items. I would suggest taking a look on the database level how the order is saved when placing an order via Magento vs your script. Commented Sep 14, 2014 at 23:54
  • Please accept your own answer to mark this question as resolved. This platform is still in beta and we need to reach an answer rate of 80%. blog.stackoverflow.com/2009/01/accept-your-own-answers Thanks! Commented Nov 26, 2014 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.