@@ -44,34 +44,45 @@ class SimpleProductsAggregatedReportDataProcessor
44
44
*/
45
45
private $ collection ;
46
46
47
+ protected $ _productCollectionFactory ;
48
+
47
49
public function __construct (
48
50
\MagentoHackathon \BestsellersSorting \Model \ResourceModel \Bestseller $ bestseller ,
49
51
\Magento \Catalog \Model \ResourceModel \Product \Action $ action ,
50
- \MagentoHackathon \BestsellersSorting \Model \ResourceModel \Bestseller \Collection $ collection
51
-
52
+ \MagentoHackathon \BestsellersSorting \Model \ResourceModel \Bestseller \Collection $ collection,
53
+ \ Magento \ Catalog \ Model \ ResourceModel \ Product \ CollectionFactory $ productCollectionFactory
52
54
)
53
55
{
54
56
55
57
$ this ->bestseller = $ bestseller ;
56
58
$ this ->action = $ action ;
57
59
$ this ->collection = $ collection ;
60
+ $ this ->_productCollectionFactory = $ productCollectionFactory ;
58
61
}
59
62
60
63
public function calculate ($ storeId = 0 )
61
64
{
62
65
$ this ->bestseller ->aggregate (null , null );
63
-
66
+
67
+ $ productIds = $ this ->_productCollectionFactory ->create ()->getAllIds ();
68
+
64
69
$ collection = $ this ->collection ;
65
70
/** @var \MagentoHackathon\BestsellersSorting\Model\Bestseller $productId */
66
71
foreach ($ collection as $ item ) {
67
72
73
+ /**
74
+ * https://github.com/magento-hackathon/bestsellers-sorting-m2/issues/1
75
+ * Integrity constraint violation issue on running reindex #1
76
+ */
77
+ if (!in_array ($ item ->getProductId (),$ productIds )) {
78
+ continue ;
79
+ }
80
+
68
81
/**https://magento.stackexchange.com/questions/151186/best-way-to-update-products-attribute-value */
69
82
$ this ->action ->updateAttributes (
70
83
[$ item ->getProductId ()],
71
84
['bestseller_order ' => $ item ->getRatingPos ()],
72
85
$ item ->getStoreId ());
73
86
}
74
-
75
-
76
87
}
77
88
}
0 commit comments