summaryrefslogtreecommitdiff
path: root/views/mods/mod_productview/productview.phtml
blob: ae66c3987b7faef7015bc960bb6063b42b1bbdb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php

	/**
	 * Modul Produktansichten: Ausgabe von [wpsg_productview]
	 *
	 * Das Element .wpsg_productview tauscht productview.js per Ajax aus; das versteckte Feld wpsg_atts mit der Signatur
	 * (_sig) muss in eigenen Fassungen erhalten bleiben. Seiten, Sortierung und Ansicht funktionieren auch ohne JavaScript
	 * über die Adresse (pv-pg, pv-order, pv-mode).
	 */

	if (!defined('ABSPATH')) exit;

	$v = $this->view['wpsg_mod_productview'];
	$atts = $v['atts'];
	$currency = $this->get_option('wpsg_currency');
	$prefix = (($atts['key'] === 'default')?'pv-':'pv-'.$atts['key'].'-');

	$arOrder = $v['arOrder'];
	if ($atts['order_set'] !== '') $arOrder = array_intersect_key($arOrder, array_flip(explode(',', $atts['order_set'])));

	$hidden = function($name, $value) use (&$hidden) {
		if (is_array($value)) { foreach ($value as $k => $sub) $hidden($name.'['.$k.']', $sub); return; }
		echo '<input type="hidden" name="'.esc_attr($name).'" value="'.esc_attr((string)$value).'" />';
	};

