@@ -127,6 +127,13 @@ abstract class AbstractModel extends \Magento\Framework\Object
127
127
*/
128
128
protected $ _actionValidator ;
129
129
130
+ /**
131
+ * Array to store object's original data
132
+ *
133
+ * @var array
134
+ */
135
+ private $ storedData = [];
136
+
130
137
/**
131
138
* @param \Magento\Framework\Model\Context $context
132
139
* @param \Magento\Framework\Registry $registry
@@ -155,7 +162,7 @@ public function __construct(
155
162
) {
156
163
$ this ->_idFieldName = $ this ->_getResource ()->getIdFieldName ();
157
164
}
158
-
165
+ $ this -> updateStoredData ();
159
166
parent ::__construct ($ data );
160
167
$ this ->_construct ();
161
168
}
@@ -354,6 +361,7 @@ public function afterLoad()
354
361
{
355
362
$ this ->getResource ()->afterLoad ($ this );
356
363
$ this ->_afterLoad ();
364
+ $ this ->updateStoredData ();
357
365
return $ this ;
358
366
}
359
367
@@ -566,6 +574,7 @@ public function afterSave()
566
574
$ this ->_eventManager ->dispatch ('model_save_after ' , ['object ' => $ this ]);
567
575
$ this ->_eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ]);
568
576
$ this ->_eventManager ->dispatch ($ this ->_eventPrefix . '_save_after ' , $ this ->_getEventData ());
577
+ $ this ->updateStoredData ();
569
578
return $ this ;
570
579
}
571
580
@@ -611,6 +620,7 @@ public function afterDelete()
611
620
$ this ->_eventManager ->dispatch ('model_delete_after ' , ['object ' => $ this ]);
612
621
$ this ->_eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ]);
613
622
$ this ->_eventManager ->dispatch ($ this ->_eventPrefix . '_delete_after ' , $ this ->_getEventData ());
623
+ $ this ->updateStoredData ();
614
624
return $ this ;
615
625
}
616
626
@@ -689,4 +699,19 @@ protected function _clearData()
689
699
{
690
700
return $ this ;
691
701
}
702
+
703
+ /**
704
+ * Synchronize object's stored data with the actual data
705
+ *
706
+ * @return $this
707
+ */
708
+ protected function updateStoredData ()
709
+ {
710
+ if (isset ($ this ->_data )) {
711
+ $ this ->storedData = $ this ->_data ;
712
+ } else {
713
+ $ this ->storedData = [];
714
+ }
715
+ return $ this ;
716
+ }
692
717
}
0 commit comments