/**
  * Returns coupon info in case it's applicable. Used in customer section
  * @param string $code
  * @param bool $chosenProducts
  * @return array
  */
 public function applyCoupon($code, $chosenProducts = false)
 {
     $status = true;
     $coupon_query = $this->getDb()->query("\n\t\t    SELECT *\n\t\t    FROM coupon\n\t\t    WHERE\n\t\t        code = :code\n\t\t        AND ((date_start = '0000-00-00' OR date_start < :dateStart)\n\t\t        AND (date_end = '0000-00-00' OR date_end > :dateEnd))\n\t\t        AND status = 1\n            ", [":code" => $code, ":dateStart" => date('Y-m-d H:00:00'), ":dateEnd" => date('Y-m-d H:00:00', strtotime('+1 hour'))]);
     if ($coupon_query->num_rows) {
         if ($coupon_query->row['total'] >= $this->cart->getSubTotal($chosenProducts)) {
             $status = false;
         }
         $coupon_history_query = $this->getDb()->query("SELECT COUNT(*) AS total FROM `coupon_history` ch WHERE ch.coupon_id = '" . (int) $coupon_query->row['coupon_id'] . "'");
         if ($coupon_query->row['uses_total'] > 0 && $coupon_history_query->row['total'] >= $coupon_query->row['uses_total']) {
             $status = false;
         }
         if ($coupon_query->row['logged'] && !$this->customer->getId()) {
             $status = false;
         }
         if ($this->customer->getId()) {
             $coupon_history_query = $this->getDb()->query("SELECT COUNT(*) AS total FROM `coupon_history` ch WHERE ch.coupon_id = '" . (int) $coupon_query->row['coupon_id'] . "' AND ch.customer_id = '" . (int) $this->customer->getId() . "'");
             if ($coupon_query->row['uses_customer'] > 0 && $coupon_history_query->row['total'] >= $coupon_query->row['uses_customer']) {
                 $status = false;
             }
         }
         $coupon_product_query = $this->getDb()->query("SELECT * FROM coupon_product WHERE coupon_id = '" . (int) $coupon_query->row['coupon_id'] . "'");
         $coupon_product_data = array_map(function ($item) {
             return $item['product_id'];
         }, $coupon_product_query->rows);
         if ($coupon_product_data) {
             $coupon_product = false;
             $productsCouponAppliesTo = [];
             foreach ($this->cart->getProducts($chosenProducts) as $product) {
                 if ($coupon_query->row['applies_to_categories']) {
                     $productCategories = array_map(function (ProductCategory $item) {
                         return $item->getCategory()->getId();
                     }, ProductDAO::getInstance()->getCategories($product['product_id']));
                     if (sizeof(array_intersect($productCategories, $coupon_product_data))) {
                         $coupon_product = true;
                         $productsCouponAppliesTo[] = $product['product_id'];
                     }
                 } else {
                     if (in_array($product['product_id'], $coupon_product_data)) {
                         $coupon_product = true;
                         $productsCouponAppliesTo[] = $product['product_id'];
                     }
                 }
             }
             if (!$coupon_product) {
                 $status = false;
             }
         }
     } else {
         $status = false;
     }
     if ($status) {
         return array('coupon_id' => $coupon_query->row['coupon_id'], 'code' => $coupon_query->row['code'], 'name' => $coupon_query->row['name'], 'type' => $coupon_query->row['type'], 'discount' => $coupon_query->row['discount'], 'shipping' => $coupon_query->row['shipping'], 'total' => $coupon_query->row['total'], 'product' => $productsCouponAppliesTo, 'date_start' => $coupon_query->row['date_start'], 'date_end' => $coupon_query->row['date_end'], 'uses_total' => $coupon_query->row['uses_total'], 'uses_customer' => $coupon_query->row['uses_customer'], 'status' => $coupon_query->row['status'], 'date_added' => $coupon_query->row['date_added']);
     }
 }
Example #2
0
 private function changeStatusProducts($status)
 {
     if (isset($this->request->post['selected']) && $this->validateChange()) {
         foreach ($this->getRequest()->getParam('selected') as $productId) {
             $product = ProductDAO::getInstance()->getProduct($productId, true);
             $product->setStatus($status);
             ProductDAO::getInstance()->saveProduct($product);
         }
         $this->getSession()->data['success'] = $this->language->get('text_success');
         $url = '';
         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'];
         }
         $this->redirect($this->getUrl()->link('catalog/product', 'token=' . $this->getSession()->data['token'] . $url, 'SSL'));
     }
     $this->getList();
 }
