PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.29.4
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.29.4
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Models / Upsell.php
Upsell.php
129 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Models;
4
5 use SureCart\Support\Contracts\PageModel;
6
7 /**
8 * Holds the data of the Upsell.
9 */
10 class Upsell extends Model implements PageModel {
11 /**
12 * Rest API endpoint
13 *
14 * @var string
15 */
16 protected $endpoint = 'upsells';
17
18 /**
19 * Object name
20 *
21 * @var string
22 */
23 protected $object_name = 'upsell';
24
25 /**
26 * Get the upsell template id.
27 *
28 * @return string
29 */
30 public function getTemplateIdAttribute(): string {
31 $template_id = $this->attributes['metadata']->wp_template_id ?? '';
32 // use a fallback for FSE.
33 if ( wp_is_block_theme() ) {
34 // if one is not set, or it's a php file, use the fallback.
35 if ( empty( $template_id ) || false !== strpos( $template_id, '.php' ) ) {
36 return 'surecart/surecart//single-upsell';
37 }
38 }
39 return $template_id;
40 }
41
42 /**
43 * Get the bump template
44 *
45 * @return \WP_Template|false
46 */
47 public function getTemplateAttribute() {
48 $template = get_block_template( $this->getTemplateIdAttribute() );
49 return ! empty( $template->content ) ? $template : get_block_template( 'surecart/surecart//single-upsell' );
50 }
51
52 /**
53 * Get the bump template id.
54 *
55 * @return string
56 */
57 public function getTemplatePartIdAttribute(): string {
58 return $this->attributes['metadata']->wp_template_part_id ?? 'surecart/surecart//upsell-info';
59 }
60
61 /**
62 * Get the bump template part template.
63 *
64 * @return \WP_Template
65 */
66 public function getTemplatePartAttribute() {
67 $template = get_block_template( $this->getTemplatePartIdAttribute(), 'wp_template_part' );
68 if ( ! empty( $template->content ) ) {
69 return $template;
70 }
71 return get_block_template( 'surecart/surecart//upsell-info' );
72 }
73
74 /**
75 * Get Template Content.
76 *
77 * @return string
78 */
79 public function getTemplateContent() : string {
80 return wp_is_block_theme() ?
81 $this->template->content ?? '' :
82 $this->template_part->content ?? '';
83 }
84
85 /**
86 * Get the bump permalink.
87 *
88 * @return string
89 */
90 public function getPermalinkAttribute(): string {
91 if ( empty( $this->attributes['id'] ) ) {
92 return '';
93 }
94 // permalinks off.
95 if ( ! get_option( 'permalink_structure' ) ) {
96 return add_query_arg( 'sc_upsell_id', $this->id, get_home_url() );
97 }
98 // permalinks on.
99 return trailingslashit( get_home_url() ) . trailingslashit( \SureCart::settings()->permalinks()->getBase( 'upsell_page' ) ) . trailingslashit( $this->id );
100 }
101
102 /**
103 * Get the page title.
104 *
105 * @return string
106 */
107 public function getPageTitleAttribute(): string {
108 return $this->metadata->cta ?? $this->name ?? '';
109 }
110
111 /**
112 * Get the meta description.
113 *
114 * @return string
115 */
116 public function getMetaDescriptionAttribute(): string {
117 return $this->metadata->description ?? '';
118 }
119
120 /**
121 * Get the JSON Schema Array
122 *
123 * @return array
124 */
125 public function getJsonSchemaArray(): array {
126 return [];
127 }
128 }
129