Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Orders With Downloadable Products With Broken SKU #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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