Skip to content

Commit aca86c0

Browse files
Merge MAGETWO-97081 into 2.2.8-bugfixes-300119
2 parents 949a961 + c5d7f4c commit aca86c0

File tree

2 files changed

+35
-29
lines changed
  • app/code/Magento/Catalog/Model/Product/ProductFrontendAction
  • lib/internal/Magento/Framework/DB/Adapter/Pdo

2 files changed

+35
-29
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ private function getProductIdsByActions(array $actions)
138138
$productIds = [];
139139

140140
foreach ($actions as $action) {
141-
$productIds[] = $action['product_id'];
141+
if (isset($action['product_id']) && is_int($action['product_id'])) {
142+
$productIds[] = $action['product_id'];
143+
}
142144
}
143145

144146
return $productIds;
@@ -159,33 +161,37 @@ public function syncActions(array $productsData, $typeId)
159161
$customerId = $this->session->getCustomerId();
160162
$visitorId = $this->visitor->getId();
161163
$collection = $this->getActionsByType($typeId);
162-
$collection->addFieldToFilter('product_id', $this->getProductIdsByActions($productsData));
163-
164-
/**
165-
* Note that collection is also filtered by visitor id and customer id
166-
* This collection shouldnt be flushed when visitor has products and then login
167-
* It can remove only products for visitor, or only products for customer
168-
*
169-
* ['product_id' => 'added_at']
170-
* @var ProductFrontendActionInterface $item
171-
*/
172-
foreach ($collection as $item) {
173-
$this->entityManager->delete($item);
174-
}
175-
176-
foreach ($productsData as $productId => $productData) {
177-
/** @var ProductFrontendActionInterface $action */
178-
$action = $this->productFrontendActionFactory->create([
179-
'data' => [
180-
'visitor_id' => $customerId ? null : $visitorId,
181-
'customer_id' => $this->session->getCustomerId(),
182-
'added_at' => $productData['added_at'],
183-
'product_id' => $productId,
184-
'type_id' => $typeId
185-
]
186-
]);
187-
188-
$this->entityManager->save($action);
164+
$productIds = $this->getProductIdsByActions($productsData);
165+
166+
if ($productIds) {
167+
$collection->addFieldToFilter('product_id', $productIds);
168+
169+
/**
170+
* Note that collection is also filtered by visitor id and customer id
171+
* This collection shouldnt be flushed when visitor has products and then login
172+
* It can remove only products for visitor, or only products for customer
173+
*
174+
* ['product_id' => 'added_at']
175+
* @var ProductFrontendActionInterface $item
176+
*/
177+
foreach ($collection as $item) {
178+
$this->entityManager->delete($item);
179+
}
180+
181+
foreach ($productsData as $productId => $productData) {
182+
/** @var ProductFrontendActionInterface $action */
183+
$action = $this->productFrontendActionFactory->create([
184+
'data' => [
185+
'visitor_id' => $customerId ? null : $visitorId,
186+
'customer_id' => $this->session->getCustomerId(),
187+
'added_at' => $productData['added_at'],
188+
'product_id' => $productId,
189+
'type_id' => $typeId
190+
]
191+
]);
192+
193+
$this->entityManager->save($action);
194+
}
189195
}
190196
}
191197

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,7 @@ public function prepareSqlCondition($fieldName, $condition)
29042904
if (isset($condition['to'])) {
29052905
$query .= empty($query) ? '' : ' AND ';
29062906
$to = $this->_prepareSqlDateCondition($condition, 'to');
2907-
$query = $this->_prepareQuotedSqlCondition($query . $conditionKeyMap['to'], $to, $fieldName);
2907+
$query = $query . $this->_prepareQuotedSqlCondition($conditionKeyMap['to'], $to, $fieldName);
29082908
}
29092909
} elseif (array_key_exists($key, $conditionKeyMap)) {
29102910
$value = $condition[$key];

0 commit comments

Comments
 (0)