PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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 trunk All 48 releases
← All changes | app/Models/OrderItem.php +32 -11 1.5.0 → 1.6.5 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 {
@@ -84,9 +85,9 @@
84 85 }
85 86
86 87 public function getCouponDiscountAttribute()
87 88 {
88 - return (int) ($this->line_meta['coupon_discount'] ?? 0);
89 + return (int)($this->line_meta['coupon_discount'] ?? 0);
89 90 }
90 91
91 92 public function setOtherInfoAttribute($value)
92 93 {
@@ -238,12 +239,32 @@
238 239 }
239 240
240 241 public function getDisplayTitle()
241 242 {
242 - if($this->post_title == $this->title) {
243 + if ($this->post_title == $this->title) {
243 244 return $this->title;
244 245 }
245 246
246 247 return $this->post_title . ' - ' . $this->title;
247 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 + );
248 269 }
249 270 }