Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit 7bafdcc

Browse files
committed
First version
0 parents  commit 7bafdcc

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Codepeak\Productfix\Observer\Catalog;
4+
5+
use Magento\Framework\App\ObjectManager;
6+
use Magento\Framework\Event\Observer;
7+
use Magento\Framework\Event\ObserverInterface;
8+
9+
/**
10+
* Class Productsaveafter
11+
*
12+
* @package Codepeak\Productfix\Observer\Catalog
13+
* @author Robert Lord <robert@codepeak.se>
14+
*/
15+
class Productsaveafter implements ObserverInterface
16+
{
17+
/**
18+
* Execute observer
19+
*
20+
* @param \Magento\Framework\Event\Observer $observer
21+
*
22+
* @return void
23+
*/
24+
public function execute(Observer $observer)
25+
{
26+
if ($observer->getProduct() && $observer->getProduct()->getId()) {
27+
$productId = $observer->getProduct()->getId();
28+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
29+
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
30+
$connection = $resource->getConnection();
31+
$tableName = $resource->getTableName('catalog_product_entity'); //gives table name with prefix
32+
$connection->query(
33+
"UPDATE `" . $tableName . "` SET `updated_at` = NOW() WHERE `entity_id` = '" . $productId . "' LIMIT 1"
34+
);
35+
}
36+
}
37+
}

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# magento2-productfix
2+
3+
There is an issue in (at the time of writing) Magento 2.1.4 and previous versions that doesn't update the field `updated_at` in the table `catalog_product_entity` when a product is updated. This simple module uses raw SQL to force update the field.
4+
5+
**Use this module at own risk and make sure to test it first!**
6+
7+
## How to install
8+
9+
After installing Magento 2, run the following commands from your Magento 2 root directory:
10+
11+
```
12+
composer require codepeak/magento2-productfix
13+
php bin/magento cache:flush
14+
```
15+
16+
## Contribute
17+
18+
Feel free to **fork** and contribute to this module. Simply create a pull request and we'll review and merge your changes to master branch.
19+
20+
## About Codepeak
21+
22+
Codepeak is a Magento consultant agency located in Sweden. For more information, please visit [codepeak.se](https://codepeak.se).

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "codepeak/magento2-productfix",
3+
"description": "Solves the error with updated_at field not updating",
4+
"license": "proprietary",
5+
"authors": [
6+
{
7+
"name": "Robert Lord, Codepeak AB",
8+
"email": "robert@codepeak.se"
9+
}
10+
],
11+
"minimum-stability": "dev",
12+
"require": {},
13+
"autoload": {
14+
"psr-4": {
15+
"Codepeak\\Productfix\\": ""
16+
},
17+
"files": [
18+
"registration.php"
19+
]
20+
}
21+
}

etc/events.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
3+
<event name="catalog_product_save_after">
4+
<observer name="codepeakProductfixEventObserver" instance="Codepeak\Productfix\Observer\Catalog\Productsaveafter"/>
5+
</event>
6+
</config>

etc/module.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="Codepeak_Productfix" setup_version="1.0.0"/>
4+
</config>

registration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
\Magento\Framework\Component\ComponentRegistrar::register(
4+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
5+
'Codepeak_Productfix',
6+
__DIR__
7+
);

0 commit comments

Comments
 (0)