|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\FactFinderSdk\Business\Expander; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\CurrencyTransfer; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\LocaleTransfer; |
|
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\StoreTransfer; |
|
|
|
|
|
|
13
|
|
|
use SprykerEco\Shared\FactFinderSdk\FactFinderSdkConstants; |
|
14
|
|
|
|
|
15
|
|
|
class FactFinderSdkReviewExpander extends FactFinderSdkAbstractExpander |
|
16
|
|
|
{ |
|
17
|
|
|
public const ID_PRODUCT_ABSTRACT = 'IdProductAbstract'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer |
|
21
|
|
|
* @param \Generated\Shared\Transfer\CurrencyTransfer $currencyTransfer |
|
22
|
|
|
* @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer |
|
23
|
|
|
* @param array $productData |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function expand(LocaleTransfer $localeTransfer, CurrencyTransfer $currencyTransfer, StoreTransfer $storeTransfer, $productData) |
|
28
|
|
|
{ |
|
29
|
|
|
$query = $this->queryContainer |
|
30
|
|
|
->getReviewsQuery($productData[static::ID_PRODUCT_ABSTRACT], $localeTransfer); |
|
31
|
|
|
$abstractProduct = $query->find(); |
|
32
|
|
|
|
|
33
|
|
|
if ($abstractProduct->count() === 0) { |
|
34
|
|
|
$productData[FactFinderSdkConstants::ITEM_RATING] = 0; |
|
35
|
|
|
|
|
36
|
|
|
return $productData; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$productData = $this->setRating($abstractProduct, $productData); |
|
40
|
|
|
|
|
41
|
|
|
return $productData; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \Propel\Runtime\Collection\ObjectCollection $abstractProduct |
|
46
|
|
|
* @param array $productData |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function setRating($abstractProduct, $productData) |
|
51
|
|
|
{ |
|
52
|
|
|
$reviews = $abstractProduct->getFirst()->getSpyProductReviews(); |
|
53
|
|
|
|
|
54
|
|
|
if ($reviews->count() === 0) { |
|
55
|
|
|
return $productData; |
|
56
|
|
|
} |
|
57
|
|
|
$productRating = 0; |
|
58
|
|
|
|
|
59
|
|
|
foreach ($reviews as $review) { |
|
60
|
|
|
$productRating += $review->getRating(); |
|
61
|
|
|
} |
|
62
|
|
|
$productRating = $productRating / $reviews->count(); |
|
63
|
|
|
$productRating = number_format($productRating, 1, '.', ''); |
|
64
|
|
|
|
|
65
|
|
|
$productData[FactFinderSdkConstants::ITEM_RATING] = $productRating; |
|
66
|
|
|
|
|
67
|
|
|
return $productData; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths