Question

I can create a giftcard account as:

$model = $this->giftCAFactory->create()->setStatus(
            \Magento\GiftCardAccount\Model\Giftcardaccount::STATUS_DISABLED
        )->setWebsiteId(
            $this->_storeManager->getStore()->getId()
        )->setBalance(
            40
        )->setIsRedeemable(
            TRUE
        )->save();

N.B: I am creating with STATUS_DISABLED, if I create with STATUS_ENABLED, I can redeem that gift code as it is already activated in this case.

But I need to activate programmatically giftcard account after creation as we can do from backend:

enter image description here

I tried by loading model and setting status to enabled but it is not working as:

$model = $this->_objectManager->create(\Magento\GiftCardAccount\Model\Giftcardaccount::class);
                $model->load($id);
                $model->setStatus(
                \Magento\GiftCardAccount\Model\Giftcardaccount::STATUS_ENABLED
            );

Any help will be highly appreciated !!

Was it helpful?

Solution

As mentioned by @Rakesh save() was missing, it works now:

$model = $this->_objectManager->create(\Magento\GiftCardAccount\Model\Giftcardaccount::class);
                $model->load($id);
                $model->setStatus(
                \Magento\GiftCardAccount\Model\Giftcardaccount::STATUS_ENABLED);
                $model->save();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top