PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.6
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.6
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
← All changes | app/Models/OrderItem.php +40 -11 1.3.28 → 1.6.6 View file →
@@ -7,8 +7,9 @@
7 7 use FluentCart\App\Models\Concerns\CanSearch;
8 8 use FluentCart\App\Models\Concerns\CanUpdateBatch;
9 9 use FluentCart\App\Models\WpModels\PostMeta;
10 10 use FluentCart\Framework\Database\Orm\Relations\HasOne;
11 +use FluentCart\Framework\Support\Arr;
11 12
12 13 /**
13 14 * OrderItem Model - DB Model for Order Items
14 15 *
@@ -54,19 +55,19 @@
54 55 'payment_type',
55 56 'created_at',
56 57 // 'shipping_charge'
57 58 ];
58 - protected $appends = ['payment_info', 'setup_info', 'is_custom'];
59 + protected $appends = ['payment_info', 'setup_info', 'is_custom', 'variation_display_title'];
59 60
60 61 protected $casts = [
61 - 'unit_price' => 'double',
62 - 'cost' => 'double',
63 - 'subtotal' => 'double',
64 - 'tax_amount' => 'double',
65 - 'shipping_charge' => 'double',
66 - 'discount_total' => 'double',
67 - 'line_total' => 'double',
68 - 'refund_total' => 'double',
62 + 'unit_price' => 'double',
63 + 'cost' => 'double',
64 + 'subtotal' => 'double',
65 + 'tax_amount' => 'double',
66 + 'shipping_charge' => 'double',
67 + 'discount_total' => 'double',
68 + 'line_total' => 'double',
69 + 'refund_total' => 'double',
69 70 ];
70 71
71 72 protected static function booted()
72 73 {
@@ -76,11 +77,19 @@
76 77 }
77 78
78 79 protected function getFormattedTotalAttribute()
79 80 {
80 - return Helper::toDecimal($this->subtotal);
81 + if ($this->line_total == 0 && $this->discount_total == 0) {
82 + return Helper::toDecimal($this->subtotal);
83 + }
84 + return Helper::toDecimal($this->line_total);
81 85 }
82 86
87 + public function getCouponDiscountAttribute()
88 + {
89 + return (int)($this->line_meta['coupon_discount'] ?? 0);
90 + }
91 +
83 92 public function setOtherInfoAttribute($value)
84 93 {
85 94 if (is_array($value) || is_object($value)) {
86 95 $this->attributes['other_info'] = json_encode($value);
@@ -230,12 +239,32 @@
230 239 }
231 240
232 241 public function getDisplayTitle()
233 242 {
234 - if($this->post_title == $this->title) {
243 + if ($this->post_title == $this->title) {
235 244 return $this->title;
236 245 }
237 246
238 247 return $this->post_title . ' - ' . $this->title;
239 248
249 + }
250 +
251 + /**
252 + * Labeled attribute combination resolved from the frozen
253 + * other_info['item_attributes'] snapshot, e.g. "Color: Red | Size: XS".
254 + * Falls back to the stored variation title when no attribute snapshot
255 + * resolves (custom/simple items, or attrs whose groups were removed).
256 + *
257 + * @return string
258 + */
259 + public function getVariationDisplayTitleAttribute()
260 + {
261 + // Order items carry the item_attributes snapshot (written at order
262 + // creation), so resolve directly — getDisplayAttributesString renders
263 + // the labeled combination and falls back to the variation title.
264 + return \FluentCart\App\Helpers\AttributeHelper::getDisplayAttributesString(
265 + Arr::get($this->other_info, 'item_attributes', []),
266 + $this,
267 + 'order_item'
268 + );
240 269 }
241 270 }