Example #3
0
 /**
  *
  */
 public function index()
 {
     $this->language->load('product/product');
     if (isset($this->request->get['path'])) {
         $path = '';
         foreach (explode('_', $this->request->get['path']) as $path_id) {
             if (!$path) {
                 $path = $path_id;
             } else {
                 $path .= '_' . $path_id;
             }
             $category = CategoryDAO::getInstance()->getCategory($path_id);
             if ($category) {
                 #kabantejay synonymizer start
                 $razdel = $category->getDescription()->getName();
                 #kabantejay synonymizer end
                 $this->setBreadcrumbs([['text' => $category->getDescription()->getName(), 'route' => 'product/category&path=' . $path]]);
             }
         }
     }
     if (isset($this->request->get['manufacturer_id'])) {
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_brand'), 'href' => $this->getUrl()->link('product/manufacturer'), 'separator' => $this->language->get('text_separator'));
         $manufacturer_info = ManufacturerDAO::getInstance()->getManufacturer($this->request->get['manufacturer_id']);
         if ($manufacturer_info) {
             $this->data['breadcrumbs'][] = array('text' => $manufacturer_info['name'], 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id']), 'separator' => $this->language->get('text_separator'));
         }
     }
     if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) {
         $url = '';
         if (isset($this->request->get['filter_name'])) {
             $url .= '&filter_name=' . $this->request->get['filter_name'];
         }
         if (isset($this->request->get['filter_tag'])) {
             $url .= '&filter_tag=' . $this->request->get['filter_tag'];
         }
         if (isset($this->request->get['filter_description'])) {
             $url .= '&filter_description=' . $this->request->get['filter_description'];
         }
         if (isset($this->request->get['filter_category_id'])) {
             $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
         }
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_search'), 'href' => $this->getUrl()->link('product/search', $url), 'separator' => $this->language->get('text_separator'));
     }
     if (isset($this->request->get['product_id'])) {
         $productId = $this->request->get['product_id'];
     } else {
         $productId = 0;
     }
     try {
         $product = ProductDAO::getInstance()->getProduct($productId, false, true);
         $description = is_null($product->getDescription($this->getLanguage()->getId())) ? new \model\localization\Description($this->getLanguage()->getId(), '') : $product->getDescription($this->getLanguage()->getId());
         $this->data['product_info'] = $product;
         //print_r($product_info);exit;
         $url = '';
         if (isset($this->request->get['path'])) {
             $url .= '&path=' . $this->request->get['path'];
         }
         if (isset($this->request->get['manufacturer_id'])) {
             $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
         }
         if (isset($this->request->get['filter_name'])) {
             $url .= '&filter_name=' . $this->request->get['filter_name'];
         }
         if (isset($this->request->get['filter_tag'])) {
             $url .= '&filter_tag=' . $this->request->get['filter_tag'];
         }
         if (isset($this->request->get['filter_description'])) {
             $url .= '&filter_description=' . $this->request->get['filter_description'];
         }
         if (isset($this->request->get['filter_category_id'])) {
             $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
         }
         $this->data['breadcrumbs'][] = array('text' => $product->getName(), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $this->request->get['product_id']), 'separator' => $this->language->get('text_separator'));
         if (!empty($description->getSeoTitle())) {
             $this->document->setTitle($description->getSeoTitle());
         } else {
             $this->document->setTitle($product->getName());
         }
         $this->document->setDescription($description->getMetaDescription());
         $this->document->setKeywords($description->getMetaKeyword());
         //$this->document->addLink($this->getUrl()->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
         $this->data['seo_h1'] = $description->getSeoH1();
         $this->data['heading_title'] = $product->getName();
         $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product->getMinimum());
         $this->getLoader()->model('catalog/review');
         $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']));
         $this->data['product_id'] = $product->getId();
         $this->data['manufacturer'] = $product->getManufacturer()->getName();
         $this->data['manufacturers'] = $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $product->getManufacturer()->getId());
         $this->data['model'] = $product->getModel();
         $this->data['reward'] = $product->getRewards();
         $this->data['points'] = $product->getPoints();
         if ($product->getQuantity() <= 0) {
             $this->data['stock'] = $product->getStockStatusId();
         } elseif ($this->getConfig()->get('config_stock_display')) {
             $this->data['stock'] = $product->getQuantity();
         } else {
             $this->data['stock'] = $this->language->get('text_instock');
         }
         if ($product->getImagePath()) {
             $this->data['popup'] = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_popup_width'), $this->getConfig()->get('config_image_popup_height'));
         } else {
             $this->data['popup'] = '';
         }
         $results = ProductDAO::getInstance()->getProductImages($this->request->get['product_id']);
         if ($results) {
             $this->data['thumb'] = ImageService::getInstance()->resize($results[0]->getImagePath(), $this->getConfig()->get('config_image_thumb_width'), $this->getConfig()->get('config_image_thumb_height'));
         } else {
             if ($product->getImagePath()) {
                 $this->data['thumb'] = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_thumb_width'), $this->getConfig()->get('config_image_thumb_height'));
             } else {
                 $this->data['thumb'] = '';
             }
         }
         $this->data['images'] = array();
         foreach ($results as $tag) {
             $this->data['images'][] = array('popup' => ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_popup_width'), $this->getConfig()->get('config_image_popup_height')), 'thumb' => ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_additional_width'), $this->getConfig()->get('config_image_additional_height')));
         }
         if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
             $this->data['price'] = $this->getCurrentCurrency()->format($product->getPrice());
         } else {
             $this->data['price'] = false;
         }
         if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
             $this->data['special'] = $this->getCurrentCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
         } else {
             $this->data['special'] = false;
         }
         //			if ($this->getConfig()->get('config_tax')) {
         //				$this->data['tax'] = $this->getCurrentCurrency()->format((float)$product_info->getSpecial'] ? $product_info['special'] : $product_info['price());
         //			} else {
         //				$this->data['tax'] = false;
         //			}
         $discounts = ProductDAO::getInstance()->getProductDiscounts($product->getId());
         $this->data['discounts'] = array();
         foreach ($discounts as $discount) {
             $this->data['discounts'][] = array('quantity' => $discount['quantity'], 'price' => $this->getCurrentCurrency()->format($discount['price']));
         }
         $this->data['options'] = array();
         foreach (ProductDAO::getInstance()->getProductOptions($this->request->get['product_id']) as $productOption) {
             if ($productOption->getOption()->isMultiValueType()) {
                 $option_value_data = array();
                 foreach ($productOption->getValue() as $option_value) {
                     if (is_null($option_value->getOptionValue())) {
                         continue;
                     }
                     if (!$option_value->getSubtract() || $option_value->getQuantity() > 0) {
                         $option_value_data[] = array('product_option_value_id' => $option_value->getId(), 'option_value_id' => $option_value->getOptionValue()->getId(), 'name' => $option_value->getOptionValue()->getName(), 'image' => ImageService::getInstance()->resize($option_value->getOptionValue()->getImage(), 50, 50), 'price' => (double) $option_value->getPrice() ? $this->getCurrentCurrency()->format($option_value->getPrice()) : false, 'price_prefix' => $option_value->getPrice() < 0 ? '-' : '+');
                     }
                 }
                 $this->data['options'][] = array('product_option_id' => $productOption->getId(), 'option_id' => $productOption->getOption()->getId(), 'name' => $productOption->getOption()->getName(), 'type' => $productOption->getType(), 'option_value' => $option_value_data, 'required' => $productOption->isRequired());
             } elseif ($productOption->getOption()->isSingleValueType()) {
                 $this->data['options'][] = array('product_option_id' => $productOption->getId(), 'option_id' => $productOption->getOption()->getId(), 'name' => $productOption->getOption()->getName(), 'type' => $productOption->getType(), 'option_value' => $productOption->getValue(), 'required' => $productOption->isRequired());
             }
         }
         if ($product->getMinimum()) {
             $this->data['minimum'] = $product->getMinimum();
         } else {
             $this->data['minimum'] = 1;
         }
         $date_added = getdate(strtotime($product->getDateAdded()));
         $date_added = mktime(0, 0, 0, $date_added['mon'], $date_added['mday'], $date_added['year']);
         $this->data['review_status'] = $this->getConfig()->get('config_review_status');
         $this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int) $product->getReviewsCount());
         $this->data['rating'] = (int) $product->getRating();
         $this->data['description'] = html_entity_decode($description->getDescription(), ENT_QUOTES, 'UTF-8');
         $this->data['image_description'] = html_entity_decode($product->getImageDescription(), ENT_QUOTES, 'UTF-8');
         $this->data['attribute_groups'] = $product->getAttributes();
         $this->data['hot'] = $date_added + 86400 * $this->getConfig()->get('config_product_hotness_age') > time();
         $this->data['weight'] = $this->weight->format($product->getWeight()->getWeight(), $product->getWeight()->getUnit()->getId());
         $this->data['products'] = array();
         #kabantejay synonymizer start
         if (!is_null($product->getManufacturer())) {
             $brand = '';
         } else {
             $brand = $product->getManufacturer();
         }
         if (!isset($razdel)) {
             $razdel = '';
         }
         if (!isset($category)) {
             $syncat = '';
         } else {
             $syncat = $category->getDescription()->getName();
         }
         if (!is_null($product->getModel())) {
             $synmod = '';
         } else {
             $synmod = $product->getModel();
         }
         if ($this->data['special'] == false) {
             $synprice = $this->data['price'];
         } else {
             $synprice = $this->data['special'];
         }
         $syntext = array(array("%H1%", $product->getName()), array("%BRAND%", $brand), array("%RAZDEL%", $razdel), array("%CATEGORY%", $syncat), array("%MODEL%", $synmod), array("%PRICE%", $synprice));
         for ($it = 0; $it < 6; $it++) {
             $this->data['description'] = str_replace($syntext[$it][0], $syntext[$it][1], $this->data['description']);
         }
         $this->data['description'] = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
             $ar = explode("|", $m[1]);
             return $ar[array_rand($ar, 1)];
         }, $this->data['description']);
         #kabantejay synonymizer end
         //			$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
         //        $results = $product_info->getRelated();
         foreach ($product->getRelated() as $tag) {
             if ($tag->getImagePath()) {
                 $image = ImageService::getInstance()->resize($tag->getImagePath(), $this->getConfig()->get('config_image_related_width'), $this->getConfig()->get('config_image_related_height'));
             } else {
                 $image = false;
             }
             if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
                 $price = $this->getCurrentCurrency()->format($tag->getPrice());
             } else {
                 $price = false;
             }
             if ((double) $tag->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
                 $special = $this->getCurrentCurrency()->format($tag->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
             } else {
                 $special = false;
             }
             if ($this->getConfig()->get('config_review_status')) {
                 $rating = (int) $tag->getRating();
             } else {
                 $rating = false;
             }
             $this->data['products'][] = array('product_id' => $tag->getId(), 'thumb' => $image, 'name' => $tag->getName(), 'price' => $price, 'special' => $special, 'rating' => $rating, 'reviews' => sprintf($this->language->get('text_reviews'), (int) $tag->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', 'product_id=' . $tag->getId()));
         }
         $this->data['tags'] = array();
         //			$results = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
         foreach ($product->getTags() as $tag) {
             $this->data['tags'][] = array('tag' => $tag, 'href' => $this->getUrl()->link('product/search', 'filter_tag=' . $tag));
         }
         ProductDAO::getInstance()->updateViewed($product->getId());
         $this->setBreadcrumbs();
         $this->children = array('common/header', 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer');
         $templateFile = '/template/product/product.tpl';
         $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default';
         $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
     } catch (InvalidArgumentException $exc) {
         $url = '';
         if (isset($this->request->get['path'])) {
             $url .= '&path=' . $this->request->get['path'];
         }
         if (isset($this->request->get['manufacturer_id'])) {
             $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
         }
         if (isset($this->request->get['filter_name'])) {
             $url .= '&filter_name=' . $this->request->get['filter_name'];
         }
         if (isset($this->request->get['filter_tag'])) {
             $url .= '&filter_tag=' . $this->request->get['filter_tag'];
         }
         if (isset($this->request->get['filter_description'])) {
             $url .= '&filter_description=' . $this->request->get['filter_description'];
         }
         if (isset($this->request->get['filter_category_id'])) {
             $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
         }
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_error'), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $productId), 'separator' => $this->language->get('text_separator'));
         $this->document->setTitle($this->language->get('text_error'));
         $this->data['heading_title'] = $this->language->get('text_error');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['continue'] = $this->getUrl()->link('common/home');
         $this->children = array('common/header', 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer');
         $this->getResponse()->setOutput($this->render($this->getConfig()->get('config_template') . '/template/error/not_found.tpl'));
     }
 }
Example #4
0
 public function product()
 {
     $manufacturer = ManufacturerDAO::getInstance()->getManufacturer($this->parameters['manufacturerId']);
     if ($manufacturer) {
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getSeoTitle())) {
             $this->document->setTitle($manufacturer->getDescription($this->getLanguage()->getId())->getSeoTitle());
         } else {
             $this->document->setTitle($manufacturer->getName());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getMetaDescription())) {
             $this->document->setDescription($manufacturer->getDescription($this->getLanguage()->getId())->getMetaDescription());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getMetaKeyword())) {
             $this->document->setKeywords($manufacturer->getDescription($this->getLanguage()->getId())->getMetaKeyword());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getSeoH1())) {
             $this->data['seo_h1'] = $manufacturer->getDescription($this->getLanguage()->getId())->getSeoH1();
         }
         $this->data = array_merge($this->data, $this->parameters);
         $this->data['heading_title'] = $manufacturer->getName();
         $this->data['compare'] = $this->getUrl()->link('product/compare');
         $url = '';
         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'];
         }
         #kabantejay synonymizer start
         $this->data['description'] = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
             $ar = explode("|", $m[1]);
             return $ar[array_rand($ar, 1)];
         }, html_entity_decode(!is_null($manufacturer->getDescription($this->getLanguage()->getId())) ? $manufacturer->getDescription($this->getLanguage()->getId())->getDescription() : "", ENT_QUOTES, 'UTF-8'));
         #kabantejay synonymizer end
         $this->data['products'] = array();
         $data = array('filterManufacturerId' => $this->parameters['manufacturerId'], 'sort' => $this->parameters['sort'], 'order' => $this->parameters['order'], 'start' => ($this->parameters['page'] - 1) * $this->parameters['limit'], 'limit' => $this->parameters['limit']);
         $product_total = ProductDAO::getInstance()->getProductsCount($data);
         $products = ProductDAO::getInstance()->getProducts($data, $this->parameters['sort'], $this->parameters['order'], ($this->parameters['page'] - 1) * $this->parameters['limit'], $this->parameters['limit']);
         foreach ($products as $product) {
             if ($product->getImagePath()) {
                 $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
             } else {
                 $image = false;
             }
             if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
                 //					$price = $this->currency->format($this->tax->calculate($product->getPrice(), $product->getTaxClassId(), $this->getConfig()->get('config_tax')));
                 $price = $this->getCurrentCurrency()->format($product->getPrice());
             } else {
                 $price = false;
             }
             if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
                 //					$special = $this->currency->format($this->tax->calculate($product->getSpecials(), $product->getTaxClassId(), $this->getConfig()->get('config_tax')));
                 $special = $this->getCurrentCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
             } else {
                 $special = false;
             }
             //				if ($this->getConfig()->get('config_tax')) {
             //					$tax = $this->currency->format((float)$product->getSpecial() ? $product->getSpecial() : $product->getPrice());
             //				} else {
             //					$tax = false;
             //				}
             //              #kabantejay synonymizer start
             if (is_null($product->getDescriptions())) {
                 $description = '';
             } else {
                 $description = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
                     $ar = explode("|", $m[1]);
                     return $ar[array_rand($ar, 1)];
                 }, $product->getDescriptions()->getDescription($this->getLanguage()->getId()));
             }
             //	   		#kabantejay synonymizer end
             $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => utf8_truncate(strip_tags(html_entity_decode($description, ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'special' => $special, 'rating' => $this->getConfig()->get('config_review_status') ? $product->getRating() : false, 'reviews' => sprintf($this->getLanguage()->get('text_reviews'), $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&manufacturer_id=' . $product->getManufacturer()->getId() . '&product_id=' . $product->getId()));
         }
         $url = '';
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->data['sorts'] = array();
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url));
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         $this->data['limits'] = array();
         $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
         $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=25'));
         $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=50'));
         $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=75'));
         $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=100'));
         $url = '';
         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->setBreadcrumbs([['text' => $this->getLanguage()->get('text_brand'), 'route' => $this->getUrl()->link('product/manufacturer')]]);
         $pagination = new Pagination();
         $pagination->total = $product_total;
         $pagination->page = $this->parameters['page'];
         $pagination->limit = $this->parameters['limit'];
         $pagination->text = $this->getLanguage()->get('text_pagination');
         $pagination->url = $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}');
         $this->data['pagination'] = $pagination->render();
         $this->data['continue'] = $this->getUrl()->link('common/home');
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $templateFile = '/template/product/manufacturerInfo.tpl.php';
         $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default';
         $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
     } else {
         $this->document->setTitle($this->getLanguage()->get('text_error'));
         $this->data['heading_title'] = $this->getLanguage()->get('text_error');
         $this->data['continue'] = $this->getUrl()->link('common/home');
         $this->setBreadcrumbs();
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $templateFile = '/template/error/not_found.tpl';
         $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default';
         $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
     }
 }
 /**
  * @return Weight
  */
 public function getWeight()
 {
     if (!isset($this->weight)) {
         $this->weight = ProductDAO::getInstance()->getWeight($this->id);
     }
     return $this->weight;
 }
