Skip to content

Commit

Permalink
Merge pull request #24 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 eddd274 + 1c8e81f commit 9ec6df7
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions Model/Plugin/AfterPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,39 @@
*/
namespace Magenerds\GermanLaw\Model\Plugin;

use Magento\Framework\Pricing\Render;
use Magento\Framework\Pricing\SaleableInterface;

/**
* Class AfterPrice
* @package Magenerds\GermanLaw\Model\Plugin
*/
class AfterPrice
{
/**
* Hold final price code
*
* @var string
*/
const FINAL_PRICE = 'final_price';

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

/**
* Hold layout
*
* @var \Magento\Framework\View\LayoutInterface
*/
protected $_layout;

/**
* Hold after price html string
*
* @var null|string
*/
protected $_afterPriceHtml = null;
Expand All @@ -48,17 +69,31 @@ public function __construct(
* Plugin for price rendering in order to display after price information
*
* @param \Magento\Framework\Pricing\Render $subject
* @param $renderHtml
* @oaram \Closure $closure
* @param array $params
* @return string
*/
public function afterRender(\Magento\Framework\Pricing\Render $subject, $renderHtml)
public function aroundRender(Render $subject, \Closure $closure, ...$params)
{
// check if html is empty
if ($renderHtml == '' || str_replace("\n", "", $renderHtml) == '') {
// run default render first
$renderHtml = $closure(...$params);

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

// 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 . $this->_getAfterPriceHtml();
return $renderHtml;
}

/**
Expand All @@ -68,7 +103,7 @@ public function afterRender(\Magento\Framework\Pricing\Render $subject, $renderH
*/
protected function _getAfterPriceHtml()
{
if (is_null($this->_afterPriceHtml)) {
if (null === $this->_afterPriceHtml) {
$afterPriceBlock = $this->_layout->createBlock('Magenerds\GermanLaw\Block\AfterPrice', 'after_price');
$afterPriceBlock->setTemplate('Magenerds_GermanLaw::price/after.phtml');
$this->_afterPriceHtml = $afterPriceBlock->toHtml();
Expand Down

0 comments on commit 9ec6df7

Please sign in to comment.