Skip to content

Commit

Permalink
Merge pull request #133 from riha112/2844
Browse files Browse the repository at this point in the history
[2844] Downloadable link correct currency
  • Loading branch information
carinadues authored Nov 8, 2021
2 parents 7b22fd7 + 0d498dc commit 7fd2d08
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/Model/Resolver/Product/Links.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Product;

use Magento\Catalog\Model\Product;
use Magento\DownloadableGraphQl\Model\ConvertLinksToArray;
use Magento\DownloadableGraphQl\Model\GetDownloadableProductLinks;
use Magento\DownloadableGraphQl\Resolver\Product\Links as SourceLinks;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Pricing\Helper\Data as PriceHelper;

class Links extends SourceLinks
{
/**
* @var PriceHelper
*/
protected $pricingHelper;

/**
* @param GetDownloadableProductLinks $getDownloadableProductLinks
* @param ConvertLinksToArray $convertLinksToArray
* @param PriceHelper $pricingHelper
*/
public function __construct(
GetDownloadableProductLinks $getDownloadableProductLinks,
ConvertLinksToArray $convertLinksToArray,
PriceHelper $pricingHelper
) {
parent::__construct($getDownloadableProductLinks, $convertLinksToArray);
$this->pricingHelper = $pricingHelper;
}

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

/** @var Product $product */
$product = $value['model'];
$data = parent::resolve($field, $context, $info, $value, $args);

foreach ($data as &$link) {
$link['price'] = $this->pricingHelper->currencyByStore(
$link['price'], $product->getStore(), false
);
}

return $data;
}
}
3 changes: 3 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<preference for="Magento\Framework\Search\Dynamic\Algorithm\Improved"
type="ScandiPWA\CatalogGraphQl\Search\Dynamic\Algorithm\Improved"/>

<preference for="Magento\DownloadableGraphQl\Resolver\Product\Links"
type="ScandiPWA\CatalogGraphQl\Model\Resolver\Product\Links" />

<type name="Magento\Elasticsearch\SearchAdapter\Aggregation\Builder">
<plugin name="aggregation_equalize_products_count_handler"
type="ScandiPWA\CatalogGraphQl\Plugin\SearchAdapter\Aggregation\BuilderPlugin" />
Expand Down

0 comments on commit 7fd2d08

Please sign in to comment.