Example #6
0
 public function setOption()
 {
     if ($this->getCache()->get('isSetOptionRunning')) {
         $this->getLogger()->write("Tried to run setOption() again");
         return;
     }
     $initialTime = ini_get('max_execution_time');
     ini_set('max_execution_time', 3600);
     session_write_close();
     $this->getCache()->set('isSetOptionRunning', true);
     $option = OptionDAO::getInstance()->getOptionById($this->parameters['optionId']);
     $this->loadFilter();
     $count = 0;
     foreach ($this->mpfilter["products"] as $product) {
         $this->getCache()->set('progress', "Step 2 of 2. Setting options for product " . $count++ . " of " . sizeof($this->mpfilter["products"]));
         if (in_array($product['product_id'], $this->mpfilter['change_ids']) || $this->mpfilter['change_all']) {
             $product = ProductDAO::getInstance()->getProduct($product['product_id'], true);
             $productOptions = $product->getOptions();
             if ($this->parameters['operation'] == 'AddOption') {
                 if (is_null($productOptions->getByOptionId($option->getId()))) {
                     $productOptions->attach(new ProductOption(null, $product, $option, null, false, null));
                 }
             } elseif ($this->parameters['operation'] == 'DelOption') {
                 $productOptions->detach($productOptions->getByOptionId($option->getId()));
             } elseif ($this->parameters['operation'] == 'AddValue') {
                 $productOption = $productOptions->getByOptionId($option->getId());
                 if (is_null($productOption)) {
                     $productOption = new ProductOption(null, $product, $option, null, false, null);
                     $productOptions->attach($productOption);
                 }
                 if ($productOption->getOption()->isSingleValueType()) {
                     $productOption->setValue($this->parameters['optionValue']);
                 } else {
                     // Option value type is multivalue
                     if (is_null($productOption->getValue()->getByOptionValueId($this->parameters['optionValue']))) {
                         $productOption->setValue(new ProductOptionValue(null, $productOption, new OptionValue($option, $this->parameters['optionValue']), 0, 0, $this->parameters['price'], 0, $this->parameters['weight'], null));
                     }
                 }
             } elseif ($this->parameters['operation'] == 'DelValue') {
                 $productOption = $productOptions->getByOptionId($option->getId());
                 if (!is_null($productOption)) {
                     if ($productOption->getOption()->isSingleValueType()) {
                         $productOption->deleteValue();
                     } elseif ($productOption->getOption()->isMultiValueType()) {
                         $productOption->deleteValue(new ProductOptionValue(null, $productOption, new OptionValue($option, $this->parameters['optionValue']), null, null, null, null, null, null));
                     } else {
                         throw new InvalidArgumentException("Not acceptable option value type '" . $this->parameters['optionValueType'] . "'");
                     }
                 }
             }
             ProductDAO::getInstance()->saveProduct($product);
         }
     }
     ini_set('max_execution_time', $initialTime);
     $this->getCache()->delete('isSetOptionRunning');
 }
