How to activate giftcard account after creation in magento 2
-
18-03-2021 - |
Domanda
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:
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 !!
Soluzione
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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange