OrderItem.php 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018-06-27
  6. * Time: 12:35
  7. */
  8. namespace iBrand\Component\Discount\Test\Models;
  9. use Illuminate\Database\Eloquent\Model;
  10. class OrderItem extends Model
  11. {
  12. protected $guarded=['id'];
  13. public function __construct(array $attributes = [])
  14. {
  15. $this->setTable(config('ibrand.app.database.prefix', 'ibrand_') . 'order_item');
  16. parent::__construct($attributes);
  17. }
  18. public function getTotal()
  19. {
  20. return $this->total;
  21. }
  22. public function recalculateAdjustmentsTotal()
  23. {
  24. $this->adjustments_total = $this->divide_order_discount + $this->item_discount;
  25. $this->recalculateTotal();
  26. }
  27. public function recalculateTotal()
  28. {
  29. $this->total = $this->units_total + $this->adjustments_total;
  30. if ($this->total < 0) {
  31. $this->total = 0;
  32. }
  33. if (null !== $this->order) {
  34. $this->order->recalculateItemsTotal();
  35. }
  36. }
  37. }