Example #7
0
 private function getUserNames()
 {
     $data = [];
     foreach ($this->parameters as $key => $value) {
         if (strpos($key, 'filter') === false) {
             continue;
         }
         $data[$key] = $value;
     }
     unset($data['filterUserNameId']);
     $tmpResult = array();
     $userNames = ProductDAO::getInstance()->getProductUserNames($data);
     foreach ($userNames as $userName) {
         if (!in_array($userName['user_id'], $tmpResult)) {
             $tmpResult[$userName['user_id']] = $userName['user_name'];
         }
     }
     natcasesort($tmpResult);
     return $tmpResult;
 }
Example #8
0
 public function index()
 {
     $this->language->load('checkout/cart');
     // Remove
     if (isset($this->request->get['remove'])) {
         $this->getCart()->remove($this->request->get['remove']);
         $this->redirect($this->url->link('checkout/cart'));
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         if (isset($this->request->post['quantity'])) {
             if (!is_array($this->request->post['quantity'])) {
                 if (isset($this->request->post['option'])) {
                     $option = $this->request->post['option'];
                 } else {
                     $option = array();
                 }
                 $this->getCart()->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
             } else {
                 foreach ($this->request->post['quantity'] as $key => $value) {
                     $this->cart->update($key, $value);
                 }
             }
         }
         if (isset($this->request->post['remove'])) {
             foreach ($this->request->post['remove'] as $key) {
                 $this->cart->remove($key);
             }
         }
         if (isset($this->request->post['voucher']) && $this->request->post['voucher']) {
             foreach ($this->request->post['voucher'] as $key) {
                 if (isset($this->session->data['vouchers'][$key])) {
                     unset($this->session->data['vouchers'][$key]);
                 }
             }
         }
         if (isset($this->request->post['redirect'])) {
             $this->session->data['redirect'] = $this->request->post['redirect'];
         }
         if (isset($this->request->post['quantity']) || isset($this->request->post['remove']) || isset($this->request->post['voucher'])) {
             unset($this->session->data['shipping_methods']);
             unset($this->session->data['shipping_method']);
             unset($this->session->data['payment_methods']);
             unset($this->session->data['payment_method']);
             unset($this->session->data['reward']);
             $this->redirect($this->url->link('checkout/cart'));
         }
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('href' => $this->url->link('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('href' => $this->url->link('checkout/cart'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator'));
     if ($this->cart->hasProducts() || isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_select'] = $this->language->get('text_select');
         $this->data['text_weight'] = $this->language->get('text_weight');
         $this->data['column_remove'] = $this->language->get('column_remove');
         $this->data['column_image'] = $this->language->get('column_image');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['button_update'] = $this->language->get('button_update');
         $this->data['button_remove'] = $this->language->get('button_remove');
         $this->data['button_shopping'] = $this->language->get('button_shopping');
         $this->data['button_checkout'] = $this->language->get('button_checkout');
         $this->data['textBrand'] = $this->language->get('MANUFACTURER');
         $this->data['textCheckoutSelected'] = $this->language->get('CHECKOUT_SELECTED');
         if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
             $this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
         } else {
             $this->data['attention'] = '';
         }
         if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
             $this->data['error_warning'] = $this->language->get('error_stock');
         } elseif (isset($this->session->data['error'])) {
             $this->data['error_warning'] = $this->session->data['error'];
             unset($this->session->data['error']);
         } else {
             $this->data['error_warning'] = '';
         }
         if (isset($this->session->data['success'])) {
             $this->data['success'] = $this->session->data['success'];
             unset($this->session->data['success']);
         } else {
             $this->data['success'] = '';
         }
         if ($this->config->get('config_cart_weight')) {
             $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
         } else {
             $this->data['weight'] = false;
         }
         $this->load->model('tool/image');
         $this->data['products'] = array();
         $products = CartDAO::getInstance()->getProducts();
         uasort($products, function ($a, $b) {
             if ($a['supplierId'] < $b['supplierId']) {
                 return -1;
             } elseif ($a['supplierId'] > $b['supplierId']) {
                 return 1;
             } else {
                 return 0;
             }
         });
         $currentSupplierId = null;
         $currentSupplierOrderTotal = 0;
         foreach ($products as $product) {
             $product_total = 0;
             foreach ($products as $product_2) {
                 if ($product_2['product_id'] == $product['product_id']) {
                     $product_total += $product_2['quantity'];
                 }
             }
             if ($product['minimum'] > $product_total) {
                 $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
             }
             //print_r($product);
             //$this->load->model('shop/general');
             //$order_product = $this->model_shop_general->getOrderProduct($pro)
             /*if($product['image'] == '' || $product['image'] == "data/event/agent-moomidae.jpg") {
                 $options = $this->modelOrderItem->getOptions($product['order_product_id']);
                 $itemUrl = !empty($options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'])
                 ? $options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'] : '';
                 $product['image'] = !empty($itemUrl) ? $itemUrl : $product['image'];
               }*/
             $product_image = ProductDAO::getInstance()->getImage($product['product_id']);
             if ($product['image']) {
                 $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
             } else {
                 $image = $this->model_tool_image->resize($product_image, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
             }
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['option_value']));
                 } else {
                     $this->load->library('encryption');
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $file = substr($encryption->decrypt($option['option_value']), 0, strrpos($encryption->decrypt($option['option_value']), '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($file));
                 }
             }
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $price = false;
             }
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $total = $this->currency->format($this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $total = false;
             }
             $this->data['products'][] = array('actionDeleteUrl' => $this->url->link('checkout/cart/removeItem', 'key=' . urlencode($product['key']), 'SSL'), 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'stock' => $product['stock'], 'reward' => $product['reward'] ? sprintf($this->language->get('text_reward'), $product['reward']) : '', 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']), 'supplierId' => $product['supplierId']);
             /// Show local shipping cost
             if ($currentSupplierId != $product['supplierId']) {
                 if (!is_null($currentSupplierId)) {
                     $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal);
                 }
                 $currentSupplierId = $product['supplierId'];
                 $this->data['suppliers'][$currentSupplierId]['name'] = $product['brand'];
                 $this->data['suppliers'][$currentSupplierId]['shippingCost'] = $product['supplierShippingCost'];
                 $this->data['suppliers'][$currentSupplierId]['freeShippingThreshold'] = $product['supplierFreeShippingThreshold'];
                 $currentSupplierOrderTotal = $product['total'];
             } else {
                 $currentSupplierOrderTotal += $product['total'];
             }
         }
         /// Post-products last supplier check
         $this->checkLocalShipping($currentSupplierId, $currentSupplierOrderTotal);
         // Gift Voucher
         $this->data['vouchers'] = array();
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $key => $voucher) {
                 $this->data['vouchers'][] = array('key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']));
             }
         }
         $total_data = array();
         $total = 0;
         $taxes = $this->getCart()->getTaxes();
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $this->load->model('setting/extension');
             $sort_order = array();
             $results = \model\setting\ExtensionDAO::getInstance()->getExtensions('total');
             foreach ($results as $key => $value) {
                 $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
             }
             array_multisort($sort_order, SORT_ASC, $results);
             foreach ($results as $result) {
                 if ($this->config->get($result['code'] . '_status')) {
                     $this->load->model('total/' . $result['code']);
                     $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
                 }
             }
             $sort_order = array();
             foreach ($total_data as $key => $value) {
                 $sort_order[$key] = $value['sort_order'];
             }
             array_multisort($sort_order, SORT_ASC, $total_data);
         }
         $this->data['totals'] = $total_data;
         // Modules
         $this->data['modules'] = array();
         if (isset($results)) {
             foreach ($results as $result) {
                 if ($this->config->get($result['code'] . '_status') && file_exists(DIR_APPLICATION . 'controller/total/' . $result['code'] . '.php')) {
                     $this->data['modules'][] = $this->getChild('total/' . $result['code']);
                 }
             }
         }
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = $this->session->data['redirect'];
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->url->link('common/home');
         }
         $this->data['urlCheckout'] = $this->url->link('checkout/checkout', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl.php';
         } else {
             $this->template = 'default/template/checkout/cart.tpl.php';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_empty');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['continue'] = $this->url->link('common/home');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     }
 }
