How to get store credit in magento 2 EE?
-
06-04-2021 - |
Question
I want to get customer balance(store credit) by customer id in custom collection.
I am loading credit memo collection, so i want to show remaining customer balance with that.
La solution
Below is the code which useful to get store credit..
<?php
use \Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$instance = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$balanceCollection = $objectManager->get('Magento\CustomerBalance\Model\BalanceFactory');
$model = $balanceCollection->create();
$model->setCustomerId(1)->loadByCustomer(); // put your customer id here
echo $model->getAmount();
?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange