Apply gift card programatically [closed]
-
13-12-2019 - |
Question
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.
Solution
Please try below code
$giftcardAccountCode = "Abc";
$storeId = 1;
$quoteId = 201;
$quote = Mage::getModel("sales/quote");
$quote->setStoreId($storeId)
->load($quoteId);
/** @var $giftcardAccount Enterprise_GiftCardAccount_Model_Giftcardaccount */
$giftcardAccount = Mage::getModel('enterprise_giftcardaccount/giftcardaccount')
->loadByCode($giftcardAccountCode);
if (!$giftcardAccount->getId()) {
Mage::throwException('Giftcard Account Not Found By Code');
}
try {
$giftcardAccount->addToCart(true, $quote);
} catch (Exception $e) {
$e->getMessage();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange