문제

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.

도움이 되었습니까?

해결책

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();
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top