Guest User

Untitled

a guest
May 16th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. public function afterSave($insert, $changedAttributes) {
  2. if (floatval($this->offer) >= floatval($this->product->threshold_price)) {
  3. $coupon = false;
  4. $createCoupon = "";
  5. $ctr = 1;
  6. while ($coupon == false) {
  7. $createCoupon = $this->createCoupon(
  8. "Offer for " . $this->customer_name . ' #' . $this->id,
  9. $this->product->sale_price - $this->offer,
  10. $this->product_id
  11. );
  12.  
  13. if ($createCoupon || $ctr > 3) {
  14. $coupon = true;
  15. }
  16.  
  17. $ctr++;
  18. }
  19.  
  20. $this->status = self::STATUS_ACCEPTED_COUPON_GENERATED;
  21. $this->coupon_code = $createCoupon->code;
  22.  
  23. // todo this
  24. // echo "Accepted automatically then send email to customer as the same time to merchant email";
  25. } else {
  26. $this->status = self::STATUS_REJECTED;
  27. }
  28.  
  29. return parent::afterSave($insert, $changedAttributes);
  30. }
  31.  
  32. public function afterSave($insert, $changedAttributes) {
  33.  
  34. // So basically I want to update the status in afterSave
  35. $this->status = "What ever value rejected or accepted base of the outcome of generating coupon";
  36. $this->coupon = "AddTheCoupon";
  37.  
  38. // Save or Update
  39. $this->save();
  40.  
  41. return parent::afterSave($insert, $changedAttributes);
  42. }
Add Comment
Please, Sign In to add comment