Ejemplo n.º 1
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->loadModel('catalog/product');
     $this->loadModel('catalog/review');
     $this->loadModel('tool/seo_url');
     $this->loadModel('tool/image');
     $promoton = new APromotion();
     $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
     $this->data['products'] = array();
     $results = $promoton->getProductSpecials('pd.name', 'ASC', 0, $this->config->get('config_special_limit'));
     $resource = new AResource('image');
     foreach ($results as $result) {
         $thumbnail = $resource->getMainThumb('products', $result['product_id'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'), true);
         if ($this->config->get('enable_reviews')) {
             $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
         } else {
             $rating = false;
         }
         $special = FALSE;
         $discount = $promoton->getProductDiscount($result['product_id']);
         if ($discount) {
             $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
             $special = $promoton->getProductSpecial($result['product_id']);
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
             }
         }
         $options = $this->model_catalog_product->getProductOptions($result['product_id']);
         if ($options) {
             $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
         } else {
             if ($this->config->get('config_cart_ajax')) {
                 $add = '#';
             } else {
                 $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
             }
         }
         $this->data['products'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'thumb' => $thumbnail, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add);
     }
     if ($this->config->get('config_customer_price')) {
         $this->data['display_price'] = TRUE;
     } elseif ($this->customer->isLogged()) {
         $this->data['display_price'] = TRUE;
     } else {
         $this->data['display_price'] = FALSE;
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     // framed needs to show frames for generic block.
     //If tpl used by listing block framed was set by listing block settings
     $this->data['block_framed'] = true;
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Ejemplo n.º 2
0
 public function category()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/product');
     $promoton = new APromotion($this->request->get['customer_group_id']);
     if (isset($this->request->get['category_id'])) {
         $category_id = $this->request->get['category_id'];
     } else {
         $category_id = 0;
     }
     $product_data = array();
     $results = $this->model_catalog_product->getProductsByCategoryId($category_id);
     foreach ($results as $result) {
         $discount = $promoton->getProductDiscount($result['product_id']);
         if ($discount) {
             $price = $discount;
         } else {
             $price = $result['price'];
             $special = $promoton->getProductSpecial($result['product_id']);
             if ($special) {
                 $price = $special;
             }
         }
         if (!empty($this->request->get['currency']) && !empty($this->request->get['value'])) {
             $price = $this->currency->format((double) $price, $this->request->get['currency'], $this->request->get['value']);
         } else {
             $price = $this->currency->format((double) $price);
         }
         $product_data[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'price' => $price);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($product_data));
 }
Ejemplo n.º 3
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $url = '';
     if (isset($this->request->get['keyword'])) {
         $url .= '&keyword=' . $this->request->get['keyword'];
     }
     if (isset($this->request->get['category_id'])) {
         $url .= '&category_id=' . $this->request->get['category_id'];
     }
     if (isset($this->request->get['description'])) {
         $url .= '&description=' . $this->request->get['description'];
     }
     if (isset($this->request->get['model'])) {
         $url .= '&model=' . $this->request->get['model'];
     }
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/search', $url), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')));
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['sort'])) {
         list($sort, $order) = explode("-", $this->request->get['sort']);
     } else {
         list($sort, $order) = explode("-", $this->config->get('config_product_default_sort_order'));
         if ($sort == 'name') {
             $sort = 'pd.' . $sort;
         } elseif (in_array($sort, array('sort_order', 'price'))) {
             $sort = 'p.' . $sort;
         }
     }
     $this->data['keyword'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'keyword', 'value' => $this->request->get['keyword']));
     $this->data['keyword'] = $this->data['keyword']->getHtml();
     $this->loadModel('catalog/category');
     $categories = $this->_getCategories(0);
     $options = array(0 => $this->language->get('text_category'));
     if ($categories) {
         foreach ($categories as $item) {
             $options[$item['category_id']] = $item['name'];
         }
     }
     $this->data['category'] = HtmlElementFactory::create(array('type' => 'selectbox', 'name' => 'category_id', 'options' => $options, 'value' => $this->request->get['category_id']));
     $this->data['description'] = HtmlElementFactory::create(array('type' => 'checkbox', 'id' => 'description', 'name' => 'description', 'checked' => (int) $this->request->get['description'], 'value' => 1, 'label_text' => $this->language->get('entry_description')));
     $this->data['model'] = HtmlElementFactory::create(array('type' => 'checkbox', 'id' => 'model', 'name' => 'model', 'checked' => (bool) $this->request->get['model'], 'value' => 1, 'label_text' => $this->language->get('entry_model')));
     $this->data['submit'] = HtmlElementFactory::create(array('type' => 'button', 'name' => 'search_button', 'text' => $this->language->get('button_search'), 'icon' => 'icon-search', 'style' => 'button'));
     if (isset($this->request->get['keyword'])) {
         $this->loadModel('catalog/product');
         $promoton = new APromotion();
         if (isset($this->request->get['category_id'])) {
             $category_id = explode(',', $this->request->get['category_id']);
             end($category_id);
             $category_id = current($category_id);
         } else {
             $category_id = '';
         }
         $product_total = $this->model_catalog_product->getTotalProductsByKeyword($this->request->get['keyword'], $category_id, isset($this->request->get['description']) ? $this->request->get['description'] : '', isset($this->request->get['model']) ? $this->request->get['model'] : '');
         if ($product_total) {
             $url = '';
             if (isset($this->request->get['category_id'])) {
                 $url .= '&category_id=' . $this->request->get['category_id'];
             }
             if (isset($this->request->get['description'])) {
                 $url .= '&description=' . $this->request->get['description'];
             }
             if (isset($this->request->get['model'])) {
                 $url .= '&model=' . $this->request->get['model'];
             }
             $limit = $this->config->get('config_catalog_limit');
             if (isset($this->request->get['limit']) && intval($this->request->get['limit']) > 0) {
                 $limit = intval($this->request->get['limit']);
                 if ($limit > 50) {
                     $limit = 50;
                 }
             }
             $this->loadModel('catalog/review');
             $this->loadModel('tool/seo_url');
             $products = array();
             $results = $this->model_catalog_product->getProductsByKeyword($this->request->get['keyword'], $category_id, isset($this->request->get['description']) ? $this->request->get['description'] : '', isset($this->request->get['model']) ? $this->request->get['model'] : '', $sort, $order, ($page - 1) * $limit, $limit);
             //if single result, redirect to the product
             if (count($results) == 1) {
                 $this->redirect($this->html->getSEOURL('product/product', '&product_id=' . key($results), '&encode'));
             }
             $resource = new AResource('image');
             if (is_array($results) && $results) {
                 foreach ($results as $result) {
                     $thumbnail = $resource->getMainThumb('products', $result['product_id'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'), true);
                     if ($this->config->get('enable_reviews')) {
                         $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
                     } else {
                         $rating = false;
                     }
                     $special = FALSE;
                     $discount = $promoton->getProductDiscount($result['product_id']);
                     if ($discount) {
                         $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
                     } else {
                         $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                         $special = $promoton->getProductSpecial($result['product_id']);
                         if ($special) {
                             $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                         }
                     }
                     $options = $this->model_catalog_product->getProductOptions($result['product_id']);
                     if ($options) {
                         $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
                     } else {
                         if ($this->config->get('config_cart_ajax')) {
                             $add = '#';
                         } else {
                             $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
                         }
                     }
                     $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'thumb' => $thumbnail, 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'href' => $this->html->getSEOURL('product/product', '&keyword=' . $this->request->get['keyword'] . $url . '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'));
                 }
             }
             $this->data['products'] = $products;
             if ($this->config->get('config_customer_price')) {
                 $display_price = TRUE;
             } elseif ($this->customer->isLogged()) {
                 $display_price = TRUE;
             } else {
                 $display_price = FALSE;
             }
             $this->data['display_price'] = $display_price;
             $url = '';
             if (isset($this->request->get['keyword'])) {
                 $url .= '&keyword=' . $this->request->get['keyword'];
             }
             if (isset($this->request->get['category_id'])) {
                 $url .= '&category_id=' . $this->request->get['category_id'];
             }
             if (isset($this->request->get['description'])) {
                 $url .= '&description=' . $this->request->get['description'];
             }
             if (isset($this->request->get['model'])) {
                 $url .= '&model=' . $this->request->get['model'];
             }
             if (isset($this->request->get['page'])) {
                 $url .= '&page=' . $this->request->get['page'];
             }
             if (isset($this->request->get['limit'])) {
                 $url .= '&limit=' . $this->request->get['limit'];
             }
             $sorts = array();
             $sorts[] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.sort_order&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=pd.name&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=pd.name&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.price&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.price&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=rating&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=rating&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_desc'), 'value' => 'date_modified-DESC', 'href' => $this->html->getSEOURL('product/search', $url . '&sort=date_modified&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_asc'), 'value' => 'date_modified-ASC', 'href' => $this->html->getSEOURL('product/search', $url . '&sort=date_modified&order=ASC', '&encode'));
             $this->data['sorts'] = $sorts;
             $options = array();
             foreach ($sorts as $item) {
                 $options[$item['value']] = $item['text'];
             }
             $sorting = $this->html->buildSelectbox(array('name' => 'sort', 'options' => $options, 'value' => $sort . '-' . $order));
             $this->data['sorting'] = $sorting;
             $url = '';
             if (isset($this->request->get['keyword'])) {
                 $url .= '&keyword=' . $this->request->get['keyword'];
             }
             if (isset($this->request->get['category_id'])) {
                 $url .= '&category_id=' . $this->request->get['category_id'];
             }
             if (isset($this->request->get['description'])) {
                 $url .= '&description=' . $this->request->get['description'];
             }
             if (isset($this->request->get['model'])) {
                 $url .= '&model=' . $this->request->get['model'];
             }
             if (isset($this->request->get['sort'])) {
                 $url .= '&sort=' . $this->request->get['sort'];
             }
             if (isset($this->request->get['order'])) {
                 $url .= '&order=' . $this->request->get['order'];
             }
             if (isset($this->request->get['limit'])) {
                 $url .= '&limit=' . $this->request->get['limit'];
             }
             $this->data['pagination_bootstrap'] = HtmlElementFactory::create(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => $product_total, 'page' => $page, 'limit' => $limit, 'url' => $this->html->getURL('product/search', $url . '&page={page}', '&encode'), 'style' => 'pagination'));
             $this->data['sort'] = $sort;
             $this->data['order'] = $order;
             $this->data['limit'] = $limit;
         }
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/product/search.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Ejemplo n.º 4
0
 /**
  * Collect product information for cart based on user selections
  * Function can be used to get totals and other product information
  * (based on user selection) as it is before getting into cart or after
  * @param int $product_id
  * @param int $quantity
  * @param array $options
  * @return array
  */
 public function buildProductDetails($product_id, $quantity = 0, $options = array())
 {
     if (!has_value($product_id) || !is_numeric($product_id) || $quantity == 0) {
         return array();
     }
     $stock = TRUE;
     $sf_product_mdl = $this->load->model('catalog/product', 'storefront');
     $elements_with_options = HtmlElementFactory::getElementsWithOptions();
     $product_query = $sf_product_mdl->getProductDataForCart($product_id);
     if (count($product_query) <= 0 || $product_query['call_to_order']) {
         return array();
     }
     $option_price = 0;
     $option_data = array();
     $groups = array();
     //Process each option and value
     foreach ($options as $product_option_id => $product_option_value_id) {
         //skip empty values
         if ($product_option_value_id == '' || is_array($product_option_value_id) && !$product_option_value_id) {
             continue;
         }
         $option_query = $sf_product_mdl->getProductOption($product_id, $product_option_id);
         $element_type = $option_query['element_type'];
         if (!in_array($element_type, $elements_with_options)) {
             //This is single value element, get all values and expect only one
             $option_value_query = $sf_product_mdl->getProductOptionValues($product_id, $product_option_id);
             $option_value_query = $option_value_query[0];
             //Set value from input
             $option_value_query['name'] = $this->db->escape($options[$product_option_id]);
         } else {
             //is multivalue option type
             if (is_array($product_option_value_id)) {
                 $option_value_queries = array();
                 foreach ($product_option_value_id as $val_id) {
                     $option_value_queries[$val_id] = $sf_product_mdl->getProductOptionValue($product_id, $val_id);
                 }
             } else {
                 $option_value_query = $sf_product_mdl->getProductOptionValue($product_id, (int) $product_option_value_id);
             }
         }
         if ($option_value_query) {
             //if group option load price from parent value
             if ($option_value_query['group_id'] && !in_array($option_value_query['group_id'], $groups)) {
                 $group_value_query = $sf_product_mdl->getProductOptionValue($product_id, $option_value_query['group_id']);
                 $option_value_query['prefix'] = $group_value_query['prefix'];
                 $option_value_query['price'] = $group_value_query['price'];
                 $groups[] = $option_value_query['group_id'];
             }
             $option_data[] = array('product_option_value_id' => $option_value_query['product_option_value_id'], 'product_option_id' => $product_option_id, 'name' => $option_query['name'], 'element_type' => $element_type, 'settings' => $option_query['settings'], 'value' => $option_value_query['name'], 'prefix' => $option_value_query['prefix'], 'price' => $option_value_query['price'], 'sku' => $option_value_query['sku'], 'weight' => $option_value_query['weight'], 'weight_type' => $option_value_query['weight_type']);
             //check if need to track stock and we have it
             if ($option_value_query['subtract'] && $option_value_query['quantity'] < $quantity) {
                 $stock = FALSE;
             }
             $op_stock_trackable += $option_value_query['subtract'];
             unset($option_value_query);
         } else {
             if ($option_value_queries) {
                 foreach ($option_value_queries as $item) {
                     $option_data[] = array('product_option_value_id' => $item['product_option_value_id'], 'name' => $option_query['name'], 'value' => $item['name'], 'prefix' => $item['prefix'], 'price' => $item['price'], 'sku' => $item['sku'], 'weight' => $item['weight'], 'weight_type' => $item['weight_type']);
                     //check if need to track stock and we have it
                     if ($item['subtract'] && $item['quantity'] < $quantity) {
                         $stock = FALSE;
                     }
                     $op_stock_trackable += $option_value_query['subtract'];
                 }
                 unset($option_value_queries);
             }
         }
     }
     // end of options build
     //needed for promotion
     $discount_quantity = 0;
     // this is used to calculate total QTY of 1 product in the cart
     // check is product is in cart and calculate quantity to define item price with product discount
     foreach ($this->cust_data['cart'] as $k => $v) {
         $array2 = explode(':', $k);
         if ($array2[0] == $product_id) {
             $discount_quantity += $v['qty'];
         }
     }
     if (!$discount_quantity) {
         $discount_quantity = $quantity;
     }
     //Apply group and quantity discount first and if non, reply product discount
     $price = $this->promotion->getProductQtyDiscount($product_id, $discount_quantity);
     if (!$price) {
         $price = $this->promotion->getProductSpecial($product_id);
     }
     //Still no special price, use regulr price
     if (!$price) {
         $price = $product_query['price'];
     }
     foreach ($option_data as $item) {
         if ($item['prefix'] == '%') {
             $option_price += $price * $item['price'] / 100;
         } else {
             $option_price += $item['price'];
         }
     }
     // product downloads
     $download_data = $this->download->getProductOrderDownloads($product_id);
     //check if we need to check main product stock. Do only if no stock trakable options selected
     if (!$op_stock_trackable && $product_query['subtract'] && $product_query['quantity'] < $quantity) {
         $stock = FALSE;
     }
     $result = array('product_id' => $product_query['product_id'], 'name' => $product_query['name'], 'model' => $product_query['model'], 'shipping' => $product_query['shipping'], 'option' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'minimum' => $product_query['minimum'], 'maximum' => $product_query['maximum'], 'stock' => $stock, 'price' => $price + $option_price, 'total' => ($price + $option_price) * $quantity, 'tax_class_id' => $product_query['tax_class_id'], 'weight' => $product_query['weight'], 'weight_class' => $product_query['weight_class'], 'length' => $product_query['length'], 'width' => $product_query['width'], 'height' => $product_query['height'], 'length_class' => $product_query['length_class'], 'ship_individually' => $product_query['ship_individually'], 'shipping_price' => $product_query['shipping_price'], 'free_shipping' => $product_query['free_shipping'], 'sku' => $product_query['sku']);
     return $result;
 }
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('product/special');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $url = '';
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/special', $url), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')));
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = (int) $this->request->get['limit'];
         $limit = $limit > 50 ? 50 : $limit;
     } else {
         $limit = $this->config->get('config_catalog_limit');
     }
     if (isset($this->request->get['sort'])) {
         $sorting_href = $this->request->get['sort'];
         list($sort, $order) = explode("-", $sorting_href);
     } else {
         $sorting_href = $this->config->get('config_product_default_sort_order');
         list($sort, $order) = explode("-", $sorting_href);
         if ($sort == 'name') {
             $sort = 'pd.' . $sort;
         } elseif (in_array($sort, array('sort_order', 'price'))) {
             $sort = 'p.' . $sort;
         }
     }
     $this->loadModel('catalog/product');
     $promoton = new APromotion();
     $product_total = $promoton->getTotalProductSpecials();
     if ($product_total) {
         $this->loadModel('catalog/review');
         $this->loadModel('tool/seo_url');
         $this->loadModel('tool/image');
         $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
         $results = $promoton->getProductSpecials($sort, $order, ($page - 1) * $limit, $limit);
         $resource = new AResource('image');
         foreach ($results as $result) {
             $thumbnail = $resource->getMainThumb('products', $result['product_id'], (int) $this->config->get('config_image_product_width'), (int) $this->config->get('config_image_product_height'), true);
             if ($this->config->get('enable_reviews')) {
                 $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
             } else {
                 $rating = false;
             }
             $special = FALSE;
             $discount = $promoton->getProductDiscount($result['product_id']);
             if ($discount) {
                 $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                 $special = $promoton->getProductSpecial($result['product_id']);
                 if ($special) {
                     $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                 }
             }
             $options = $this->model_catalog_product->getProductOptions($result['product_id']);
             if ($options) {
                 $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
             } else {
                 if ($this->config->get('config_cart_ajax')) {
                     $add = '#';
                 } else {
                     $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
                 }
             }
             //check for stock status, availability and config
             $track_stock = false;
             $in_stock = false;
             $no_stock_text = $result['stock'];
             $total_quantity = 0;
             if ($this->model_catalog_product->isStockTrackable($result['product_id'])) {
                 $track_stock = true;
                 $total_quantity = $this->model_catalog_product->hasAnyStock($result['product_id']);
                 //we have stock or out of stock checkout is allowed
                 if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
                     $in_stock = true;
                 }
             }
             $this->data['products'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'thumb' => $thumbnail, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 'track_stock' => $track_stock, 'in_stock' => $in_stock, 'no_stock_text' => $no_stock_text, 'total_quantity' => $total_quantity);
         }
         if ($this->config->get('config_customer_price')) {
             $display_price = TRUE;
         } elseif ($this->customer->isLogged()) {
             $display_price = TRUE;
         } else {
             $display_price = FALSE;
         }
         $this->data['display_price'] = $display_price;
         $sorts = array();
         $sorts[] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->html->getURL('product/special', $url . '&sort=p.sort_order&order=ASC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->html->getURL('product/special', $url . '&sort=pd.name&order=ASC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->html->getURL('product/special', $url . '&sort=pd.name&order=DESC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_price_asc'), 'value' => 'ps.price-ASC', 'href' => $this->html->getURL('product/special', $url . '&sort=special&order=ASC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_price_desc'), 'value' => 'ps.price-DESC', 'href' => $this->html->getURL('product/special', $url . '&sort=special&order=DESC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->html->getURL('product/special', $url . '&sort=rating&order=DESC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->html->getURL('product/special', $url . '&sort=rating&order=ASC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_date_desc'), 'value' => 'date_modified-DESC', 'href' => $this->html->getSEOURL('product/special', $url . '&sort=date_modified&order=DESC', '&encode'));
         $sorts[] = array('text' => $this->language->get('text_sorting_date_asc'), 'value' => 'date_modified-ASC', 'href' => $this->html->getSEOURL('product/special', $url . '&sort=date_modified&order=ASC', '&encode'));
         $options = array();
         foreach ($sorts as $item) {
             $options[$item['value']] = $item['text'];
         }
         $sorting = $this->html->buildSelectbox(array('name' => 'sort', 'options' => $options, 'value' => $sort . '-' . $order));
         $this->view->assign('sorting', $sorting);
         $this->view->assign('url', $this->html->getURL('product/special'));
         $this->data['sorts'] = $sorts;
         $pagination_url = $this->html->getURL('product/special', '&sort=' . $sorting_href . '&page={page}' . '&limit=' . $limit, '&encode');
         $this->data['pagination_bootstrap'] = HtmlElementFactory::create(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => $product_total, 'page' => $page, 'limit' => $limit, 'url' => $pagination_url, 'style' => 'pagination'));
         $this->data['sort'] = $sort;
         $this->data['order'] = $order;
         $this->data['review_status'] = $this->config->get('enable_reviews');
         $this->view->batchAssign($this->data);
         $this->view->setTemplate('pages/product/special.tpl');
     } else {
         $this->view->assign('text_error', $this->language->get('text_empty'));
         $continue = HtmlElementFactory::create(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'style' => 'button'));
         $this->view->assign('button_continue', $continue);
         $this->view->assign('continue', $this->html->getURL('index/home'));
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Ejemplo n.º 6
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->loadModel('tool/seo_url');
     $this->loadModel('catalog/category');
     if (isset($this->request->get['path'])) {
         $path = '';
         foreach (explode('_', $this->request->get['path']) as $path_id) {
             $category_info = $this->model_catalog_category->getCategory($path_id);
             if (!$path) {
                 $path = $path_id;
             } else {
                 $path .= '_' . $path_id;
             }
             if ($category_info) {
                 $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/category', '&path=' . $path, '&encode'), 'text' => $category_info['name'], 'separator' => $this->language->get('text_separator')));
             }
         }
     }
     $this->loadModel('catalog/manufacturer');
     if (isset($this->request->get['manufacturer_id'])) {
         $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
         if ($manufacturer_info) {
             $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $this->request->get['manufacturer_id'], '&encode'), 'text' => $manufacturer_info['name'], 'separator' => $this->language->get('text_separator')));
         }
     }
     if (isset($this->request->get['keyword'])) {
         $url = '';
         if (isset($this->request->get['category_id'])) {
             $url .= '&category_id=' . $this->request->get['category_id'];
         }
         if (isset($this->request->get['description'])) {
             $url .= '&description=' . $this->request->get['description'];
         }
         $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/search', '&keyword=' . $this->request->get['keyword'] . $url, '&encode'), 'text' => $this->language->get('text_search'), 'separator' => $this->language->get('text_separator')));
     }
     $key = array();
     //key of product from cart
     if (has_value($this->request->get['key'])) {
         $key = explode(':', $this->request->get['key']);
         $product_id = (int) $key[0];
     } elseif (has_value($this->request->get['product_id'])) {
         $product_id = (int) $this->request->get['product_id'];
     } else {
         $product_id = 0;
     }
     $urls = array('is_group_option' => $this->html->getURL('r/product/product/is_group_option', '&product_id=' . $product_id, '&encode'));
     $this->view->assign('urls', $urls);
     $this->loadModel('catalog/product');
     $promoton = new APromotion();
     $product_info = $this->model_catalog_product->getProduct($product_id);
     //can not locate product? get out
     if (!$product_info) {
         $this->_product_not_found($product_id);
         return null;
     }
     $url = $this->_build_url();
     $this->view->assign('error', '');
     if (isset($this->session->data['error'])) {
         $this->view->assign('error', $this->session->data['error']);
         unset($this->session->data['error']);
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/product', $url . '&product_id=' . $product_id, '&encode'), 'text' => $product_info['name'], 'separator' => $this->language->get('text_separator')));
     $this->document->setTitle($product_info['name']);
     $this->document->setKeywords($product_info['meta_keywords']);
     $this->document->setDescription($product_info['meta_description']);
     $this->document->addLink(array('href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, '&encode'), 'rel' => 'canonical'));
     $this->data['heading_title'] = $product_info['name'];
     $this->data['minimum'] = $product_info['minimum'];
     $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
     $this->data['maximum'] = $product_info['maximum'];
     $this->data['text_maximum'] = sprintf($this->language->get('text_maximum'), $product_info['maximum']);
     $this->data['option_resources_url'] = $this->html->getURL('r/product/product/get_option_resources');
     $this->data['calc_total_url'] = $this->html->getURL('r/product/product/calculateTotal');
     $this->data['product_review_url'] = $this->html->getURL('product/review/review', '&product_id=' . $product_id);
     $this->data['product_review_write_url'] = $this->html->getURL('product/review/write', '&product_id=' . $product_id);
     $this->data['product_wishlist_add_url'] = $this->html->getURL('product/wishlist/add', '&product_id=' . $product_id);
     $this->data['product_wishlist_remove_url'] = $this->html->getURL('product/wishlist/remove', '&product_id=' . $product_id);
     $this->data['captcha_url'] = $this->html->getURL('common/captcha');
     $this->loadModel('catalog/review');
     $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($product_id));
     if ($this->config->get('enable_reviews')) {
         $average = $this->model_catalog_review->getAverageRating($product_id);
     } else {
         $average = false;
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     $this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average);
     $this->data['rating_element'] = HtmlElementFactory::create(array('type' => 'rating', 'name' => 'rating', 'value' => '', 'options' => array(1 => 1, 2, 3, 4, 5), 'pack' => true));
     $this->data['review_name'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'name'));
     $this->data['review_text'] = HtmlElementFactory::create(array('type' => 'textarea', 'name' => 'text', 'attr' => ' rows="8" cols="50" '));
     $this->data['review_captcha'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'captcha', 'attr' => ''));
     $this->data['review_button'] = HtmlElementFactory::create(array('type' => 'button', 'name' => 'review_submit', 'text' => $this->language->get('button_submit'), 'style' => 'btn-primary', 'icon' => 'fa fa-comment'));
     $this->data['product_info'] = $product_info;
     $form = new AForm();
     $form->setForm(array('form_name' => 'product'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'product', 'action' => $this->html->getSecureURL('checkout/cart')));
     $product_price = $product_info['price'];
     $discount = $promoton->getProductDiscount($product_id);
     if ($discount) {
         $product_price = $discount;
         $this->data['price_num'] = $this->tax->calculate($discount, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         $this->data['special'] = FALSE;
     } else {
         $this->data['price_num'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         $special = $promoton->getProductSpecial($product_id);
         if ($special) {
             $product_price = $special;
             $this->data['special_num'] = $this->tax->calculate($special, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         } else {
             $this->data['special'] = FALSE;
         }
     }
     $this->data['price'] = $this->currency->format($this->data['price_num']);
     if (isset($this->data['special_num'])) {
         $this->data['special'] = $this->currency->format($this->data['special_num']);
     }
     $product_discounts = $promoton->getProductDiscounts($product_id);
     $discounts = array();
     foreach ($product_discounts as $discount) {
         $discounts[] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'))));
     }
     $this->data['discounts'] = $discounts;
     $this->data['product_price'] = $product_price;
     $this->data['tax_class_id'] = $product_info['tax_class_id'];
     if (!$product_info['call_to_order']) {
         $this->data['form']['minimum'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => $product_info['minimum'] ? (int) $product_info['minimum'] : 1, 'style' => 'short', 'attr' => ' size="3" '));
         $this->data['form']['add_to_cart'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'add_to_cart', 'text' => $this->language->get('button_add_to_cart'), 'style' => 'button1'));
     }
     $this->data['form']['product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_id', 'value' => $product_id));
     $this->data['form']['redirect'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'redirect', 'value' => $this->html->getURL('product/product', $url . '&product_id=' . $product_id, '&encode')));
     $this->data['model'] = $product_info['model'];
     $this->data['manufacturer'] = $product_info['manufacturer'];
     $this->data['manufacturers'] = $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $product_info['manufacturer_id'], '&encode');
     $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
     $this->data['product_id'] = $product_id;
     $this->data['average'] = $average;
     $resource = new AResource('image');
     $thumbnail = $resource->getMainThumb('manufacturers', $product_info['manufacturer_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), true);
     if (!preg_match('/no_image/', $thumbnail['thumb_url'])) {
         $this->data['manufacturer_icon'] = $thumbnail['thumb_url'];
     }
     // Preapare options and values for display
     $elements_with_options = HtmlElementFactory::getElementsWithOptions();
     $options = array();
     $product_options = $this->model_catalog_product->getProductOptions($product_id);
     //get info from cart if key presents
     $cart_product_info = array();
     if ($key) {
         $cart_product_info = $this->cart->getProduct($this->request->get['key']);
     }
     foreach ($product_options as $option) {
         $values = array();
         $name = $price = '';
         $default_value = $cart_product_info['options'][$option['product_option_id']];
         if ($option['element_type'] == 'R') {
             $default_value = is_array($default_value) ? current($default_value) : (string) $default_value;
         }
         $preset_value = $default_value;
         foreach ($option['option_value'] as $option_value) {
             $default_value = $option_value['default'] && !$default_value ? $option_value['product_option_value_id'] : $default_value;
             // for case when trying to add to cart withot required options. we get option-array back inside _GET
             if (has_value($this->request->get['option'][$option['product_option_id']])) {
                 $default_value = $this->request->get['option'][$option['product_option_id']];
             }
             $name = $option_value['name'];
             //check if we disable options based on out of stock setting
             if ($option_value['subtract'] && $this->config->get('config_nostock_autodisable') && $option_value['quantity'] <= 0) {
                 continue;
             }
             //Apply option price modifier
             if ($option_value['prefix'] == '%') {
                 $price = $this->tax->calculate($product_price * $option_value['price'] / 100, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
                 if ($price != 0) {
                     $price = $this->currency->format($price);
                 } else {
                     $price = '';
                 }
             } else {
                 $price = $this->tax->calculate($option_value['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
                 if ($price != 0) {
                     $price = $this->currency->format($price);
                 } else {
                     $price = '';
                 }
             }
             //Check stock and status
             $opt_stock_message = '';
             if ($option_value['subtract']) {
                 if ($option_value['quantity'] <= 0) {
                     //show out of stock message
                     $opt_stock_message = $product_info['stock_status'];
                 } else {
                     if ($this->config->get('config_stock_display')) {
                         $opt_stock_message = $option_value['quantity'] . " " . $this->language->get('text_instock');
                     }
                 }
             }
             $values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message;
         }
         //if not values are build, nothing to show
         if (count($values)) {
             $value = '';
             //add price to option name if it is not element with options
             if (!in_array($option['element_type'], $elements_with_options)) {
                 $option['name'] .= ' <small>' . $price . '</small>';
                 if ($opt_stock_message) {
                     $option['name'] .= '<br />' . $opt_stock_message;
                 }
                 $value = $default_value ? $default_value : $name;
             }
             //set default selection is nothing selected
             if (!has_value($value)) {
                 if (has_value($default_value)) {
                     $value = $default_value;
                 } else {
                     if (in_array($option['element_type'], $elements_with_options) && $option['element_type'] != 'S') {
                         //set first from the list to default
                         reset($values);
                         $value = key($values);
                     }
                 }
             }
             //for checkbox with empty value
             if ($value == '' && $option['element_type'] == 'C') {
                 $value = 1;
             }
             $option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'option[' . $option['product_option_id'] . ']' : 'option[' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'required' => $option['required'], 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text']);
             if ($option['element_type'] == 'C') {
                 if (!in_array($value, array('0', '1'))) {
                     $option_data['label_text'] = $value;
                 }
                 $option_data['checked'] = $preset_value ? true : false;
             }
             $options[] = array('name' => $option['name'], 'html' => $this->html->buildElement($option_data));
         }
     }
     $this->data['options'] = $options;
     //handle stock messages
     // if track stock is off. no messages needed.
     if ($this->model_catalog_product->isStockTrackable($product_id)) {
         $total_quantity = $this->model_catalog_product->hasAnyStock($product_id);
         $this->data['track_stock'] = true;
         //out of stock if no quantity and no stick checkout is disabled
         if ($total_quantity <= 0 && !$this->config->get('config_stock_checkout')) {
             $this->data['in_stock'] = false;
             //show out of stock message
             $this->data['stock'] = $product_info['stock_status'];
         } else {
             $this->data['in_stock'] = true;
             if ($this->config->get('config_stock_display')) {
                 $this->data['stock'] = $product_info['quantity'];
             } else {
                 $this->data['stock'] = $this->language->get('text_instock');
             }
         }
         //check if we need to disable product for no stock
         if ($this->config->get('config_nostock_autodisable') && $total_quantity <= 0) {
             //set available data
             $pd_identifiers = "ID: " . $product_id;
             $pd_identifiers .= empty($product_info['model']) ? '' : " Model: " . $product_info['model'];
             $pd_identifiers .= empty($product_info['sku']) ? '' : " SKU: " . $product_info['sku'];
             $message_ttl = sprintf($this->language->get('notice_out_of_stock_ttl'), $product_info['name']);
             $message_txt = sprintf($this->language->get('notice_out_of_stock_body'), $product_info['name'], $pd_identifiers);
             //record to message box
             $msg = new AMessage();
             $msg->saveNotice($message_ttl, $message_txt);
             $this->model_catalog_product->updateStatus($product_id, 0);
             $this->redirect($this->html->getSEOURL('product/product', '&product_id=' . $product_info['product_id'], '&encode'));
         }
     }
     // main product image
     $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_thumb_width'), 'height' => $this->config->get('config_image_thumb_height')));
     $this->data['image_main'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 1, false);
     if ($this->data['image_main']) {
         $this->data['image_main']['sizes'] = $sizes;
     }
     // additional images
     $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_additional_width'), 'height' => $this->config->get('config_image_additional_height')));
     $this->data['images'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 0, false);
     $products = array();
     $results = $this->model_catalog_product->getProductRelated($product_id);
     foreach ($results as $result) {
         // related product image
         $sizes = array('main' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height')), 'thumb' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height')));
         $image = $resource->getResourceAllObjects('products', $result['product_id'], $sizes, 1);
         if ($this->config->get('enable_reviews')) {
             $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
         } else {
             $rating = false;
         }
         $special = FALSE;
         $discount = $promoton->getProductDiscount($result['product_id']);
         if ($discount) {
             $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], (bool) $this->config->get('config_tax')));
         } else {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], (bool) $this->config->get('config_tax')));
             $special = $promoton->getProductSpecial($result['product_id']);
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], (bool) $this->config->get('config_tax')));
             }
         }
         $options = $this->model_catalog_product->getProductOptions($result['product_id']);
         if ($options) {
             $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
         } else {
             if ($this->config->get('config_cart_ajax')) {
                 $add = '#';
             } else {
                 $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
             }
         }
         $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'image' => $image, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add);
     }
     $this->data['related_products'] = $products;
     if ($this->config->get('config_customer_price')) {
         $display_price = TRUE;
     } elseif ($this->customer->isLogged()) {
         $display_price = TRUE;
     } else {
         $display_price = FALSE;
     }
     $this->data['display_price'] = $display_price;
     $this->model_catalog_product->updateViewed($product_id);
     $tags = array();
     $results = $this->model_catalog_product->getProductTags($product_id);
     foreach ($results as $result) {
         if ($result['tag']) {
             $tags[] = array('tag' => $result['tag'], 'href' => $this->html->getURL('product/search', '&keyword=' . $result['tag'], '&encode'));
         }
     }
     $this->data['tags'] = $tags;
     //downloads before order if allowed
     if ($this->config->get('config_download')) {
         $dwn = new ADownload();
         $download_list = $dwn->getDownloadsBeforeOrder($product_id);
         if ($download_list) {
             foreach ($download_list as $download) {
                 $href = $this->html->getURL('account/download/startdownload', '&download_id=' . $download['download_id']);
                 $download['attributes'] = $this->download->getDownloadAttributesValuesForCustomer($download['download_id']);
                 $download['button'] = $form->getFieldHtml(array('type' => 'button', 'id' => 'download_' . $download['download_id'], 'href' => $href, 'title' => $this->language->get('text_start_download'), 'text' => $this->language->get('text_start_download')));
                 $downloads[] = $download;
             }
             $this->data['downloads'] = $downloads;
         }
     }
     #check if product is in a wishlist
     $this->data['is_customer'] = false;
     if ($this->customer->isLogged() || $this->customer->isUnauthCustomer()) {
         $this->data['is_customer'] = true;
         $whishlist = $this->customer->getWishList();
         if ($whishlist[$product_id]) {
             $this->data['in_wishlist'] = true;
         }
     }
     $this->view->setTemplate('pages/product/product.tpl');
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Ejemplo n.º 7
0
 public function main()
 {
     if ($this->html_cache()) {
         return;
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('blocks/special');
     $this->data['heading_title'] = $this->language->get('heading_title', 'blocks/special');
     $this->loadModel('catalog/product');
     $this->loadModel('catalog/review');
     $this->loadModel('tool/seo_url');
     $this->loadModel('tool/image');
     $promotion = new APromotion();
     $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
     $this->data['products'] = array();
     $results = $promotion->getSpecialProducts(array('sort' => 'pd.name', 'order' => 'ASC', 'start' => 0, 'limit' => $this->config->get('config_special_limit'), 'avg_rating' => $this->config->get('enable_reviews')));
     $product_ids = array();
     foreach ($results as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     //get thumbnails by one pass
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
     $stock_info = $this->model_catalog_product->getProductsStockInfo($product_ids);
     foreach ($results as $result) {
         $thumbnail = $thumbnails[$result['product_id']];
         $special = FALSE;
         $discount = $result['discount_price'];
         if ($discount) {
             $price = $discount;
         } else {
             $price = $result['price'];
             $special = $promotion->getProductSpecial($result['product_id']);
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
             }
         }
         $price = $this->currency->format($this->tax->calculate($price, $result['tax_class_id'], $this->config->get('config_tax')));
         $options = $this->model_catalog_product->getProductOptions($result['product_id']);
         if ($options) {
             $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
         } else {
             if ($this->config->get('config_cart_ajax')) {
                 $add = '#';
             } else {
                 $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
             }
         }
         //check for stock status, availability and config
         $track_stock = false;
         $in_stock = false;
         $no_stock_text = $result['stock'];
         $total_quantity = 0;
         if ($stock_info[$result['product_id']]['subtract']) {
             $track_stock = true;
             $total_quantity = $stock_info[$result['product_id']]['quantity'];
             //we have stock or out of stock checkout is allowed
             if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
                 $in_stock = true;
             }
         }
         $this->data['products'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'blurb' => $result['blurb'], 'model' => $result['model'], 'rating' => (int) $result['rating'], 'stars' => sprintf($this->language->get('text_stars'), (int) $result['rating']), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'thumb' => $thumbnail, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'track_stock' => $track_stock, 'in_stock' => $in_stock, 'no_stock_text' => $no_stock_text, 'total_quantity' => $total_quantity, 'date_added' => $result['date_added']);
     }
     if ($this->config->get('config_customer_price')) {
         $this->data['display_price'] = TRUE;
     } elseif ($this->customer->isLogged()) {
         $this->data['display_price'] = TRUE;
     } else {
         $this->data['display_price'] = FALSE;
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     // framed needs to show frames for generic block.
     //If tpl used by listing block framed was set by listing block settings
     $this->data['block_framed'] = true;
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }