Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/components/woocommerce-integration.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace Blocksy;
4 +
5 + require get_template_directory() . '/inc/components/woocommerce/general.php';
6 +
7 + require get_template_directory() . '/inc/components/woocommerce/common/layer-defaults.php';
8 + require get_template_directory() . '/inc/components/woocommerce/common/rest-api.php';
9 + require get_template_directory() . '/inc/components/woocommerce/common/cart.php';
10 + require get_template_directory() . '/inc/components/woocommerce/common/account.php';
11 + require get_template_directory() . '/inc/components/woocommerce/common/store-notice.php';
12 + require get_template_directory() . '/inc/components/woocommerce/common/mini-cart.php';
13 + require get_template_directory() . '/inc/components/woocommerce/common/sale-flash.php';
14 + require get_template_directory() . '/inc/components/woocommerce/common/stock-badge.php';
15 +
16 + require get_template_directory() . '/inc/components/woocommerce/archive/helpers.php';
17 + require get_template_directory() . '/inc/components/woocommerce/archive/index.php';
18 + require get_template_directory() . '/inc/components/woocommerce/archive/product-card.php';
19 + require get_template_directory() . '/inc/components/woocommerce/archive/loop.php';
20 + require get_template_directory() . '/inc/components/woocommerce/archive/loop-elements.php';
21 + require get_template_directory() . '/inc/components/woocommerce/archive/pagination.php';
22 +
23 + require get_template_directory() . '/inc/components/woocommerce/single/helpers.php';
24 + require get_template_directory() . '/inc/components/woocommerce/single/review-form.php';
25 + require get_template_directory() . '/inc/components/woocommerce/single/single-modifications.php';
26 + require get_template_directory() . '/inc/components/woocommerce/single/add-to-cart.php';
27 + require get_template_directory() . '/inc/components/woocommerce/single/woo-gallery.php';
28 + require get_template_directory() . '/inc/components/woocommerce/single/tabs.php';
29 +
30 + // if (class_exists('WC_Additional_Variation_Images_Frontend')) {
31 + require get_template_directory() . '/inc/components/woocommerce/integrations/woocommerce-additional-variation-images.php';
32 + // }
33 +
34 + if (class_exists('Custom_Related_Products')) {
35 + require get_template_directory() . '/inc/components/woocommerce/integrations/wt-woocommerce-related-products.php';
36 + }
37 +
38 + if (class_exists('WC_Payments')) {
39 + require get_template_directory() . '/inc/components/woocommerce/integrations/woocommerce-payments.php';
40 + }
41 +
42 + add_filter(
43 + 'blocksy_theme_autoloader_classes_map',
44 + function ($classes) {
45 + $prefix = 'inc/components/woocommerce/';
46 +
47 + $classes['WooCommerceBoot'] = $prefix . 'boot.php';
48 + $classes['WooCommerceImageSizes'] = $prefix . 'common/image-sizes.php';
49 +
50 + $classes['WooCommerceSingle'] = $prefix . 'single/single.php';
51 + $classes['WooCommerceAddToCart'] = $prefix . 'single/add-to-cart.php';
52 + $classes['SingleProductAdditionalActions'] = $prefix . 'single/additional-actions-layer.php';
53 +
54 + $classes['WooCommerceCheckout'] = $prefix . 'common/checkout.php';
55 + $classes['WooCommerceCart'] = $prefix . 'common/cart.php';
56 +
57 + return $classes;
58 + }
59 + );
60 +
61 + class WooCommerce {
62 + public $single = null;
63 + public $checkout = null;
64 + public $cart = null;
65 + public $import_export = null;
66 +
67 + private $default_variation_cache = [];
68 +
69 + public function __construct() {
70 + new WooCommerceBoot();
71 +
72 + new WooCommerceImageSizes();
73 +
74 + $this->single = new WooCommerceSingle();
75 +
76 + $this->checkout = new WooCommerceCheckout();
77 + $this->cart = new WooCommerceCart();
78 +
79 + $this->import_export = new WooImportExport();
80 + new WooVariationImagesImportExport();
81 + }
82 +
83 + public function retrieve_product_default_variation($product, $object = true) {
84 + if (isset($this->default_variation_cache[$product->get_id()])) {
85 + $cached_variation_id = $this->default_variation_cache[$product->get_id()];
86 +
87 + if ($object && $cached_variation_id) {
88 + return wc_get_product($cached_variation_id);
89 + }
90 +
91 + return $cached_variation_id;
92 + }
93 +
94 + $maybe_variation = null;
95 +
96 + $default_attributes = $product->get_default_attributes();
97 + $variation_attributes = $product->get_variation_attributes();
98 +
99 + if (count($default_attributes) === count($variation_attributes)) {
100 + $prefixed_slugs = array_map(function($pa_name) {
101 + return 'attribute_'. sanitize_title($pa_name);
102 + }, array_keys($default_attributes));
103 +
104 + $default_attributes = array_combine($prefixed_slugs, $default_attributes);
105 +
106 + $maybe_get_variation = (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
107 + $product,
108 + $default_attributes
109 + );
110 +
111 + if ($maybe_get_variation) {
112 + $maybe_variation = $maybe_get_variation;
113 + }
114 + }
115 +
116 + $has_some_matching_get_param = false;
117 +
118 + if (get_queried_object_id() === $product->get_id()) {
119 + foreach ($variation_attributes as $attribute_name => $attribute_values) {
120 + if (isset($_GET['attribute_' . $attribute_name])) {
121 + $has_some_matching_get_param = true;
122 + break;
123 + }
124 + }
125 + }
126 +
127 + if ($has_some_matching_get_param) {
128 + $maybe_get_variation = (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
129 + $product,
130 + $_GET
131 + );
132 +
133 + if ($maybe_get_variation) {
134 + $maybe_variation = $maybe_get_variation;
135 + }
136 + }
137 +
138 + // Persist only ID in the cache, no need to waste memory on full
139 + // object which are already cached by Woo.
140 + $this->default_variation_cache[$product->get_id()] = $maybe_variation;
141 +
142 + if ($object && $maybe_variation) {
143 + return wc_get_product($maybe_variation);
144 + }
145 +
146 + return $maybe_variation;
147 + }
148 + }
149 +
150 +