Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testAction(){
- $num_points = -500;
- $customer_id = 74160;
- $comment = "YOU ARE TOTALLY GETTING POINTS";
- $order_id = 345;
- /**/
- // Reason Id
- // Giveth = -1 : Points Redeemed on Order
- // TBT_Rewards_Model_Transfer_Reason_SystemAdjustment::REASON_TYPE_ID
- // Taketh = 6 : Administrative Adjustment
- // TBT_Rewards_Model_Transfer_Reason_Redemption::REASON_TYPE_ID
- // Status - have to use this or it doesn't reflect the current points
- // also changing the status doesn't remove it
- // TBT_Rewards_Model_Transfer_Status::STATUS_APPROVED
- // Give / Take points
- /**/
- $transfer = Mage::getModel('rewards/transfer')
- ->setStatus(null, TBT_Rewards_Model_Transfer_Status::STATUS_APPROVED ) //TODO: DERP LESS
- ->setId( null ) // Creates new?
- ->setCurrencyId( 1 ) //TODO: derp less
- ->setQuantity( $num_points )
- ->setCustomerId( $customer_id )
- ->setComments( $comment )
- ->setOrderId( $order_id ) //stored as reference_id in rewards_transfer_reference
- ->setReasonId( TBT_Rewards_Model_Transfer_Reason_Redemption::REASON_TYPE_ID )
- ->save();
- /**/
- /**/
- // Can't move out of STATUS_APPROVED -> TBT_Rewards_Model_Transfer_Status
- // so we just create an offset
- $applied_points = Mage::getModel('rewards/transfer')
- ->getTransfersAssociatedWithOrder($order_id)->getFirstItem();
- ->getQuantity();
- /**/
- //$available_pointsArr = Mage::getModel('rewards/customer')->getRewardsCustomer( $this->_customer() )->getUsablePoints();
- //$available_points = array_pop($available_pointsArr);
- $available_points = 10000;
- $points_used = 0;
- $cartTotal = 29.9700;
- $remainingTotal = $cartTotal;
- // Figure out how many
- foreach( $this->_pricePoint as $set ){
- $price = $set[0];
- $point = $set[1];
- if( $remainingTotal > 1 ){
- while( $remainingTotal > $price ){
- // Do we have enough points to use?
- if( $available_points > $point ){
- // Decrease total and add to the used
- $remainingTotal -= $price;
- $points_used += $point;
- }else{
- break;
- }
- }
- }
- }
- echo $points_used . " - $" . $remainingTotal . "<br/>";
- /* trying to walk the points side
- $remainder = $available_points;
- $applied_points = 0;
- foreach( $this->_pointToPrice as $point => $price ){
- $countIn = floor($remainder / $points);
- if( $countIn ){
- $applied_points += $countIn * $point;
- }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement