wishlist.php (6017B)
1 <?php 2 class ControllerAccountWishList extends Controller { 3 public function index() { 4 if (!$this->customer->isLogged()) { 5 $this->session->data['redirect'] = $this->url->link('account/wishlist', '', true); 6 7 $this->response->redirect($this->url->link('account/login', '', true)); 8 } 9 10 $this->load->language('account/wishlist'); 11 12 $this->load->model('account/wishlist'); 13 14 $this->load->model('catalog/product'); 15 16 $this->load->model('tool/image'); 17 18 if (isset($this->request->get['remove'])) { 19 // Remove Wishlist 20 $this->model_account_wishlist->deleteWishlist($this->request->get['remove']); 21 22 $this->session->data['success'] = $this->language->get('text_remove'); 23 24 $this->response->redirect($this->url->link('account/wishlist')); 25 } 26 27 $this->document->setTitle($this->language->get('heading_title')); 28 29 $data['breadcrumbs'] = array(); 30 31 $data['breadcrumbs'][] = array( 32 'text' => $this->language->get('text_home'), 33 'href' => $this->url->link('common/home') 34 ); 35 36 $data['breadcrumbs'][] = array( 37 'text' => $this->language->get('text_account'), 38 'href' => $this->url->link('account/account', '', true) 39 ); 40 41 $data['breadcrumbs'][] = array( 42 'text' => $this->language->get('heading_title'), 43 'href' => $this->url->link('account/wishlist') 44 ); 45 46 if (isset($this->session->data['success'])) { 47 $data['success'] = $this->session->data['success']; 48 49 unset($this->session->data['success']); 50 } else { 51 $data['success'] = ''; 52 } 53 54 $data['products'] = array(); 55 56 $results = $this->model_account_wishlist->getWishlist(); 57 58 foreach ($results as $result) { 59 $product_info = $this->model_catalog_product->getProduct($result['product_id']); 60 61 if ($product_info) { 62 if ($product_info['image']) { 63 $image = $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_wishlist_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_wishlist_height')); 64 } else { 65 $image = false; 66 } 67 68 if ($product_info['quantity'] <= 0) { 69 $stock = $product_info['stock_status']; 70 } elseif ($this->config->get('config_stock_display')) { 71 $stock = $product_info['quantity']; 72 } else { 73 $stock = $this->language->get('text_instock'); 74 } 75 76 if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { 77 $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 78 } else { 79 $price = false; 80 } 81 82 if ((float)$product_info['special']) { 83 $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); 84 } else { 85 $special = false; 86 } 87 88 $data['products'][] = array( 89 'product_id' => $product_info['product_id'], 90 'thumb' => $image, 91 'name' => $product_info['name'], 92 'model' => $product_info['model'], 93 'stock' => $stock, 94 'price' => $price, 95 'special' => $special, 96 'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']), 97 'remove' => $this->url->link('account/wishlist', 'remove=' . $product_info['product_id']) 98 ); 99 } else { 100 $this->model_account_wishlist->deleteWishlist($result['product_id']); 101 } 102 } 103 104 $data['continue'] = $this->url->link('account/account', '', true); 105 106 $data['column_left'] = $this->load->controller('common/column_left'); 107 $data['column_right'] = $this->load->controller('common/column_right'); 108 $data['content_top'] = $this->load->controller('common/content_top'); 109 $data['content_bottom'] = $this->load->controller('common/content_bottom'); 110 $data['footer'] = $this->load->controller('common/footer'); 111 $data['header'] = $this->load->controller('common/header'); 112 113 $this->response->setOutput($this->load->view('account/wishlist', $data)); 114 } 115 116 public function add() { 117 $this->load->language('account/wishlist'); 118 119 $json = array(); 120 121 if (isset($this->request->post['product_id'])) { 122 $product_id = $this->request->post['product_id']; 123 } else { 124 $product_id = 0; 125 } 126 127 $this->load->model('catalog/product'); 128 129 $product_info = $this->model_catalog_product->getProduct($product_id); 130 131 if ($product_info) { 132 if ($this->customer->isLogged()) { 133 // Edit customers cart 134 $this->load->model('account/wishlist'); 135 136 $this->model_account_wishlist->addWishlist($this->request->post['product_id']); 137 138 $json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist')); 139 140 $json['total'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist()); 141 } else { 142 if (!isset($this->session->data['wishlist'])) { 143 $this->session->data['wishlist'] = array(); 144 } 145 146 $this->session->data['wishlist'][] = $this->request->post['product_id']; 147 148 $this->session->data['wishlist'] = array_unique($this->session->data['wishlist']); 149 150 $json['success'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', true), $this->url->link('account/register', '', true), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist')); 151 152 $json['total'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0)); 153 } 154 } 155 156 $this->response->addHeader('Content-Type: application/json'); 157 $this->response->setOutput(json_encode($json)); 158 } 159 }