?>
<div class="wpsg_productview wpsg-pv wpsg-pv--<?php echo esc_attr($v['mode']); ?>" id="wpsg_productview_<?php echo intval($v['index']); ?>" data-wpsg-pv="<?php echo intval($v['index']); ?>" data-wpsg-pv-url="<?php echo esc_url($this->getURL(wpsg_ShopController::URL_BASKET)); ?>">

	<input type="hidden" name="wpsg_atts" value="<?php echo esc_attr((string)wp_json_encode($atts)); ?>" />

	<div class="wpsg-pv__head">

		<?php if ($v['title'] !== '') { ?>
		<h2 class="wpsg-pv__title"><?php echo esc_html($v['title']); ?></h2>
		<?php } ?>

		<p class="wpsg-pv__info" aria-live="polite"><?php if ($v['count'] > 0) {
			echo esc_html(wpsg_translate(__('Anzeige #1# – #2# von #3# Ergebnissen', 'wpsg'), ($v['page'] - 1) * $v['per_page'] + 1, $v['pageMax'], $v['count']));
		} else {
			echo esc_html__('Keine Produkte in dieser Ansicht.', 'wpsg');
		} ?></p>

		<?php if ($atts['hideorder'] !== '1' && $v['count'] > 1 && sizeof($arOrder) > 1) { ?>
		<form class="wpsg-pv__order" method="get" action="<?php echo esc_url($v['url']); ?>">
			<?php if ($v['mode'] !== $atts['mode_initial']) $hidden($prefix.'mode', $v['mode']); ?>
			<?php if (wpsg_isSizedArray($atts['filter'])) $hidden('pvf', $atts['filter']); ?>
			<label>
				<span class="wpsg-pv__order-label"><?php echo esc_html__('Sortierung', 'wpsg'); ?></span>
				<select name="<?php echo esc_attr($prefix.'order'); ?>">
					<?php foreach ($arOrder as $value => $label) { ?>
					<option value="<?php echo esc_attr($value); ?>" <?php selected($v['order'], $value); ?>><?php echo esc_html($label); ?></option>
					<?php } ?>
				</select>
			</label>
			<button type="submit" class="wpsg_button wpsg-pv__order-submit<?php echo wpsg_button_class(); ?>"><?php echo esc_html__('Sortieren', 'wpsg'); ?></button>
		</form>
		<?php } ?>

		<?php if ($atts['hideviewselect'] !== '1' && $v['count'] > 0) { ?>
		<nav class="wpsg-pv__modes" aria-label="<?php echo esc_attr__('Ansicht', 'wpsg'); ?>">
			<a href="<?php echo esc_url(wpsg_mod_productview::getStateURL($v, ['mode' => 'grid', 'pg' => $v['page']])); ?>" data-mode="grid" <?php echo (($v['mode'] === 'grid')?'aria-current="true" class="active"':''); ?>><?php echo esc_html__('Kacheln', 'wpsg'); ?></a>
			<a href="<?php echo esc_url(wpsg_mod_productview::getStateURL($v, ['mode' => 'list', 'pg' => $v['page']])); ?>" data-mode="list" <?php echo (($v['mode'] === 'list')?'aria-current="true" class="active"':''); ?>><?php echo esc_html__('Liste', 'wpsg'); ?></a>
		</nav>
		<?php } ?>

	</div>

	<?php if (wpsg_isSizedArray($v['products'])) { ?>
	<ul class="wpsg-pv__items" style="--wpsg-columns:<?php echo intval($v['cols']); ?>">
		<?php foreach ($v['products'] as $oProduct) { $product_id = intval($oProduct->id); $url = $oProduct->getProductURL(); $name = $oProduct->getProductName(); $attachment_id = $this->imagehandler->getAttachmentID($oProduct->getProductKey()); ?>
		<li class="wpsg-pv__item wpsg_productview_product_<?php echo $product_id; ?>">

			<?php if (wpsg_isSizedInt($attachment_id)) { ?>
			<a class="wpsg-pv__image" href="<?php echo esc_url($url); ?>" tabindex="-1" aria-hidden="true"><?php echo wp_get_attachment_image($attachment_id, wpsg_mod_productview::IMAGE_SIZE, false, ['alt' => '']); ?></a>
			<?php } ?>

			<div class="wpsg-pv__body">

				<h3 class="wpsg-pv__name"><a href="<?php echo esc_url($url); ?>"><?php echo esc_html($name); ?></a></h3>
				<?php $detailname = (string)$oProduct->detailname; if ($detailname !== '' && $detailname !== $name) { ?>
				<p class="wpsg-pv__detailname"><?php echo esc_html($detailname); ?></p>
				<?php } ?>

				<?php $rating = floatval($oProduct->getRating()); if ($rating > 0) { ?>
				<p class="wpsg-pv__rating" title="<?php echo esc_attr(wpsg_translate(__('#1# von 5 Sternen', 'wpsg'), wpsg_ff($rating, '', true))); ?>"><span aria-hidden="true"><?php echo str_repeat('★', intval(round($rating))).str_repeat('☆', 5 - intval(round($rating))); ?></span><span class="screen-reader-text"><?php echo esc_html(wpsg_translate(__('#1# von 5 Sternen', 'wpsg'), wpsg_ff($rating, '', true))); ?></span></p>
				<?php } ?>

				<?php if ($oProduct->canDisplayPrice()) { $price = $oProduct->getPrice(); $oldPrice = $oProduct->getOldPrice(); ?>
				<p class="wpsg-pv__price">
					<?php if ($oldPrice !== false && $oldPrice != $price) { ?>
					<span class="wpsg-pv__price-current wpsg_mod_productview_current"><?php echo esc_html(wpsg_ff($price, $currency)); ?></span>
					<del class="wpsg-pv__price-old wpsg_mod_productview_oldprice"><?php echo esc_html(wpsg_ff($oldPrice, $currency)); ?></del>
					<?php } else { ?>
					<span class="wpsg-pv__price-current"><?php echo esc_html(wpsg_ff($price, $currency)); ?></span>
					<?php } ?>
				</p>
				<?php if ($this->hasMod('wpsg_mod_fuellmenge')) { ?>
				<div class="wpsg-pv__baseprice"><?php echo $this->callMod('wpsg_mod_fuellmenge', 'renderPriceInfo', [$price, $oProduct->fmenge, $product_id]); ?></div>
				<?php } ?>
				<p class="wpsg-pv__taxnote wpsg_produkt_preishinweis">
					<?php $shipping = '<a href="'.esc_url($this->getURL(wpsg_ShopController::URL_VERSANDKOSTEN)).'">'.esc_html__('Versandkosten', 'wpsg').'</a>'; ?>
					<?php if ($this->get_option('wpsg_kleinunternehmer')) { ?>
						<?php echo wpsg_translate(esc_html__('Endpreis zzgl. #1#', 'wpsg'), $shipping); ?>
					<?php } else if ($this->getFrontendTaxview() == WPSG_NETTO) { ?>
						<?php echo wpsg_translate(esc_html__('(zzgl. #1#% MwSt. und zzgl. #2#)', 'wpsg'), esc_html(wpsg_ff($oProduct->getFrontendTaxValue())), $shipping); ?>
					<?php } else { ?>
						<?php echo wpsg_translate(esc_html__('(inkl. #1#% MwSt. und zzgl. #2#)', 'wpsg'), esc_html(wpsg_ff($oProduct->getFrontendTaxValue())), $shipping); ?>
					<?php } ?>
				</p>
				<?php } else { ?>
				<p class="wpsg-pv__price"><?php echo esc_html__('Preise werden nur für angemeldete Benutzer angezeigt.', 'wpsg'); ?></p>
				<?php } ?>

				<?php if ($this->hasMod('wpsg_mod_stock') && $this->get_option('wpsg_mod_stock_showProduct') == '1') { ?>
				<p class="wpsg-pv__stock"><?php echo esc_html(wpsg_translate(__('#1# Artikel auf Lager', 'wpsg'), intval($oProduct->stock))); ?></p>
				<?php } ?>

				<?php if ($this->hasMod('wpsg_mod_deliverytime') && $this->get_option('wpsg_mod_deliverytime_show_product') == '1') { ?>
				<p class="wpsg-pv__deliverytime">
					<?php if ($this->callMod('wpsg_mod_deliverytime', 'isStoreProduct', [$oProduct->getProductKey()])) { ?>
						<?php echo esc_html((string)$this->callMod('wpsg_mod_deliverytime', 'displayStoreText', [$oProduct->getProductKey()])); ?>
					<?php } else { $strDelay = (string)$this->callMod('wpsg_mod_deliverytime', 'displayDelayTime', [$oProduct->getProductKey()]); ?>
						<?php if ($strDelay !== '') { echo esc_html($strDelay); } else { ?>
						<?php echo esc_html__('Lieferzeit:', 'wpsg'); ?> <?php echo wp_kses_post((string)$this->callMod('wpsg_mod_deliverytime', 'displayDeliveryTime', [$oProduct->getProductKey()])); ?>
						<?php } ?>
					<?php } ?>
				</p>
				<?php } ?>

				<?php if ($this->hasMod('wpsg_mod_weight') && $this->get_option('wpsg_mod_weight_showProduct') === '1' && floatval($oProduct->weight) > 0) { ?>
				<p class="wpsg-pv__weight"><?php echo esc_html(wpsg_translate(__('Gewicht: #1#', 'wpsg'), wpsg_ff($oProduct->weight, $this->get_option('wpsg_mod_weight_unit')))); ?></p>
				<?php } ?>

				<?php $short = (string)$oProduct->getShortDescription(); if ($short !== '') { ?>
				<div class="wpsg-pv__description"><?php echo wp_kses_post($short); ?></div>
				<?php } ?>

				<div class="wpsg-pv__action">
					<?php if ($atts['button'] === '1' && wpsg_buy_in_list($oProduct)) { ?>
					<form method="post" action="<?php echo esc_url($v['url']); ?>">
						<input type="hidden" name="wpsg[produkt_id]" value="<?php echo esc_attr((string)$product_id); ?>" />
						<input type="hidden" name="wpsg[menge]" value="1" />
						<input type="hidden" name="myReferer" value="<?php echo esc_attr($v['url']); ?>" />
						<button type="submit" name="wpsg[submit]" value="1" class="wpsg_button wpsg_add_basket<?php echo wpsg_button_class(); ?>"><?php echo esc_html__('In den Warenkorb', 'wpsg'); ?><span class="screen-reader-text"><?php echo esc_html(': '.$name); ?></span></button>
					</form>
					<?php } ?>
					<a class="wpsg_button<?php echo wpsg_button_class(); ?>" href="<?php echo esc_url($url); ?>"><?php echo esc_html__('Zum Produkt', 'wpsg'); ?><span class="screen-reader-text"><?php echo esc_html(': '.$name); ?></span></a>
				</div>

			</div>

		</li>
		<?php } ?>
	</ul>
	<?php } ?>

	<?php if ($v['pages'] > 1) { ?>
	<nav class="wpsg-pv__pager wpsg_productview_pager" aria-label="<?php echo esc_attr__('Seiten', 'wpsg'); ?>">
		<?php for ($i = 1; $i <= $v['pages']; $i ++) { ?>
			<?php if ($i === $v['page']) { ?>
			<span aria-current="page"><?php echo $i; ?></span>
			<?php } else if ($i === 1 || $i === $v['pages'] || abs($i - $v['page']) <= 2) { ?>
			<a href="<?php echo esc_url(wpsg_mod_productview::getStateURL($v, ['pg' => $i])); ?>" data-page="<?php echo $i; ?>"><?php echo $i; ?></a>
			<?php } else if (abs($i - $v['page']) === 3) { ?>
			<span class="wpsg-pv__gap">…</span>
			<?php } ?>
		<?php } ?>
	</nav>
	<?php } ?>

</div>