-
-
Save BJIAST/f98c128f871c61676fd39980890e23ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function subscribe($product_id, $user) { | |
| $query = $this->db->query("SELECT subscribes FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'"); | |
| if ($query->num_rows && $query->row['subscribes'] != '' ) { | |
| $subscribes = json_decode($query->row['subscribes']); | |
| $user = json_decode($user); | |
| $key = array_search($user->email, array_column($subscribes, 'email')); | |
| if(false == $key) { | |
| return false; | |
| } | |
| array_push($subscribes, $user); | |
| $subscribes = json_encode($subscribes); | |
| } else { | |
| $user = json_decode($user); | |
| $subscribes = json_encode(array($user)); | |
| } | |
| $this->db->query("UPDATE " . DB_PREFIX . "product SET subscribes = '$subscribes' WHERE product_id = '" . (int)$product_id . "'"); | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment