Skip to content

Commit

Permalink
Merge pull request #25 from TheSamsa/master
Browse files Browse the repository at this point in the history
fix double 'tax text' for price block. It occured because both, final…
  • Loading branch information
sydekumf authored Feb 7, 2018
2 parents 3a742dd + e738104 commit 0237ee9
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions Model/Plugin/AfterPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@
class AfterPrice
{
/**
* Holds the tier price key
* Hold final price code
*
* @var string
*/
const TIER_PRICE_KEY = 'tier_price';
const FINAL_PRICE = 'final_price';

/**
* Hold tier price code
*
* @var string
*/
const TIER_PRICE = 'tier_price';

/**
* @var LayoutInterface
Expand Down Expand Up @@ -59,13 +68,24 @@ public function __construct(
* @param $renderHtml string
* @return string
*/
public function aroundRender(Render $subject, callable $proceed, $priceCode, SaleableInterface $saleableItem, array $arguments = [])
public function aroundRender(Render $subject, \Closure $closure, ...$params)
{
$renderHtml = $proceed($priceCode, $saleableItem, $arguments);
// run default render first
$renderHtml = $closure(...$params);

try{
// Get Price Code and Product
list($priceCode, $productInterceptor) = $params;
$emptyTierPrices = empty($productInterceptor->getTierPrice());

// we decided to skip tier prices, read why: https://github.com/Magenerds/BasePrice/issues/15
if ($priceCode != self::TIER_PRICE_KEY){
$renderHtml .= $this->getAfterPriceHtml($saleableItem);
// If it is final price block and no tier prices exist set additional render
// If it is tier price block and tier prices exist set additional render
if ((static::FINAL_PRICE === $priceCode && $emptyTierPrices) || (static::TIER_PRICE === $priceCode && !$emptyTierPrices)) {
$renderHtml .= $this->_getAfterPriceHtml();
}
} catch (\Exception $ex) {
// if an error occurs, just render the default since it is preallocated
return $renderHtml;
}

return $renderHtml;
Expand Down Expand Up @@ -109,4 +129,4 @@ protected function getAfterPriceHtml(SaleableInterface $product)

return $this->afterPriceHtml[$product->getId()];
}
}
}

0 comments on commit 0237ee9

Please sign in to comment.