Skip to content

Commit

Permalink
Merge pull request #1 from alex-vo/bug/924/disabled-product-404
Browse files Browse the repository at this point in the history
returning null in urlResolver for type PRODUCT if product is disabled
  • Loading branch information
alfredsgenkins authored Oct 16, 2020
2 parents 9d0bfbc + cc9ab35 commit 3cb9f1a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Model/Resolver/EntityUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace ScandiPWA\UrlrewriteGraphQl\Model\Resolver;

use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
Expand Down Expand Up @@ -101,8 +102,13 @@ public function resolve(

if ($type === 'PRODUCT') {
// Using this instead of factory due https://github.com/magento/magento2/issues/12278
$collection = $this->productCollectionFactory->create();
$collection = $this->productCollectionFactory->create()
->addAttributeToFilter('status', ['eq' => Status::STATUS_ENABLED]);
$product = $collection->addIdFilter($id)->getFirstItem();
if (!$product->hasData()) {
return null;
}

$result['sku'] = $product->getSku();
}
}
Expand Down

0 comments on commit 3cb9f1a

Please sign in to comment.