| 1 |
<?php |
| 2 |
|
| 3 |
class GiftUp_Cache |
| 4 |
{ |
| 5 |
// Cache API gift card get API result per web request |
| 6 |
public $giftcard = null; |
| 7 |
|
| 8 |
// Cache some cart totals |
| 9 |
public $applied_gift_card_balance = 0; |
| 10 |
|
| 11 |
public function gift_card_found() { |
| 12 |
return $this->giftcard != null |
| 13 |
&& strlen($this->get_accepted_gift_card_code()) > 0; |
| 14 |
} |
| 15 |
|
| 16 |
public function get_requested_gift_card_code() { |
| 17 |
if (WC()->session) { |
| 18 |
return WC()->session->get( GIFTUP_REQUESTED_GIFTCARD_CODE ); |
| 19 |
} |
| 20 |
return null; |
| 21 |
} |
| 22 |
|
| 23 |
public function get_accepted_gift_card_code() { |
| 24 |
if (WC()->session) { |
| 25 |
return WC()->session->get( GIFTUP_ACCEPTED_GIFTCARD_CODE ); |
| 26 |
} |
| 27 |
return null; |
| 28 |
} |
| 29 |
|
| 30 |
public function set_gift_card_code( $code ) { |
| 31 |
if (WC()->session) { |
| 32 |
WC()->session->set( GIFTUP_REQUESTED_GIFTCARD_CODE, $code ); |
| 33 |
|
| 34 |
if (empty($code) || $code == null) { |
| 35 |
WC()->session->set( GIFTUP_ACCEPTED_GIFTCARD_CODE, null ); |
| 36 |
} |
| 37 |
else if (GiftUp()->api->get_gift_card($code) != null) { |
| 38 |
WC()->session->set( GIFTUP_ACCEPTED_GIFTCARD_CODE, $this->giftcard['code'] ); |
| 39 |
} |
| 40 |
else { |
| 41 |
WC()->session->set( GIFTUP_ACCEPTED_GIFTCARD_CODE, null ); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|