This is a quick example of how you can programmatically create a code for Magestore’s Gift Card module.
1. Create the Gift Card
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$data = array( // Valid price format without currency code 'balance' => $input['giftcard_balance'], // The currency code such as $ or € 'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(), // Please find all available statuses in the Magestore > Gift Card module 'status' => 2, // Remove the line to set no expire date 'expired_at' => strtotime('+1 month'), 'customer_id' => $customer->getId(), 'customer_name' => $customer->getFirstname(), 'customer_email' => $customer->getEmail(), 'recipient_name' => 'Recipient Name', 'recipient_email' => 'recipient@email.tld', 'extra_content' => $this->__('Created by module X') ); $giftvoucher = Mage::getModel('giftvoucher/giftvoucher') ->setData($data) ->setIncludeHistory(true) ->save(); |
2. Link the Gift Card to a Customer
In order to be able to see the Gift Card in My Account > Gift Card you need to create a reference between Gift Card and a customer id. This is something you can do right after the Gift Voucher was successfully created.
1 2 3 4 5 |
$customervoucher = Mage::getModel('giftvoucher/customervoucher') ->setCustomerId($customer->getId()) ->setVoucherId($giftvoucher->getId()) ->setAddedDate(now()) ->save(); |