customerSession = $customerSession;
$this->storeManager = $storeManager;
$this->coreRegistry = $coreRegistry;
$this->eventManager = $eventManager;
$this->helper = $helper;
$this->jsonEncoder = $jsonEncoder;
$this->state = $state;
$this->isNeedRenderPrice = $isNeedRenderPrice;
}
/**
* @param PricingRender $subject
* @param callable $proceed
* @param $priceCode
* @param SaleableInterface $saleableItem
* @param array $arguments
* @return string
*/
public function aroundRender(
PricingRender $subject,
callable $proceed,
$priceCode,
SaleableInterface $saleableItem,
array $arguments = []
) {
if (!$this->isNeedRenderPrice->execute($saleableItem, $arguments)
&& $this->state->getAreaCode() != \Magento\Framework\App\Area::AREA_ADMINHTML
&& $price = $this->renderPrice($saleableItem, $priceCode, $arguments)
) {
return $price;
}
return $proceed($priceCode, $saleableItem, $arguments);
}
public function renderPrice(SaleableInterface $saleableItem, string $priceCode, array $arguments = []): ?string
{
$this->saveDataToSession($saleableItem);
$additional = $this->generateJsHideOnCategory($saleableItem);
if ($this->helper->getModuleConfig('information/hide_price')) {
$priceHtml = $this->getNewPriceHtmlBox($saleableItem, $priceCode, $arguments);
$result = $priceHtml . $additional;
}
return $result ?? null;
}
/**
* @param PricingRender $subject
* @param callable $proceed
* @param AmountInterface $amount
* @param PriceInterface $price
* @param SaleableInterface $saleableItem
* @param array $arguments
* @return string
*/
public function aroundRenderAmount(
PricingRender $subject,
callable $proceed,
AmountInterface $amount,
PriceInterface $price,
SaleableInterface $saleableItem = null,
array $arguments = []
) {
if ($this->isNeedRenderPrice->execute($saleableItem, $arguments)) {
// Show Price Box
$result = $proceed($amount, $price, $saleableItem, $arguments);
return $result;
}
return '';
}
private function getNewPriceHtmlBox($saleableItem, $priceCode, $arguments)
{
$html = '';
/* get price replacement only for final price - others is hided*/
$arguments['id_suffix'] = isset($arguments['id_suffix']) ? $arguments['id_suffix'] : '';
if (in_array($priceCode, ['final_price', 'wishlist_configured_price']) && $arguments['id_suffix'] != 'copy-') {
$html = $this->helper->getNewPriceHtmlBox($saleableItem);
}
return $html;
}
/**
* @deprecated Hiding product button in another function
* Js for for hiding product button on category page
*
* @param $saleableItem
*
* @return string
* @internal param string $sku
* @internal param int $id
*/
private function generateJsHideOnCategory($saleableItem)
{
if ($saleableItem->getHidePriceObserved()) {
return;
}
$id = $saleableItem->getId();
$name = $saleableItem->getName();
$productId = 'amhideprice-product-id-' . $id . '-' . random_int(1, 10000);
// TODO - remove js code - button is replaced by observer
$html = '
';
$saleableItem->setHidePriceObserved(true);
return $html;
}
/**
* @param $saleableItem
*/
private function saveDataToSession(SaleableInterface $saleableItem)
{
$dataArray = $this->coreRegistry->registry('amasty_hideprice_data_array');
if (!$dataArray) {
$dataArray = [];
}
$dataArray[] = [
'sku' => $saleableItem->getSku(),
'id' => $saleableItem->getId(),
'name' => $saleableItem->getName()
];
$this->coreRegistry->unregister('amasty_hideprice_data_array');
$this->coreRegistry->register('amasty_hideprice_data_array', $dataArray);
}
/**
* @param string $html
* @param $saleableItem
* @return string
*/
private function updatePriceHtml($html, $saleableItem)
{
$html .= $this->generateJsHideOnCategory($saleableItem);
return $html;
}
}