PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.2.18
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.2.18
1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 All 178 releases
disco / app / Attributes / AttributeFactory.php

AttributeFactory.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.2.18, at app/Attributes/AttributeFactory.php

160 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Disco Attribute Factory
4 *
5 * @package Disco
6 * @subpackage Disco\App\Attributes
7 * @category MyCategory
8 */
9
10 namespace Disco\App\Attributes;
11
12 /**
13 * Class AttributeFactory
14 *
15 * @package Disco
16 * @subpackage Disco\App\Attributes
17 * @author Ohidul Islam <wahid0003@gmail.com>
18 * @link https://webappick.com
19 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
20 * @category MyCategory
21 */
22 class AttributeFactory {
23
24 /**
25 * AttributeFactory constructor.
26 */
27 public function __construct() {
28 // class constructor
29 }
30
31 /**
32 * Get Attribute Type, Initialize Class and Return Value.
33 * If Method is Not Found, Return Empty String.
34 *
35 * @param string $method_name Method Name.
36 * @param array $info Class Object.
37 * @return string
38 */
39 public static function get_value( $method_name, $info ) {
40 $class_details = self::get_class_and_method( $method_name, $info );
41
42 if ( ! $class_details ) {
43 return '';
44 }
45
46 list( $class_instance, $method, $key ) = $class_details;
47
48 if ( ! method_exists( $class_instance, $method ) ) {
49 return '';
50 }
51
52 if ( $key ) {
53 return $class_instance->$method( $key );
54 }
55
56 return $class_instance->$method();
57 }
58
59 /**
60 * Get Attribute Type, Initialize Class and Return Value.
61 *
62 * @param string $method_name Method Name.
63 * @param array $info Class Object.
64 * @return array
65 */
66 public static function get_class_and_method( $method_name, $info ) {// phpcs:ignore
67 $prefix_mappings = array(
68 'customer_history' => array(
69 CustomerHistory::class,
70 null,
71 ),
72 'product_history' => array(
73 ProductHistory::class,
74 null,
75 ),
76 'customer' => array(
77 Customer::class,
78 null,
79 ),
80 'cart' => array(
81 Cart::class,
82 null,
83 ),
84 'global_attribute_' => array(
85 Product::class,
86 'get_attribute',
87 ),
88 'custom_attribute_' => array(
89 Product::class,
90 'get_attribute',
91 ),
92 'product_meta_' => array(
93 Product::class,
94 'get_product_meta',
95 ),
96 // Acf Fields.
97 'acf_fields_' => array(
98 Product::class,
99 'get_product_meta',
100 ),
101 );
102
103 foreach ( $prefix_mappings as $prefix => $class_and_method ) {
104 if ( strpos( $method_name, $prefix ) !== 0 ) {
105 continue;
106 }
107
108 $class_name = $class_and_method[0];
109
110 if ( $class_and_method[1] ) {
111 $method = $class_and_method[1];
112 } else {
113 $method = $method_name;
114 }
115
116 if ( $method === $method_name ) {
117 $key = null;
118 } else {
119 $key = str_replace( $prefix, '', $method_name );
120 }
121
122 // If the class is Cart or Customer, we don't need to pass any info.
123 if ( $class_name === Cart::class || $class_name === Customer::class ) {
124 return array(
125 new $class_name,
126 $method,
127 $key,
128 );
129 }
130
131 if ( $class_name === Product::class ) {
132 $product = $info['product'];
133 \assert( $product instanceof \WC_Product );
134
135 return array(
136 new $class_name( $product ),
137 $method,
138 $key,
139 );
140 }
141
142 return array(
143 new $class_name( $info ),
144 $method,
145 $key,
146 );
147 }//end foreach
148
149 $product = $info['product'];
150 \assert( $product instanceof \WC_Product );
151
152 return array(
153 new Product( $product ),
154 $method_name,
155 null,
156 );
157 }
158
159 }
160