Skip to content

Commit 9d7732d

Browse files
committed
revisione gestione prezzi differenziati per prodotti
1 parent 05e7618 commit 9d7732d

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

code/app/Models/Concerns/Priceable.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,40 @@
1818

1919
trait 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);

0 commit comments

Comments
 (0)