2013-10-01 66 views

回答

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

我發現接受的答案會導致很多錯誤,如雙點。

這是我想出了問心無愧

/*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,正確地更新餘額,並將歷史/

相關問題