Skip to content

Commit

Permalink
Fix #217: variant bug when page has several cartButtons
Browse files Browse the repository at this point in the history
We have to properly reset the view params, so that we do not
accidentially pick up params from an earlier rendering.  Unfortunately,
we are using some dynamic properties, what makes that slightly harder
and more brittle than necessary.

We also have to make sure that there is only ever a single element with
a certain ID.  Since there is no need to have an ID for the cart
buttons, we change that to a class.  This is a BC break, though, due to
customizations.
  • Loading branch information
cmb69 committed Jun 20, 2020
1 parent 7dc4d6c commit c857669
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions classes/Controller.php
Expand Up @@ -112,6 +112,7 @@ protected function render($template, array $params = null)
if (!($this->viewProvider instanceof View)) {
return "XHSController:render no view provider!";
}
$this->viewProvider->resetParams();
if (isset($params)) {
foreach ($params as $key => $value) {
$this->viewProvider->assignParam($key, $value);
Expand Down
6 changes: 6 additions & 0 deletions classes/View.php
Expand Up @@ -40,6 +40,12 @@ public function setCurrency($currency)
$this->currency = $currency;
}

public function resetParams()
{
$this->params = array();
unset($this->variants);
}

public function assignParam($key, $param)
{
if (is_string($param)) {
Expand Down
4 changes: 2 additions & 2 deletions css/stylesheet.css
@@ -1,5 +1,5 @@
/*** Cart-Box for CMSimple_XH-Sites ***/
#cartButton {
.cartButton {
border: 2px solid #f60;
clear: both;
margin: 2em 0;
Expand Down Expand Up @@ -75,7 +75,7 @@ input.linkButton:hover {
text-decoration: underline;
color: maroon;
}
#cartButton {
.cartButton {
border: 2px solid #f60;
clear: both;
margin: 2em 0;
Expand Down
2 changes: 1 addition & 1 deletion templates/frontend/addToCartButton.tpl
@@ -1,5 +1,5 @@
<?php ?>
<section id="cartButton" class="xhsMain">
<section class="cartButton xhsMain">
<h1 class="xhsInl xhsLft"><?php echo $this->productName; ?></h1>
<div class="xhsInfoBlock">
<div class="xhsPrdPrice"><span class="xhsPrdPriceLabel"><?php echo $this->labels['price'];?></span> <span class="xhsPrdPriceNum"><?php echo $this->formatCurrency($this->product->getGross()); ?></span></div>
Expand Down

0 comments on commit c857669

Please sign in to comment.