PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.9.2
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.9.2
4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / widgets / lazy-cache.php
shopengine / widgets Last commit date
add-to-cart 4 days ago additional-information 3 years ago advanced-search 1 year ago archive-description 3 years ago archive-products 4 days ago archive-result-count 2 years ago archive-title 1 year ago archive-view-mode 2 years ago breadcrumbs 4 years ago call-for-price 10 months ago cart-table 4 days ago cart-totals 4 days ago checkout-coupon-form 4 days ago checkout-form-additional 3 years ago checkout-form-billing 2 years ago checkout-form-login 3 years ago checkout-form-shipping 4 days ago checkout-payment 3 years ago checkout-review-order 2 years ago checkout-shipping-methods 2 years ago cross-sells 4 days ago deal-products 2 years ago empty-cart-message 2 years ago filter-orderby 2 years ago filter-products-per-page 3 years ago filterable-product-list 1 year ago init 4 days ago notice 2 years ago product-categories 3 years ago product-category-lists 1 year ago product-description 2 years ago product-excerpt 3 years ago product-image 1 year ago product-list 4 days ago product-meta 2 years ago product-price 3 years ago product-rating 4 days ago product-review 2 years ago product-share 2 years ago product-sku 3 years ago product-stock 10 months ago product-tabs 4 days ago product-tags 3 years ago product-title 2 years ago qr-code 10 months ago recently-viewed-products 1 year ago related 4 days ago return-to-shop 2 years ago up-sells 4 days ago view-single-product 3 years ago lazy-cache.php 3 years ago manifest.php 4 days ago prod-short-code.php 2 years ago products.php 3 years ago shop.php 3 years ago widget-helper.php 4 days ago
lazy-cache.php
124 lines
1 <?php
2
3 namespace ShopEngine\Widgets;
4
5 use ShopEngine\Modules\Swatches\Swatches;
6
7 defined('ABSPATH') || exit;
8
9 trait Lazy_Cache {
10
11 private $cache_objects;
12
13 private function cache($query_type, $query_arg) {
14
15 $cache_key = $this->generate_key_hash($query_type, $query_arg);
16
17 if(isset($this->cache_objects[$cache_key])) {
18 return $this->cache_objects[$cache_key];
19 }
20
21 switch($query_type) {
22 default:
23 case 'wc_get_products':
24 $query_object = wc_get_products($query_arg);
25 break;
26
27 case 'wc_get_orders-woocommerce_my_account_my_orders_query':
28 $query_object = wc_get_orders(
29 apply_filters(
30 'woocommerce_my_account_my_orders_query',
31 $query_arg
32 )
33 );
34 break;
35
36 case 'wc_get_orders':
37 $query_object = wc_get_orders($query_arg);
38 break;
39
40 case 'get_posts':
41 $query_object = get_posts($query_arg);
42 break;
43
44 case 'wc_get_product':
45 $query_object = wc_get_product($query_arg);
46 break;
47
48 case 'get_post_meta':
49 $query_object = get_post_meta($query_arg[0], $query_arg[1], $query_arg[2]);
50 break;
51
52 case 'get_all_color_terms':
53 $query_object = $this->get_custom_terms(Swatches::PA_COLOR, 'color');
54 break;
55
56 case 'get_all_image_terms':
57 $query_object = $this->get_custom_terms(Swatches::PA_IMAGE, 'image');
58 break;
59
60 case 'get_all_label_terms':
61 $query_object = $this->get_custom_terms(Swatches::PA_LABEL, 'label');
62 break;
63 }
64
65 $this->cache_objects[$cache_key] = $query_object;
66
67 return $query_object;
68 }
69
70 public function get_custom_terms($option_key, $key) {
71
72 $attribute_taxonomies = wc_get_attribute_taxonomies();
73 $taxonomy_terms = [];
74
75 if(!empty($attribute_taxonomies)) {
76 foreach($attribute_taxonomies as $tax) {
77 if($option_key === $tax->attribute_type) {
78 $attribute_name = wc_attribute_taxonomy_name($tax->attribute_name);
79 if(taxonomy_exists($attribute_name)) {
80 $taxonomy_terms[$tax->attribute_name] = get_terms($attribute_name, 'hide_empty=0');
81 }
82 }
83 }
84 }
85
86 $terms = $this->array_flatten($taxonomy_terms);
87
88 if(is_array($terms) && !empty($terms)) {
89 foreach($terms as $term) {
90 $term_id = $term->term_id;
91 $meta_value = get_term_meta($term_id, $option_key, true);
92 $term->{$key} = $meta_value;
93 }
94 }
95
96 return $terms;
97 }
98
99 public function array_flatten($array) {
100 if(!is_array($array)) {
101 return false;
102 }
103
104 $result = [];
105 foreach($array as $key => $value) {
106 if(is_array($value)) {
107 $result = array_merge($result, $this->array_flatten($value));
108 } else {
109 $result[$key] = $value;
110 }
111 }
112
113 return $result;
114 }
115
116 public function get_cache_objects() {
117 return $this->cache_objects;
118 }
119
120 private function generate_key_hash($string, $array) {
121 return $string . md5(serialize($array));
122 }
123 }
124