|
| 1 | +diff -Naur a/vendor/magento/module-catalog/Model/Product/ProductFrontendAction/Synchronizer.php b/vendor/magento/module-catalog/Model/Product/ProductFrontendAction/Synchronizer.php |
| 2 | +--- a/vendor/magento/module-catalog/Model/Product/ProductFrontendAction/Synchronizer.php |
| 3 | ++++ b/vendor/magento/module-catalog/Model/Product/ProductFrontendAction/Synchronizer.php |
| 4 | +@@ -16,6 +16,8 @@ |
| 5 | + use Magento\Framework\EntityManager\EntityManager; |
| 6 | + |
| 7 | + /** |
| 8 | ++ * A Product Widget Synchronizer. |
| 9 | ++ * |
| 10 | + * Service which allows to sync product widget information, such as product id with db. In order to reuse this info |
| 11 | + * on different devices |
| 12 | + */ |
| 13 | +@@ -85,9 +87,10 @@ public function __construct( |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | +- * Find lifetime in configuration. Configuration is hold in Stores Configuration |
| 18 | +- * Also this configuration is generated by: |
| 19 | +- * @see \Magento\Catalog\Model\Widget\RecentlyViewedStorageConfiguration |
| 20 | ++ * Finds lifetime in configuration. |
| 21 | ++ * |
| 22 | ++ * Configuration is hold in Stores Configuration. Also this configuration is generated by |
| 23 | ++ * {@see Magento\Catalog\Model\Widget\RecentlyViewedStorageConfiguration} |
| 24 | + * |
| 25 | + * @param string $namespace |
| 26 | + * @return int |
| 27 | +@@ -108,6 +111,8 @@ private function getLifeTimeByNamespace($namespace) |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | ++ * Filters actions. |
| 32 | ++ * |
| 33 | + * In order to avoid suspicious actions, we need to filter them in DESC order, and slice only items that |
| 34 | + * can be persisted in database. |
| 35 | + * |
| 36 | +@@ -138,7 +143,9 @@ private function getProductIdsByActions(array $actions) |
| 37 | + $productIds = []; |
| 38 | + |
| 39 | + foreach ($actions as $action) { |
| 40 | +- $productIds[] = $action['product_id']; |
| 41 | ++ if (isset($action['product_id']) && is_int($action['product_id'])) { |
| 42 | ++ $productIds[] = $action['product_id']; |
| 43 | ++ } |
| 44 | + } |
| 45 | + |
| 46 | + return $productIds; |
| 47 | +@@ -159,33 +166,37 @@ public function syncActions(array $productsData, $typeId) |
| 48 | + $customerId = $this->session->getCustomerId(); |
| 49 | + $visitorId = $this->visitor->getId(); |
| 50 | + $collection = $this->getActionsByType($typeId); |
| 51 | +- $collection->addFieldToFilter('product_id', $this->getProductIdsByActions($productsData)); |
| 52 | +- |
| 53 | +- /** |
| 54 | +- * Note that collection is also filtered by visitor id and customer id |
| 55 | +- * This collection shouldn't be flushed when visitor has products and then login |
| 56 | +- * It can remove only products for visitor, or only products for customer |
| 57 | +- * |
| 58 | +- * ['product_id' => 'added_at'] |
| 59 | +- * @var ProductFrontendActionInterface $item |
| 60 | +- */ |
| 61 | +- foreach ($collection as $item) { |
| 62 | +- $this->entityManager->delete($item); |
| 63 | +- } |
| 64 | +- |
| 65 | +- foreach ($productsData as $productId => $productData) { |
| 66 | +- /** @var ProductFrontendActionInterface $action */ |
| 67 | +- $action = $this->productFrontendActionFactory->create([ |
| 68 | +- 'data' => [ |
| 69 | +- 'visitor_id' => $customerId ? null : $visitorId, |
| 70 | +- 'customer_id' => $this->session->getCustomerId(), |
| 71 | +- 'added_at' => $productData['added_at'], |
| 72 | +- 'product_id' => $productId, |
| 73 | +- 'type_id' => $typeId |
| 74 | +- ] |
| 75 | +- ]); |
| 76 | +- |
| 77 | +- $this->entityManager->save($action); |
| 78 | ++ $productIds = $this->getProductIdsByActions($productsData); |
| 79 | ++ |
| 80 | ++ if ($productIds) { |
| 81 | ++ $collection->addFieldToFilter('product_id', $productIds); |
| 82 | ++ |
| 83 | ++ /** |
| 84 | ++ * Note that collection is also filtered by visitor id and customer id |
| 85 | ++ * This collection shouldn't be flushed when visitor has products and then login |
| 86 | ++ * It can remove only products for visitor, or only products for customer |
| 87 | ++ * |
| 88 | ++ * ['product_id' => 'added_at'] |
| 89 | ++ * @var ProductFrontendActionInterface $item |
| 90 | ++ */ |
| 91 | ++ foreach ($collection as $item) { |
| 92 | ++ $this->entityManager->delete($item); |
| 93 | ++ } |
| 94 | ++ |
| 95 | ++ foreach ($productsData as $productId => $productData) { |
| 96 | ++ /** @var ProductFrontendActionInterface $action */ |
| 97 | ++ $action = $this->productFrontendActionFactory->create([ |
| 98 | ++ 'data' => [ |
| 99 | ++ 'visitor_id' => $customerId ? null : $visitorId, |
| 100 | ++ 'customer_id' => $this->session->getCustomerId(), |
| 101 | ++ 'added_at' => $productData['added_at'], |
| 102 | ++ 'product_id' => $productId, |
| 103 | ++ 'type_id' => $typeId |
| 104 | ++ ] |
| 105 | ++ ]); |
| 106 | ++ |
| 107 | ++ $this->entityManager->save($action); |
| 108 | ++ } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | +diff -Naur a/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php b/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php |
| 113 | +--- a/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php |
| 114 | ++++ b/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php |
| 115 | +@@ -2955,7 +2955,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface |
| 116 | + if (isset($condition['to'])) { |
| 117 | + $query .= empty($query) ? '' : ' AND '; |
| 118 | + $to = $this->_prepareSqlDateCondition($condition, 'to'); |
| 119 | +- $query = $this->_prepareQuotedSqlCondition($query . $conditionKeyMap['to'], $to, $fieldName); |
| 120 | ++ $query = $query . $this->_prepareQuotedSqlCondition($conditionKeyMap['to'], $to, $fieldName); |
| 121 | + } |
| 122 | + } elseif (array_key_exists($key, $conditionKeyMap)) { |
| 123 | + $value = $condition[$key]; |
0 commit comments