PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.20
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.20
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
fluent-cart / app / Services / ShortCodeParser / Parsers / ItemParser.php

ItemParser.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.20, at app/Services/ShortCodeParser/Parsers/ItemParser.php

56 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\ShortCodeParser\Parsers;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\Framework\Support\Arr;
7
8 class ItemParser extends BaseParser
9 {
10 private $item;
11 private $order;
12
13 public function __construct($data)
14 {
15 $this->item = Arr::get($data, 'item', []);
16 $this->order = Arr::get($data, 'order');
17 parent::__construct($data);
18 }
19
20 public function parse($accessor = null, $code = null, $transformer = null): ?string
21 {
22 $item = $this->item;
23
24 switch ($accessor) {
25 case 'sl':
26 return (string) ($item['sl'] ?? '');
27 case 'name':
28 return esc_html(!empty($item['post_title']) ? $item['post_title'] : ($item['title'] ?? ''));
29 case 'variant':
30 return esc_html($item['title'] ?? '');
31 case 'quantity':
32 return esc_html($item['quantity'] ?? '');
33 case 'price':
34 return isset($item['line_total']) ? (string) ($item['line_total'] / 100) : '';
35 case 'price_formatted':
36 return $item['formatted_total'] ?? '';
37 case 'unit_price':
38 return isset($item['unit_price']) ? (string) ($item['unit_price'] / 100) : '';
39 case 'unit_price_formatted':
40 $unitPrice = isset($item['unit_price']) ? Helper::toDecimal($item['unit_price']) : '';
41 return esc_html($unitPrice);
42 case 'subtotal':
43 return isset($item['subtotal']) ? (string) ($item['subtotal'] / 100) : '';
44 case 'subtotal_formatted':
45 $subtotal = isset($item['subtotal']) ? Helper::toDecimal($item['subtotal']) : '';
46 return esc_html($subtotal);
47 case 'payment_info':
48 return wp_kses_post($item['payment_info'] ?? '');
49 case 'payment_type':
50 return esc_html($item['payment_type'] ?? '');
51 default:
52 return Arr::get($item, $accessor, '');
53 }
54 }
55 }
56