docs/api/source-extension.opencart.catalog.controller.total.reward.html
| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Total; | | 3: | /** | | 4: | * Class Reward | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Total | | 7: | */ | | 8: | class Reward extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return string | | 13: | */ | | 14: | public function index(): string { | | 15: | if ($this->config->get('total_reward_status')) { | | 16: | $available = $this->customer->getRewardPoints(); | | 17: | | | 18: | $points_total = 0; | | 19: | | | 20: | foreach ($this->cart->getProducts() as $product) { | | 21: | if ($product['points']) { | | 22: | $points_total += $product['points']; | | 23: | } | | 24: | } | | 25: | | | 26: | if ($available && $points_total) { | | 27: | $this->load->language('extension/opencart/total/reward'); | | 28: | | | 29: | $data['heading_title'] = sprintf($this->language->get('heading_title'), $available); | | 30: | | | 31: | $data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total); | | 32: | | | 33: | $data['save'] = $this->url->link('extension/opencart/total/reward.save', 'language=' . $this->config->get('config_language'), true); | | 34: | $data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true); | | 35: | | | 36: | if (isset($this->session->data['reward'])) { | | 37: | $data['reward'] = $this->session->data['reward']; | | 38: | } else { | | 39: | $data['reward'] = ''; | | 40: | } | | 41: | | | 42: | return $this->load->view('extension/opencart/total/reward', $data); | | 43: | } | | 44: | } | | 45: | | | 46: | return ''; | | 47: | } | | 48: | | | 49: | /** | | 50: | * Save | | 51: | * | | 52: | * @return void | | 53: | */ | | 54: | public function save(): void { | | 55: | $this->load->language('extension/opencart/total/reward'); | | 56: | | | 57: | $json = []; | | 58: | | | 59: | if (isset($this->request->post['reward'])) { | | 60: | $reward = abs((int)$this->request->post['reward']); | | 61: | } else { | | 62: | $reward = 0; | | 63: | } | | 64: | | | 65: | $available = $this->customer->getRewardPoints(); | | 66: | | | 67: | $points_total = 0; | | 68: | | | 69: | foreach ($this->cart->getProducts() as $product) { | | 70: | if ($product['points']) { | | 71: | $points_total += $product['points']; | | 72: | } | | 73: | } | | 74: | | | 75: | if (!$this->config->get('total_reward_status')) { | | 76: | $json['error'] = $this->language->get('error_reward'); | | 77: | } | | 78: | | | 79: | if ($reward > $available) { | | 80: | $json['error'] = sprintf($this->language->get('error_points'), $reward); | | 81: | } | | 82: | | | 83: | if ($reward > $points_total) { | | 84: | $json['error'] = sprintf($this->language->get('error_maximum'), $points_total); | | 85: | } | | 86: | | | 87: | if (!$json) { | | 88: | if ($reward) { | | 89: | $json['success'] = $this->language->get('text_success'); | | 90: | | | 91: | $this->session->data['reward'] = $reward; | | 92: | } else { | | 93: | $json['success'] = $this->language->get('text_remove'); | | 94: | | | 95: | unset($this->session->data['reward']); | | 96: | } | | 97: | | | 98: | unset($this->session->data['shipping_method']); | | 99: | unset($this->session->data['shipping_methods']); | | 100: | unset($this->session->data['payment_method']); | | 101: | unset($this->session->data['payment_methods']); | | 102: | } | | 103: | | | 104: | $this->response->addHeader('Content-Type: application/json'); | | 105: | $this->response->setOutput(json_encode($json)); | | 106: | } | | 107: | } | | 108: | |
OpenCart API API documentation generated by ApiGen dev-master