I am creating a script in which I am getting order data from third party. Everything is working fine, the issue is that I am unable to add storecredit to order. Is there any way to add store credit in order and substract them from grandtotal. Here is my code:
$order->setDiscountAmount($total_discount)->setBaseDiscountAmout($total_discount);
$order->setSubtotal($total_amount)->setBaseSubtotal($total_amount);
$order->setGrandTotal($total_amount-$total_discount)->setBaseGrandTotal($total_amount-$total_discount);
$order->save();
I wanted to do the same thing, and looking at the comments, I think it's ridiculous that this thread just died. Either you are here to help and assist, or you are not. If the thread dies because you enforce a question standard, is that helpful?
Here is how to do it.
$balance = Mage::getModel('enterprise_customerbalance/balance')
->setWebsiteId(Mage::app()->getStore($quote->getStoreId())->getWebsiteId())
->setCustomerId($quote->getCustomerId())
->loadByCustomer();
if ($balance && $balance >= $creditTobeUsed) {
$quote->setUseCustomerBalance(true);
$quote->setCustomerBalanceInstance($balance);
}
$quote->collectTotals();
$quote->save();
Enterprise_CustomerBalance_Block_Checkout_Onepage_Payment_Additional has some methods which you can use
Finally, when credit is applied, at the checkout make sure that you set the following
<input type="hidden" type="text" value="1" name="payment[use_customer_balance]" class="input-text" />