Skip to content

Commit

Permalink
apply some fixes related with failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Usik2203 committed Jul 17, 2020
1 parent 0d904ab commit 3cfc907
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\CatalogGraphQl\Model\Resolver\Products\SearchResultFactory;
use Magento\Framework\Api\Search\SearchCriteriaInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Phrase;
use Magento\Search\Api\SearchInterface;
use Magento\Search\Model\Search\PageSizeProvider;

Expand Down Expand Up @@ -112,7 +113,11 @@ public function getResult(
$productArray[$product->getId()] = $product->getData();
$productArray[$product->getId()]['model'] = $product;
foreach ($queryFields as $field) {
$productArray[$product->getId()][$field] = $this->getAttributeLabel($product, $field);
$productArray[$product->getId()][$field] = $this->getAttributeValue(
$product,
$productArray,
$field
);
}
}

Expand Down Expand Up @@ -144,19 +149,25 @@ private function buildSearchCriteria(array $args, ResolveInfo $info): SearchCrit
return $searchCriteria;
}


/**
* Get frontend label of product attribute
* Get product attribute value
*
* @param Product $product
* @param $productArray
* @param $field
*
* @return mixed
* @return string|null
*/
private function getAttributeLabel(Product $product, $field)
private function getAttributeValue(Product $product, $productArray, $field)
{
$attribute = $product->getResource()->getAttribute($field);
if ($attribute) {
return $attribute->getFrontend()->getValue($product);
if ($attribute = $product->getResource()->getAttribute($field)) {
$attributeValue = $attribute->getFrontend()->getValue($product);
if ($attributeValue && !($attributeValue instanceof Phrase) ) {
return $attributeValue;
} else {
return isset($productArray[$product->getId()][$field])? $productArray[$product->getId()][$field] : null;
}
}
}
}

0 comments on commit 3cfc907

Please sign in to comment.