Skip to content

Commit

Permalink
fix price display while logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-development committed Aug 4, 2020
1 parent 459061d commit 4ab2db6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 1.0.2
### Fixed
- Fix showing login text, after already logged in
38 changes: 37 additions & 1 deletion Pricing/Render/FinalPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,48 @@

namespace TemplateProvider\Hideprice\Pricing\Render;

use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
/** @var \Magento\Framework\App\Http\Context */
protected $httpContext;

/**
* @param Context $context
* @param SaleableInterface $saleableItem
* @param PriceInterface $price
* @param RendererPool $rendererPool
* @param array $data
* @param SalableResolverInterface $salableResolver
* @param MinimalPriceCalculatorInterface $minimalPriceCalculator
* @param \Magento\Framework\App\Helper\Context $httpContext
*/
public function __construct(
Context $context,
SaleableInterface $saleableItem,
PriceInterface $price,
RendererPool $rendererPool,
array $data = [],
\Magento\Framework\App\Http\Context $httpContext,
SalableResolverInterface $salableResolver = null,
MinimalPriceCalculatorInterface $minimalPriceCalculator = null
) {
$this->httpContext = $httpContext;
parent::__construct($context, $saleableItem, $price, $rendererPool, $data, $salableResolver, $minimalPriceCalculator);
}

protected function _toHtml()
{
$isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
$value = $this->_scopeConfig->getValue('catalog/available/hide_price_text', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if (!empty($value)) {
if (!empty($value) && !$isLoggedIn) {
return $value;
}
return parent::_toHtml();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"magento/framework": ">100.0"
},
"type": "magento2-module",
"version": "1.0.1",
"version": "1.0.2",
"license": [
"open-source"
],
Expand Down

0 comments on commit 4ab2db6

Please sign in to comment.