Skip to content

Commit

Permalink
See scandipwa/scandipwa#4896 Fixed the issue when downloadable produc…
Browse files Browse the repository at this point in the history
…t with changed sku crashed the order page
  • Loading branch information
zans-laksa committed Aug 5, 2022
1 parent 5004e6a commit d11cf7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
23 changes: 23 additions & 0 deletions Model/LinkRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
*/
declare(strict_types=1);

namespace ScandiPWA\SalesGraphQl\Model;

use Magento\Downloadable\Model\LinkRepository as SourceLinkRepository;

class LinkRepository extends SourceLinkRepository {
public function getListById(int $id): array
{
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->productRepository->getById($id);
return $this->getLinksByProduct($product);
}
}
15 changes: 8 additions & 7 deletions Model/OrderItem/OptionsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Magento\SalesGraphQl\Model\OrderItem\OptionsProcessor as SourceOptionsProcessor;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Downloadable\Api\LinkRepositoryInterface;
use ScandiPWA\SalesGraphQl\Model\LinkRepository;

/**
* Process order item options to format for GraphQl output
Expand Down Expand Up @@ -46,7 +46,7 @@ class OptionsProcessor extends SourceOptionsProcessor
protected $linkRepository;

public function __construct(
LinkRepositoryInterface $linkRepository
LinkRepository $linkRepository
) {
$this->linkRepository = $linkRepository;
}
Expand Down Expand Up @@ -152,12 +152,13 @@ protected function processBundleOptions(array $bundleOptions)
* @param $product
* @param array $links
*/
protected function processDownloadableLinksOptions($product, array $links) {
// Get the product downloadable links
$productLinks = $this->linkRepository->getList($product->getSku());
$linksOutput = [ 'label' => 'Links', 'linkItems' => []];
protected function processDownloadableLinksOptions($product, array $links)
{
$productLinks = $this->linkRepository->getListById((int)$product->getProductId());

$linksOutput = ['label' => 'Links', 'linkItems' => []];

foreach($productLinks as $link) {
foreach ($productLinks as $link) {
if (in_array($link->getId(), $links)) {
$linksOutput['linkItems'][] = $link->getTitle();
}
Expand Down

0 comments on commit d11cf7f

Please sign in to comment.