我已经好好看看了,但我无法弄清楚如何在Magento Enterprise Edition中获得和设置奖励积分
我该怎么做:
$customer = Mage::getModel('customer/customer')->load($customer_id);
Mage::getModel('enterprise_reward/reward')->setPoints($customer, $points);
$points = Mage::getModel('enterprise_reward/reward')->getPoints($customer);
答案 0 :(得分:5)
想出来。做类似以下的事情:
public function getPoints($customer_id = false) {
$customer = Mage::getModel('customer/customer')->load($customer_id);
$reward = Mage::getModel('enterprise_reward/reward')
->setCustomer($customer)
->setWebsiteId(Mage::app()->getWebsite()->getId())
->loadByCustomer();
$balance = $reward->getPointsBalance();
return $balance;
}
public function setPoints($customer_id = false, $points = false, $comment = 'Adjustment', $action = 0) {
$customer = Mage::getModel('customer/customer')->load($customer_id);
$reward = Mage::getModel('enterprise_reward/reward')
->setCustomer($customer)
->setWebsiteId(Mage::app()->getWebsite()->getId())
->loadByCustomer();
$reward->setPointsBalance($points)
->setAction($action) // Enterprise_Reward_Model_Reward::REWARD_ACTION_ADMIN
->setComment($comment)
->updateRewardPoints();
$history = Mage::getModel('enterprise_reward/reward_history')
->setReward($reward)->prepareFromReward()->save();
}
答案 1 :(得分:1)
我发现接受的答案会导致很多错误,比如双点。
这是我提出的解决方案
/*REWARD POINTS ADD START*/
$customerId = 1;
$order_id = 100000689;
$points = 10;
$customer = Mage::getModel('customer/customer')->load($customerId);
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$reward = Mage::getModel('enterprise_reward/reward')
->setCustomer($customer)
->setWebsiteId(Mage::app()->getWebsite()->getId())
->loadByCustomer();
$reward->setPointsDelta($points)
->setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
->setActionEntity($order)
->setComment('Added from affiliate program')
->updateRewardPoints();
/*END*/
这样它创建了点,具有ActionEntity,正确更新了余额并设置了历史记录/