Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed AfterPrice not working on configurables #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Block/AfterPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ public function __construct(
parent::__construct($context, $data);
}

/**
* Loops through all childs and returns true if at least one of the childs has a base price amount set.
* This extra check is needed to fix a bug where the html tag was not created if the parent product
* didn't have a product amount configured but one of the childs did. This resulted in the base price not
* showing at all because the js didn't have a container to add the base price into.
*
* @return bool
*/
public function hasChildWithBasePrice(): bool {

if(!$this->isConfigurable()) {
return false;
}

foreach ($this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct()) as $child) {
if(!empty($child->getData('baseprice_product_amount'))) {
return true;
}
}

return false;
}

/**
* Returns the configuration if module is enabled
*
Expand All @@ -79,7 +102,7 @@ public function isEnabled()

$productAmount = $this->getProduct()->getData('baseprice_product_amount');

return $moduleEnabled && !empty($productAmount);
return $moduleEnabled && (!empty($productAmount) || $this->hasChildWithBasePrice());
}

/**
Expand Down