Skip to content

Commit

Permalink
Merge remote-tracking branch 'marjan/products-can-show-prices-29926' …
Browse files Browse the repository at this point in the history
…into catalog-permissions-29880
  • Loading branch information
cpartica committed Oct 7, 2020
2 parents 8d413dd + 36790c4 commit 431b2b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public function resolve(
}

$product = $value['model'];

if ($product->hasData('can_show_price') && $product->getData('can_show_price') === false) {
return [];
}

$productId = $product->getId();
$this->tiers->addProductFilter($productId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool as PriceProviderPool;
use Magento\Framework\GraphQl\Query\ResolverInterface;
Expand Down Expand Up @@ -66,10 +67,12 @@ public function resolve(
$returnArray = [];

if (isset($requestedFields['minimum_price'])) {
$returnArray['minimum_price'] = $this->getMinimumProductPrice($product, $store);
$returnArray['minimum_price'] = $this->canShowPrice($product) ?
$this->getMinimumProductPrice($product, $store) : $this->formatEmptyResult();
}
if (isset($requestedFields['maximum_price'])) {
$returnArray['maximum_price'] = $this->getMaximumProductPrice($product, $store);
$returnArray['maximum_price'] = $this->canShowPrice($product) ?
$this->getMaximumProductPrice($product, $store) : $this->formatEmptyResult();
}
return $returnArray;
}
Expand Down Expand Up @@ -130,4 +133,39 @@ private function formatPrice(float $regularPrice, float $finalPrice, StoreInterf
'discount' => $this->discount->getDiscountByDifference($regularPrice, $finalPrice),
];
}

/**
* Check if the product is allowed to show price
*
* @param ProductInterface $product
* @return bool
*/
private function canShowPrice($product): bool
{
if ($product->hasData('can_show_price') && $product->getData('can_show_price') === false) {
return false;
}

return true;
}

/**
* Format empty result
*
* @return array
*/
private function formatEmptyResult(): array
{
return [
'regular_price' => [
'value' => null,
'currency' => null
],
'final_price' => [
'value' => null,
'currency' => null
],
'discount' => null
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
/** @var PricingSpecialPrice $specialPrice */
$specialPrice = $product->getPriceInfo()->getPrice(PricingSpecialPrice::PRICE_CODE);

if ($specialPrice->getValue()) {
if ((!$product->hasData('can_show_price')
|| ($product->hasData('can_show_price') && $product->getData('can_show_price') === true)
)
&& $specialPrice->getValue()) {
return $specialPrice->getValue();
}

Expand Down

0 comments on commit 431b2b9

Please sign in to comment.