WackGet
WackGet

Reputation: 2916

Magento Enterprise: creating a gift card programmatically?

Using Magento EE 1.9, I want to create a bunch of gift cards (or "gift card accounts" as Magento calls them) programmatically. The docs for the SOAP API have a method for doing this, but I want to do it from within a module, i.e. using only PHP.

Basically, if I upload a list of gift codes and amounts, I want Magento to create usable gift card accounts for those. For example:

VOUCH123 = $100
VOUCH456 = $120
VOUCH789 = $150

I could create single-use coupon codes for each gift voucher but I don't think that's an elegant solution. I'd rather actually create proper gift card accounts, but I don't think this is documented anywhere.

Upvotes: 1

Views: 2712

Answers (1)

JPMC
JPMC

Reputation: 1073

Edit: My previous SOAP derivative method did not seem to have a way for inputting custom codes. This new code does.

$gift_card = Mage::getModel('enterprise_giftcardaccount/giftcardaccount');

$gift_card
    ->setCode('2i2j2j-24k1ii1-67774k-231l')
    ->setStatus($gift_card::STATUS_ENABLED)
    ->setDateExpires('2015-04-15')
    ->setWebsiteId(1)
    ->setState($gift_card::STATE_AVAILABLE)
    ->setIsRedeemable($gift_card::REDEEMABLE)
    ->setBalance(25);

$gift_card->save();

I know I'm a year late, but this may perhaps help someone in the future. This is up to date as of Magento EE 1.14 (and past versions according to the doc)

A more complete working example for your question would be

$cards = array(
'VOUCH123' => 100,
'VOUCH456' => 120,
'VOUCH789' => 150);

foreach($cards as $code=>$balance)
{
    $gift_card = Mage::getModel('enterprise_giftcardaccount/giftcardaccount');

    $gift_card
        ->setCode($code)
        ->setStatus($gift_card::STATUS_ENABLED)
        ->setWebsiteId(1)
        ->setState($gift_card::STATE_AVAILABLE)
        ->setIsRedeemable($gift_card::REDEEMABLE)
        ->setBalance($balance);

    $gift_card->save();
}

Upvotes: 2

Related Questions