Skip to content

Commit

Permalink
Add excl tax price in price range (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrsKondratjevs authored Dec 28, 2020
1 parent 335866f commit 469e2a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/Model/Resolver/Product/PriceRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount;
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool as PriceProviderPool;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -95,7 +94,10 @@ protected function getMinimumProductPrice(SaleableInterface $product, StoreInter
$regularPrice = (float) $priceProvider->getMinimalRegularPrice($product)->getValue();
$finalPrice = (float) $priceProvider->getMinimalFinalPrice($product)->getValue();
$discount = $this->calculateDiscount($product, $regularPrice, $finalPrice);
$minPriceArray = $this->formatPrice($regularPrice, $finalPrice, $discount, $store);
$regularPriceExclTax = (float) $priceProvider->getMinimalRegularPrice($product)->getBaseAmount();
$finalPriceExclTax = (float) $priceProvider->getMinimalFinalPrice($product)->getBaseAmount();

$minPriceArray = $this->formatPrice($regularPrice, $regularPriceExclTax, $finalPrice, $finalPriceExclTax, $discount, $store);
$minPriceArray['model'] = $product;
return $minPriceArray;
}
Expand All @@ -113,7 +115,10 @@ protected function getMaximumProductPrice(SaleableInterface $product, StoreInter
$regularPrice = (float) $priceProvider->getMaximalRegularPrice($product)->getValue();
$finalPrice = (float) $priceProvider->getMaximalFinalPrice($product)->getValue();
$discount = $this->calculateDiscount($product, $regularPrice, $finalPrice);
$maxPriceArray = $this->formatPrice($regularPrice, $finalPrice, $discount, $store);
$regularPriceExclTax = (float) $priceProvider->getMinimalRegularPrice($product)->getBaseAmount();
$finalPriceExclTax = (float) $priceProvider->getMinimalFinalPrice($product)->getBaseAmount();

$maxPriceArray = $this->formatPrice($regularPrice, $regularPriceExclTax, $finalPrice, $finalPriceExclTax, $discount, $store);
$maxPriceArray['model'] = $product;
return $maxPriceArray;
}
Expand All @@ -126,17 +131,31 @@ protected function getMaximumProductPrice(SaleableInterface $product, StoreInter
* @param StoreInterface $store
* @return array
*/
protected function formatPrice(float $regularPrice, float $finalPrice, array $discount, StoreInterface $store): array
{
protected function formatPrice(
float $regularPrice,
float $regularPriceExclTax,
float $finalPrice,
float $finalPriceExclTax,
array $discount,
StoreInterface $store
): array {
return [
'regular_price' => [
'value' => $regularPrice,
'currency' => $store->getCurrentCurrencyCode()
],
'regular_price_excl_tax' => [
'value' => $regularPriceExclTax,
'currency' => $store->getCurrentCurrencyCode()
],
'final_price' => [
'value' => $finalPrice,
'currency' => $store->getCurrentCurrencyCode()
],
'final_price_excl_tax' => [
'value' => $finalPriceExclTax,
'currency' => $store->getCurrentCurrencyCode()
],
'discount' => $discount,
];
}
Expand Down
8 changes: 8 additions & 0 deletions src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ type Products {
max_price: Float @doc(description: "Maximal price among all selected items")
}

type ProductPrice @doc(description: "Represents a product price.") {
regular_price: Money! @doc(description: "The regular price of the product.")
regular_price_excl_tax: Money! @doc(description: "The regular price of the product excluding taxes.")
final_price: Money! @doc(description: "The final price of the product after discounts applied.")
final_price_excl_tax: Money! @doc(description: "The final price of the product after discounts applied excluding taxes.")
discount: ProductDiscount @doc(description: "The price discount. Represents the difference between the regular and final price.")
}

type ProductStockItem {
qty: Float @doc(description: "Product quantity available in stock")
min_sale_qty: Int @doc(description: "Minimal amount of item that can be bought")
Expand Down

0 comments on commit 469e2a2

Please sign in to comment.