File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919trait Priceable
2020{
21- private $ hardPrice = null ;
21+ private function cacheKey ()
22+ {
23+ $ id = inlineId ($ this );
24+ return 'forced-price- ' . $ id ;
25+ }
2226
2327 public function setPrice ($ price )
2428 {
25- $ this ->hardPrice = $ price ;
29+ $ key = $ this ->cacheKey ();
30+ app ()->make ('TempCache ' )->put ($ key , $ price );
2631 }
2732
2833 public function getPrice ($ rectify = false )
2934 {
30- if (is_null ($ this ->hardPrice )) {
35+ $ key = $ this ->cacheKey ();
36+ $ hard = app ()->make ('TempCache ' )->get ($ key );
37+
38+ if (is_null ($ hard )) {
3139 return $ this ->realPrice ($ rectify );
3240 }
3341 else {
34- return $ this -> hardPrice ;
42+ return $ hard ;
3543 }
3644 }
3745
3846 public function copyPrice ($ obj )
3947 {
40- $ this ->hardPrice = $ obj ->hardPrice ;
48+ $ cache = app ()->make ('TempCache ' );;
49+
50+ $ original_key = $ obj ->cacheKey ();
51+ $ price = $ cache ->get ($ original_key );
52+
53+ $ this_key = $ this ->cacheKey ();
54+ $ cache ->put ($ this_key , $ price );
4155 }
4256
4357 abstract public function realPrice ($ rectify );
You can’t perform that action at this time.
0 commit comments