Example #9
0
 public function info()
 {
     if (isset($this->session->data['note'])) {
         $this->data['note'] = $this->session->data['note'];
         unset($this->session->data['note']);
     } else {
         $this->data['note'] = '';
     }
     $this->modelToolImage = $this->load->model('tool/image');
     if (isset($this->request->get['order_id'])) {
         $order_id = $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->language->load('account/order');
     $this->load->model('account/order');
     $order_info = $this->model_account_order->getOrder($order_id);
     if ($order_info) {
         $orderItems = OrderItemDAO::getInstance()->getOrderItems(array('filterOrderId' => $order_id), null, true);
         if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
             if ($this->request->post['action'] == 'reorder') {
                 foreach ($orderItems as $orderItem) {
                     if (in_array($orderItem->getId(), $this->request->post['selected'])) {
                         $option_data = array();
                         $order_options = $this->model_account_order->getOrderOptions($order_id, $orderItem->getId());
                         foreach ($order_options as $order_option) {
                             if ($order_option['type'] == 'select' || $order_option['type'] == 'radio') {
                                 $option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'checkbox') {
                                 $option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'input' || $order_option['type'] == 'textarea' || $order_option['type'] == 'file' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
                                 $option_data[$order_option['product_option_id']] = $order_option['value'];
                             }
                         }
                         $this->cart->add($orderItem->getProductId(), $orderItem->getQuantity(), $option_data);
                     }
                 }
                 $this->redirect($this->url->link('checkout/cart', '', 'SSL'));
             }
         }
         $this->setBreadcrumbs();
         $url = '';
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         $this->data['text_order_detail'] = $this->language->get('text_order_detail');
         $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
         $this->data['text_order_id'] = $this->language->get('text_order_id');
         $this->data['text_date_added'] = $this->language->get('text_date_added');
         $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
         $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
         $this->data['text_payment_method'] = $this->language->get('text_payment_method');
         $this->data['text_payment_address'] = $this->language->get('text_payment_address');
         $this->data['text_history'] = $this->language->get('text_history');
         $this->data['text_comment'] = $this->language->get('text_comment');
         $this->data['text_action'] = $this->language->get('text_action');
         $this->data['text_selected'] = $this->language->get('text_selected');
         $this->data['text_reorder'] = $this->language->get('text_reorder');
         $this->data['text_return'] = $this->language->get('text_return');
         $this->data['textAction'] = $this->language->get('ACTION');
         $this->data['textComment'] = $this->language->get('COMMENT');
         $this->data['textOrderItemId'] = $this->language->get('ORDER_ITEM_ID');
         $this->data['textOrderItemImage'] = $this->language->get('IMAGE');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['column_date_added'] = $this->language->get('column_date_added');
         $this->data['column_status'] = $this->language->get('column_status');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['button_invoice'] = $this->language->get('button_invoice');
         if (isset($this->error['warning'])) {
             $this->data['error_warning'] = $this->error['warning'];
         } else {
             $this->data['error_warning'] = '';
         }
         $this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'], 'SSL');
         if ($order_info['invoice_no']) {
             $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
         } else {
             $this->data['invoice_no'] = '';
         }
         $this->data['order_id'] = $this->request->get['order_id'];
         $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
         if ($order_info['shipping_address_format']) {
             $format = $order_info['shipping_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['shipping_method'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $order_info['shipping_method'])[0])->getName();
         if ($order_info['payment_address_format']) {
             $format = $order_info['payment_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['payment_method'] = $order_info['payment_method'];
         // ----- deposit modules START -----
         $this->data['text_payment_method'] = '';
         $this->load->model('account/multi_pay');
         $this->data['payment_method'] = $this->model_account_multi_pay->order_info($order_info);
         // ----- deposit modules END -----
         $this->data['products'] = array();
         //			$orderItems = OrderItemDAO::getInstance()->getOrderItems(
         //                array('filterOrderId' => $this->request->get['order_id']), null, true
         //            );
         //            $products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
         foreach ($orderItems as $orderItem) {
             $actions = array();
             if (($orderItem->getStatusId() & 0xffff) <= 2) {
                 $actions[] = array('text' => $this->language->get('CANCEL'), 'href' => $this->url->link('account/orderItems/cancel', 'orderItemId=' . $orderItem->getId() . '&returnUrl=' . urlencode($this->selfUrl)));
             }
             $option_data = array();
             $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
             foreach ($options as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
                 } else {
                     $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
                 }
             }
             $product_image = ProductDAO::getInstance()->getImage($orderItem->getProductId());
             if ($orderItem->getImagePath() == '' || $orderItem->getImagePath() == "data/event/agent-moomidae.jpg") {
                 $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
                 $itemUrl = !empty($options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value']) ? $options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'] : '';
                 $orderItem->setImagePath(!empty($itemUrl) ? $itemUrl : $orderItem->getImagePath());
             }
             if ($orderItem->getImagePath() && file_exists(DIR_IMAGE . $orderItem->getImagePath())) {
                 $image = $this->modelToolImage->resize($orderItem->getImagePath(), 100, 100);
             } else {
                 $image = $this->modelToolImage->resize($product_image, 100, 100);
             }
             $this->data['products'][] = array('order_product_id' => $orderItem->getId(), 'actions' => $actions, 'comment' => $orderItem->getPublicComment(), 'name' => $orderItem->getName(), 'model' => $orderItem->getModel(), 'option' => $option_data, 'quantity' => $orderItem->getModel(), 'price' => $this->getCurrency()->format($orderItem->getPrice(true), $order_info['currency_code'], 1), 'total' => $this->getCurrency()->format($orderItem->getTotal(true), $order_info['currency_code'], 1), 'imagePath' => $image, 'item_status' => Status::getStatus($orderItem->getStatusId(), $this->config->get('language_id'), true), 'selected' => false);
         }
         $this->data['totals'] = $this->model_account_order->getOrderTotals($this->request->get['order_id']);
         $this->data['comment'] = $order_info['comment'];
         $this->data['histories'] = array();
         $results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);
         foreach ($results as $result) {
             $this->data['histories'][] = array('date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => nl2br($result['comment']));
         }
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/account/order_info.tpl.php';
         } else {
             $this->template = 'default/template/account/order_info.tpl.php';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     } else {
         $this->document->setTitle($this->language->get('text_order'));
         $this->data['heading_title'] = $this->language->get('text_order');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->setBreadcrumbs();
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     }
 }
Example #10
0
 public function index()
 {
     //        $this->log->write(print_r($this->request, true));
     $this->getLanguage()->load('product/search');
     if (isset($this->request->get['filter_name'])) {
         $filter_name = $this->request->get['filter_name'];
     } else {
         $filter_name = '';
     }
     //
     //		if (isset($this->request->get['filter_description'])) {
     //			$filter_description = $this->request->get['filter_description'];
     //		} else {
     //			$filter_description = '';
     //		}
     if (isset($this->request->get['filter_category_id'])) {
         $filter_category_id = $this->request->get['filter_category_id'];
     } else {
         $filter_category_id = 0;
     }
     if (isset($this->request->get['filter_sub_category'])) {
         $filter_sub_category = $this->request->get['filter_sub_category'];
     } else {
         $filter_sub_category = '';
     }
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = null;
     }
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->getConfig()->get('config_catalog_limit');
     }
     if (isset($this->request->get['keyword'])) {
         $this->document->setTitle($this->getLanguage()->get('heading_title') . ' - ' . $this->request->get['keyword']);
     } else {
         $this->document->setTitle($this->getLanguage()->get('heading_title'));
     }
     $url = '';
     if (isset($this->request->get['filter_name'])) {
         $url .= '&filter_name=' . $this->request->get['filter_name'];
     }
     if (isset($this->request->get['filter_tag'])) {
         $url .= '&filter_tag=' . $this->request->get['filter_tag'];
     }
     if (isset($this->request->get['filter_description'])) {
         $url .= '&filter_description=' . $this->request->get['filter_description'];
     }
     if (isset($this->request->get['filter_category_id'])) {
         $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
     }
     if (isset($this->request->get['filter_sub_category'])) {
         $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category'];
     }
     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->data['text_compare'] = sprintf($this->getLanguage()->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
     $this->data['compare'] = $this->getUrl()->link('product/compare');
     // 3 Level Category Search
     $this->data['categories'] = array();
     $categories_1 = CategoryDAO::getInstance()->getCategoriesByParentId(0);
     foreach ($categories_1 as $category_1) {
         $level_2_data = array();
         $categories_2 = CategoryDAO::getInstance()->getCategoriesByParentId($category_1->getId());
         foreach ($categories_2 as $category_2) {
             $level_3_data = array();
             $categories_3 = CategoryDAO::getInstance()->getCategoriesByParentId($category_2->getId());
             foreach ($categories_3 as $category_3) {
                 $level_3_data[] = array('category_id' => $category_3->getId(), 'name' => $category_3->getDescription()->getName());
             }
             $level_2_data[] = array('category_id' => $category_2->getId(), 'name' => $category_2->getDescription()->getName(), 'children' => $level_3_data);
         }
         $this->data['categories'][] = array('category_id' => $category_1->getId(), 'name' => $category_1->getDescription()->getName(), 'children' => $level_2_data);
     }
     #kabantejay synonymizer start
     $result['description'] = null;
     /// Expression below makes no sense as it refers to non-initialized variable
     //        $result['description'] = preg_replace_callback(
     //            '/\{  (.*?)  \}/xs',
     //            function ($m) {
     //                $ar = explode("|", $m[1]);
     //                return $ar[array_rand($ar, 1)];
     //            },
     //            $result['description']
     //        );
     #kabantejay synonymizer end
     $this->data['products'] = array();
     if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) {
         $filter = new FilterTree(['filterEnabled' => true, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category], 'AND', new FilterTree(['filterName' => $filter_name], 'OR', new FilterTree(['filterModel' => $filter_name], 'OR', new FilterTree(['filterTag' => $filter_name]))), true);
         $data = array('filterEnabled' => true, 'filterName' => $filter_name, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
         $product_total = ProductDAO::getInstance()->getProductsCount($filter);
         $results = ProductDAO::getInstance()->getProducts($filter, $sort, $order, ($page - 1) * $limit, $limit);
         if ($sort == null) {
             $results = $this->sortByRelevance($results, $filter_name);
         }
         foreach ($results as $product) {
             if ($product->getImagePath()) {
                 $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
             } else {
                 $image = false;
             }
             if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
                 $price = $this->getCurrency()->format($product->getPrice());
             } else {
                 $price = false;
             }
             if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
                 $special = $this->getCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
             } else {
                 $special = false;
             }
             //
             //                if ($this->getConfig()->get('config_review_status')) {
             //					$rating = (int)$product->getRating();
             //				} else {
             //					$rating = false;
             //				}
             $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => !is_null($product->getDescriptions()->getDescription($this->getLanguage()->getId())) ? utf8_truncate(strip_tags(html_entity_decode($product->getDescriptions()->getDescription($this->getLanguage()->getId())->getDescription(), ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true) : '', 'price' => $price, 'special' => $special, 'rating' => $product->getRating(), 'reviews' => sprintf($this->getLanguage()->get('text_reviews'), (int) $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $product->getId()));
         }
         $url = '';
         if (isset($this->request->get['filter_name'])) {
             $url .= '&filter_name=' . $this->request->get['filter_name'];
         }
         if (isset($this->request->get['filter_tag'])) {
             $url .= '&filter_tag=' . $this->request->get['filter_tag'];
         }
         if (isset($this->request->get['filter_description'])) {
             $url .= '&filter_description=' . $this->request->get['filter_description'];
         }
         if (isset($this->request->get['filter_category_id'])) {
             $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
         }
         if (isset($this->request->get['filter_sub_category'])) {
             $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category'];
         }
         $this->data['sorts'] = array();
         //			$this->data['sorts'][] = array(
         //				'text'  => $this->getLanguage()->get('text_default'),
         //				'value' => 'p.sort_order-ASC',
         //				'href'  => $this->getUrl()->link('product/search', 'sort=p.sort_order&order=ASC' . $url)
         //			);
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('RELEVANCE'), 'value' => null, 'href' => $this->getUrl()->link('product/search', '' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=DESC' . $url));
         $this->data['limits'] = array();
         $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/search', $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
         $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/search', $url . '&limit=25'));
         $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/search', $url . '&limit=50'));
         $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/search', $url . '&limit=75'));
         $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/search', $url . '&limit=100'));
         $pagination = new Pagination();
         $pagination->total = $product_total;
         $pagination->page = $page;
         $pagination->limit = $limit;
         $pagination->text = $this->getLanguage()->get('text_pagination');
         $pagination->url = $this->getUrl()->link('product/search', $url . '&page={page}');
         $this->data['pagination'] = $pagination->render();
     }
     $this->data['filter_name'] = $filter_name;
     //		$this->data['filter_description'] = $filter_description;
     $this->data['filter_category_id'] = $filter_category_id;
     $this->data['filter_sub_category'] = $filter_sub_category;
     $this->data['sort'] = $sort;
     $this->data['order'] = $order;
     $this->data['limit'] = $limit;
     $this->setBreadcrumbs();
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $templateFile = '/template/product/search.tpl.php';
     $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : ($templateDir = 'default');
     $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
 }
Example #11
0
 protected function index($setting)
 {
     $this->data['button_cart'] = $this->language->get('button_cart');
     $this->data['isSaler'] = $this->customer->getCustomerGroupId() == 6;
     $this->data['products'] = array();
     if (isset($_REQUEST['latest_page'])) {
         $page = $_REQUEST['latest_page'];
     } else {
         $page = 1;
     }
     $data = array('sort' => 'p.date_added', 'order' => 'DESC', 'start' => ($page - 1) * $setting['limit'], 'limit' => $setting['limit'], 'filter_category_id' => $setting['category_ids'], 'nocache' => 1);
     if (isset($this->request->get['route']) and $this->request->get['route'] == 'product/category') {
         $category_id = $this->_endc(explode('_', (string) $this->request->get['path']));
         $data['filter_category_id'] = $category_id;
         $data['filter_sub_category'] = TRUE;
     }
     if (isset($this->request->get['route']) and isset($this->request->get['manufacturer_id']) and $this->request->get['route'] == 'product/manufacturer/product') {
         $manufacturer_id = $this->request->get['manufacturer_id'];
         $data['filter_manufacturer_id'] = $manufacturer_id;
     }
     $results = \model\catalog\ProductDAO::getInstance()->getProducts($data, $data['sort'], $data['order'], $data['start'], $data['limit'], true);
     //$this->getLogger()->write(print_r($data, true));
     foreach ($results as $result) {
         if ($result->getImagePath()) {
             $image = \system\helper\ImageService::getInstance()->resize($result->getImagePath(), $setting['image_width'], $setting['image_height']);
         } else {
             $image = false;
         }
         if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
             $price = $this->getCurrency()->format($this->tax->calculate($result->getPrice(), 0, $this->getConfig()->get('config_tax')));
         } else {
             $price = false;
         }
         $specials = $result->getSpecials(true);
         if (!empty($specials)) {
             $special = $this->getCurrency()->format($specials[0]['price']);
         } else {
             $special = false;
         }
         if ($this->getConfig()->get('config_review_status')) {
             $rating = \model\catalog\ProductDAO::getInstance()->getProductRating($result->getId());
         } else {
             $rating = false;
         }
         $date_added = getdate(strtotime($result->getDateAdded()));
         $date_added = mktime(0, 0, 0, $date_added['mon'], $date_added['mday'], $date_added['year']);
         #kabantejay synonymizer start
         //			$result['description'] = preg_replace_callback('/\{  (.*?)  \}/xs', function ($m) {$ar = explode("|", $m[1]);return $ar[array_rand($ar, 1)];}, $result['description']);
         #kabantejay synonymizer end
         $this->data['products'][] = array('product_id' => $result->getId(), 'thumb' => $image, 'name' => $result->getName(), 'price' => $price, 'special' => $special, 'rating' => $rating, 'reviews' => sprintf($this->language->get('text_reviews'), $result->getReviewsCount()), 'href' => $this->url->link('product/product', 'product_id=' . $result->getId()), 'hot' => $date_added + 86400 * $this->getConfig()->get('config_product_hotness_age') > time());
     }
     $listCategoryId = array();
     $strCategories = explode(",", $data['filter_category_id']);
     for ($i = 0; $i < count($strCategories); $i++) {
         $strCategoryId = $strCategories[$i];
         array_push($listCategoryId, $strCategoryId);
     }
     $this->data['listCategories'] = array();
     foreach ($listCategoryId as $cat) {
         $category_info = $this->model_catalog_category->getCategory($cat);
         if ($category_info) {
             $this->data['listCategories'][] = array('text' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $category_info['category_id']));
         }
     }
     if (file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . '/template/module/latest.tpl.php')) {
         $this->template = $this->getConfig()->get('config_template') . '/template/module/latest.tpl.php';
     } else {
         $this->template = 'default/template/module/latest.tpl.php';
     }
     $pagination = new Pagination();
     $pagination->total = $this->model_catalog_product->getTotalProducts($data);
     $pagination->page = $page;
     $pagination->limit = $this->setting['limit'];
     $pagination->text = $this->language->get('text_pagination');
     $pagination->url = $this->modifyUrl("latest_page", "{page}");
     //$pagination->url = $this->url->link('sale/order_items', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
     $this->data['pagination'] = $pagination->render();
     $this->render();
 }
