Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. public function testAction(){
  2.         $num_points = -500;
  3.         $customer_id = 74160;
  4.         $comment = "YOU ARE TOTALLY GETTING POINTS";
  5.         $order_id = 345;
  6.  
  7.         /**/
  8.         // Reason Id
  9.         // Giveth = -1 : Points Redeemed on Order
  10.         //  TBT_Rewards_Model_Transfer_Reason_SystemAdjustment::REASON_TYPE_ID
  11.  
  12.         // Taketh = 6 : Administrative Adjustment
  13.         //  TBT_Rewards_Model_Transfer_Reason_Redemption::REASON_TYPE_ID
  14.  
  15.         // Status - have to use this or it doesn't reflect the current points
  16.         //          also changing the status doesn't remove it
  17.         // TBT_Rewards_Model_Transfer_Status::STATUS_APPROVED
  18.  
  19.         // Give / Take points
  20.         /**/
  21.         $transfer = Mage::getModel('rewards/transfer')
  22.         ->setStatus(null, TBT_Rewards_Model_Transfer_Status::STATUS_APPROVED )  //TODO: DERP LESS
  23.         ->setId( null )         // Creates new?
  24.         ->setCurrencyId( 1 )    //TODO: derp less
  25.         ->setQuantity( $num_points )
  26.         ->setCustomerId( $customer_id )
  27.         ->setComments( $comment )
  28.         ->setOrderId( $order_id )   //stored as reference_id in rewards_transfer_reference
  29.         ->setReasonId( TBT_Rewards_Model_Transfer_Reason_Redemption::REASON_TYPE_ID )
  30.         ->save();
  31.         /**/
  32.  
  33.         /**/
  34.         // Can't move out of STATUS_APPROVED -> TBT_Rewards_Model_Transfer_Status
  35.         // so we just create an offset
  36.         $applied_points = Mage::getModel('rewards/transfer')
  37.         ->getTransfersAssociatedWithOrder($order_id)->getFirstItem();
  38.         ->getQuantity();
  39.         /**/
  40.  
  41.  
  42.  
  43.  
  44.         //$available_pointsArr = Mage::getModel('rewards/customer')->getRewardsCustomer( $this->_customer() )->getUsablePoints();
  45.         //$available_points = array_pop($available_pointsArr);
  46.         $available_points = 10000;
  47.         $points_used = 0;
  48.  
  49.         $cartTotal = 29.9700;
  50.         $remainingTotal = $cartTotal;
  51.  
  52.  
  53.         // Figure out how many
  54.         foreach( $this->_pricePoint as $set ){
  55.             $price = $set[0];
  56.             $point = $set[1];
  57.  
  58.             if( $remainingTotal > 1 ){
  59.                 while( $remainingTotal > $price ){
  60.                     // Do we have enough points to use?
  61.                     if( $available_points > $point ){
  62.                         // Decrease total and add to the used
  63.  
  64.                         $remainingTotal -= $price;
  65.                         $points_used += $point;
  66.  
  67.  
  68.                     }else{
  69.                         break;
  70.  
  71.                     }
  72.                    
  73.                 }
  74.             }
  75.  
  76.         }
  77.         echo $points_used . " - $" . $remainingTotal . "<br/>";
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.         /* trying to walk the points side
  86.         $remainder = $available_points;
  87.         $applied_points = 0;
  88.         foreach( $this->_pointToPrice as $point => $price ){
  89.             $countIn = floor($remainder / $points);
  90.             if( $countIn ){
  91.                 $applied_points += $countIn * $point;
  92.             }
  93.         }
  94.         */
  95.  
  96.  
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement