I have developed a custom script to place orders in Magento. How can I apply a gift card to cart (quote) programatically? I can't see any related code.

closed as off-topic by 7ochem, Amit Bera, Prateek, Dexter, brentwpeterson Oct 30 '15 at 12:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: http://sscce.org/" – 7ochem, Amit Bera, Prateek, Dexter, brentwpeterson
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please add the code you are using now to create the order. – 7ochem Oct 30 '15 at 9:30

Please try below code

    $giftcardAccountCode = "Abc";
    $storeId = 1;
    $quoteId = 201;

    $quote = Mage::getModel("sales/quote");


    /** @var $giftcardAccount Enterprise_GiftCardAccount_Model_Giftcardaccount */
    $giftcardAccount = Mage::getModel('enterprise_giftcardaccount/giftcardaccount')
    if (!$giftcardAccount->getId()) {
        Mage::throwException('Giftcard Account Not Found  By Code');
    try {
        $giftcardAccount->addToCart(true, $quote);
    } catch (Exception $e) {
  • I have tried this method but it seems to be not working. The order amount found deducted from gift card balance; but, when checked the order from admin panel, there were no gift cards shown. Do you have any idea ? – iqbalmp Oct 30 '15 at 11:32
  • Sorry, It was my mistake! The admin order view shows an error ""The requested Payment Method is not available."..." Thanks! – iqbalmp Oct 30 '15 at 11:46
  • you can up-vote if that work for you – Abdul Oct 30 '15 at 11:57
  • The admin error was because of another payment issue - not related to Gift card. Now Giftcard working perfectly. Thanks! – iqbalmp Oct 30 '15 at 12:04

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