Example #12
0
 public function index()
 {
     $this->language->load('product/special');
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = 'p.sort_order';
     }
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->getConfig()->get('config_catalog_limit');
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $url = '';
     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->data['heading_title'] = $this->language->get('heading_title');
     $this->data['compare'] = $this->getUrl()->link('product/compare');
     $this->data['products'] = array();
     $data = array('sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
     $customerGroupId = $this->getCurrentCustomer()->isLogged() ? $this->getCurrentCustomer()->getCustomerGroupId() : $this->getConfig()->get('config_customer_group_id');
     $product_total = ProductDAO::getInstance()->getProductsCount($data);
     $products = ProductDAO::getInstance()->getDiscountedProductsByCustomerGroupId($customerGroupId, $sort, $order, ($page - 1) * $limit, $limit);
     foreach ($products as $product) {
         #kabantejay synonymizer start
         if (is_null($product->getDescriptions()) || is_null($product->getDescriptions()->getDescription($this->getLanguage()->getId()))) {
             $productDescription = '';
         } else {
             $productDescription = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
                 $ar = explode("|", $m[1]);
                 return $ar[array_rand($ar, 1)];
             }, $product->getDescriptions()->getDescription($this->getLanguage()->getId())->getDescription());
         }
         #kabantejay synonymizer end
         if ($product->getImagePath()) {
             $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
         } else {
             $image = false;
         }
         if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
             $price = $this->getCurrency()->format($product->getPrice());
         } else {
             $price = false;
         }
         if ((double) $product->getSpecialPrice($customerGroupId)) {
             $special = $this->getCurrency()->format($product->getSpecialPrice($customerGroupId));
         } else {
             $special = false;
         }
         if ($this->getConfig()->get('config_tax')) {
             $tax = $this->getCurrency()->format((double) $product->getSpecialPrice($customerGroupId) ? $product->getSpecialPrice($customerGroupId) : $product->getPrice());
         } else {
             $tax = false;
         }
         $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => utf8_truncate(strip_tags(html_entity_decode($productDescription, ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'special' => $special, 'tax' => $tax, 'rating' => $product->getRating(), 'reviews' => sprintf($this->language->get('text_reviews'), (int) $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $product->getId()));
     }
     $url = '';
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['sorts'] = array();
     $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=p.sort_order&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=pd.name&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=pd.name&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_asc'), 'value' => 'ps.price-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=ps.price&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_desc'), 'value' => 'special-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=special&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=rating&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=rating&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=p.model&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=p.model&order=DESC' . $url));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     $this->data['limits'] = array();
     $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/special', $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
     $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/special', $url . '&limit=25'));
     $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/special', $url . '&limit=50'));
     $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/special', $url . '&limit=75'));
     $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/special', $url . '&limit=100'));
     $url = '';
     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'];
     }
     $pagination = new Pagination();
     $pagination->total = $product_total;
     $pagination->page = $page;
     $pagination->limit = $limit;
     $pagination->text = $this->language->get('text_pagination');
     $pagination->url = $this->getUrl()->link('product/special', $url . '&page={page}');
     $this->data['pagination'] = $pagination->render();
     $this->data['sort'] = $sort;
     $this->data['order'] = $order;
     $this->data['limit'] = $limit;
     $this->setBreadcrumbs();
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $this->getResponse()->setOutput($this->render($this->getConfig()->get('config_template') . '/template/product/special.tpl'));
 }