2
2
3
3
namespace Reviewscouk \Reviews \Block \Product ;
4
4
5
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
6
+ use Magento \Catalog \Block \Product \Context ;
5
7
use Magento \Catalog \Block \Product \ListProduct ;
6
- use Framework \Registry as Registry ;
7
- use Magento \Framework \Escaper as Escaper ;
8
- // use Reviewscouk\Reviews\Helper\Config as ReviewsConfig;
9
- use Magento \Framework as Framework ;
8
+ use Magento \Catalog \Model \CategoryFactory ;
9
+ use Magento \Catalog \Model \Layer \Resolver ;
10
+ use Magento \Customer \Model \Session ;
11
+ use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \Data \Helper \PostHelper ;
13
+ use Magento \Framework \Escaper ;
14
+ use Magento \Framework \Url \Helper \Data ;
10
15
use Magento \Store \Model \StoreManagerInterface ;
11
- use Magento \Framework \App \Helper \Context as ContextHelper ;
12
- use \Reviewscouk \Reviews \Helper \Config as ReviewsConfig ;
13
-
16
+ use Reviewscouk \Reviews \Helper \Config as ReviewsConfig ;
14
17
15
18
class RatingSnippet extends ListProduct
16
19
{
17
20
protected $ _customerSession ;
18
21
protected $ categoryFactory ;
19
- //protected $reviewsConfig = Reviews\Helper\Config;
20
- // protected $_storeManager = StoreManagerInterface::class;
21
22
protected $ store ;
22
23
protected $ reviewsConfig ;
23
- /**
24
- * ListProduct constructor.
25
- * @param \Magento\Catalog\Block\Product\Context $context
26
- * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
27
- * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
28
- * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
29
- * @param \Magento\Framework\Url\Helper\Data $urlHelper
30
- * @param Helper $helper
31
- * @param array $data
32
- * @param \Magento\Customer\Model\Session $customerSession
33
- * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
34
- */
24
+
35
25
public function __construct (
36
- \ Magento \ Catalog \ Block \ Product \ Context $ context ,
37
- \ Magento \ Framework \ Data \ Helper \ PostHelper $ postDataHelper ,
38
- \ Magento \ Catalog \ Model \ Layer \ Resolver $ layerResolver ,
39
- \ Magento \ Catalog \ Api \ CategoryRepositoryInterface $ categoryRepository ,
40
- \ Magento \ Framework \ Url \ Helper \ Data $ urlHelper ,
26
+ Context $ context ,
27
+ PostHelper $ postDataHelper ,
28
+ Resolver $ layerResolver ,
29
+ CategoryRepositoryInterface $ categoryRepository ,
30
+ Data $ urlHelper ,
41
31
array $ data = [],
42
- \ Magento \ Customer \ Model \ Session $ customerSession = null ,
43
- \ Magento \ Catalog \ Model \ CategoryFactory $ categoryFactory = null ,
32
+ Session $ customerSession = null ,
33
+ CategoryFactory $ categoryFactory = null ,
44
34
ReviewsConfig $ reviewsConfigHelper = null ,
45
35
StoreManagerInterface $ storeManager = null
46
36
) {
47
37
$ this ->_customerSession = $ customerSession ;
48
38
$ this ->categoryFactory = $ categoryFactory ;
49
- $ this ->reviewsConfig = $ reviewsConfigHelper ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (ReviewsConfig::class);
39
+ $ this ->reviewsConfig = $ reviewsConfigHelper ?: ObjectManager::getInstance ()->get (ReviewsConfig::class);
50
40
$ this ->store = $ storeManager ;
51
41
52
42
parent ::__construct (
@@ -63,22 +53,24 @@ public function __construct(
63
53
private function getProductSkus ($ product )
64
54
{
65
55
$ sku = $ product ->getSku ();
66
- $ type = $ product ->getTypeID ();
56
+ $ type = ( string ) $ product ->getTypeID ();
67
57
68
58
$ productSkus = [$ sku ];
69
- if ($ type == 'configurable ' ) {
59
+
60
+ if ($ type === 'configurable ' ) {
70
61
$ usedProducts = $ product ->getTypeInstance ()->getUsedProducts ($ product );
71
62
foreach ($ usedProducts as $ usedProduct ) {
72
63
$ productSkus [] = $ usedProduct ->getSku ();
73
64
}
74
65
}
75
66
76
- if ($ type == 'grouped ' ) {
67
+ if ($ type === 'grouped ' ) {
77
68
$ usedProducts = $ product ->getTypeInstance ()->getAssociatedProducts ($ product );
78
69
foreach ($ usedProducts as $ usedProduct ) {
79
70
$ productSkus [] = $ usedProduct ->getSku ();
80
71
}
81
72
}
73
+
82
74
return $ productSkus ;
83
75
}
84
76
@@ -88,9 +80,11 @@ public function getRatingSnippet($product)
88
80
$ ratingSnippetEnabled = $ this ->reviewsConfig ->isCategoryRatingSnippetWidgetEnabled ($ this ->store );
89
81
$ skus = $ this ->getProductSkus ($ product );
90
82
$ html = '' ;
91
- if ($ ratingSnippetEnabled ) {
83
+
84
+ if ($ ratingSnippetEnabled ) {
92
85
$ html = '<div class="ruk_rating_snippet" data-sku=" ' . $ escaper ->escapeHtml ((!empty ($ skus ) ? implode ('; ' , $ skus ) : '' )) . '"></div> ' ;
93
86
}
87
+
94
88
return $ html ;
95
89
}
96
90
0 commit comments