Пример #1
0
 public function hookproductratingHook($params)
 {
     $product = $params['productid'];
     include_once _PS_MODULE_DIR_ . 'productcomments/ProductComment.php';
     if (!isset($product)) {
         return;
     }
     $grade = ProductComment::getAverageGrade($product);
     $this->context->smarty->assign(array('empty_grade' => 1));
     if (isset($grade['grade'])) {
         $this->context->smarty->assign(array('empty_grade' => 0));
     }
     $this->context->smarty->assign(array('average_total' => round($grade['grade']), 'nbComments' => (int) ProductComment::getCommentNumber((int) $product)));
     $this->context->smarty->assign((int) ProductComment::getCommentNumber((int) $product));
     return $this->display(__FILE__, 'ratingsproductlist.tpl');
 }
Пример #2
0
 public function postProcess()
 {
     global $currentIndex, $cookie, $smarty;
     if (Tools::getValue('approve')) {
         $id_comment = Tools::getValue('reviewID');
         $comment = new ProductComment((int) $id_comment);
         $comment->validate = 1;
         $comment->update();
         $product = new Product($comment->id_product, true, (int) $cookie->id_lang);
         $customer = new Customer($comment->id_customer);
         //send mail notifications
         Mail::Send((int) $cookie->id_lang, 'review_approved', Mail::l('Your product review for ' . $product->name), array('{product_name}' => $product->name, '{firstname}' => $customer->firstname, '{product_url}' => $product->getLink()), $customer->email, $customer->firstname . ' ' . $customer->lastname);
         //queue reward rule exec
         if (!product_review_approved::rewardExistsForReference($comment->id_customer, EVENT_REVIEW_APPROVED, 3, $comment->id_product)) {
             Tools::sendSQSRuleMessage(EVENT_REVIEW_APPROVED, $comment->id_product, $comment->id_customer, date('Y-m-d H:i:s'));
         }
     }
     if (Tools::getValue('disapprove')) {
         $id_comment = Tools::getValue('reviewID');
         $comment = new ProductComment((int) $id_comment);
         $comment->deleted = 1;
         $comment->update();
         $product = new Product($comment->id_product, true, (int) $cookie->id_lang);
         $customer = new Customer($comment->id_customer);
         //send mail notifications
         Mail::Send((int) $cookie->id_lang, 'review-reject', Mail::l('Your product review for ' . $product->name), array('{product_name}' => $product->name, '{firstname}' => $customer->firstname, '{product_url}' => $product->getLink()), $customer->email, $customer->firstname . ' ' . $customer->lastname);
     }
     if (Tools::getValue('restore')) {
         $id_comment = Tools::getValue('reviewID');
         $comment = new ProductComment((int) $id_comment);
         $comment->deleted = 0;
         $comment->update();
     }
     if (Tools::getValue('editReview')) {
         $id_comment = Tools::getValue('reviewID');
         $reviewContent = Tools::getValue('reviewContent');
         $reviewTitle = Tools::getValue('reviewTitle');
         $comment = new ProductComment((int) $id_comment);
         $comment->content = $reviewContent;
         $comment->title = $reviewTitle;
         $comment->validate = Tools::getValue('approveReview') ? 1 : 0;
         $product = new Product($comment->id_product, true, (int) $cookie->id_lang);
         $customer = new Customer($comment->id_customer);
         if ($comment->validate) {
             //queue reward rule exec
             if (!product_review_approved::rewardExistsForReference($comment->id_customer, EVENT_REVIEW_APPROVED, 3, $comment->id_product)) {
                 Tools::sendSQSRuleMessage(EVENT_REVIEW_APPROVED, $comment->id_product, $comment->id_customer, date('Y-m-d H:i:s'));
             }
             //send mail notifications
             Mail::Send((int) $cookie->id_lang, 'review_approved', Mail::l('Your product review for ' . $product->name), array('{product_name}' => $product->name, '{firstname}' => $customer->firstname, '{product_url}' => $product->getLink()), $customer->email, $customer->firstname . ' ' . $customer->lastname);
         }
         $comment->update();
     }
     if (Tools::getValue('view')) {
         $id_comment = Tools::getValue('reviewID');
         $comment = new ProductComment((int) $id_comment);
         $smarty->assign('review', $comment);
     }
     $p = (int) Tools::getValue('p', 1);
     $n = Tools::getValue('n', 20);
     $totalReviews = ProductComment::getTotalComments();
     $pages = $totalReviews / $n;
     if ($totalReviews > $n) {
         $smarty->assign('pages', $pages);
     }
     $comments = ProductComment::getComments($p, $n);
     $smarty->assign('reviews', $comments);
     $smarty->assign('currentIndex', $currentIndex);
     $smarty->assign('token', $this->token);
     $smarty->assign('customerToken', Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee));
 }
 /**
  * Action: Show page post action
  * @return Response
  */
 public function postAction($slug)
 {
     $postComment = e(Input::get('postComment'));
     if ($postComment) {
         // Get comment
         $content = e(Input::get('content'));
         // Check word
         if (mb_strlen($content) < 3) {
             return Redirect::back()->withInput()->withErrors($this->messages->add('content', '评论不得少于3个字符。'));
         }
         // Find article
         $product = $this->model->where('slug', $slug)->first();
         // Create comment
         $comment = new ProductComment();
         $comment->content = $content;
         $comment->product_id = $product->id;
         $comment->user_id = Auth::user()->id;
         if ($comment->save()) {
             // Create success
             // Updated comments
             $product->comments_count = $product->comments->count();
             $product->save();
             // Return success
             return Redirect::back()->with('success', '评论成功。');
         } else {
             // Create fail
             return Redirect::back()->withInput()->with('error', '评论失败。');
         }
     } else {
         $data = Input::all();
         $rules = array('quantity' => 'required|integer', 'product_id' => 'required', 'price' => 'required', 'seller_id' => 'required', 'inventory' => 'required');
         if (e($data['inventory']) < e($data['quantity'])) {
             return Redirect::back()->with('error', '<strong>请输入正确的' . $this->resourceName . '购买数量</strong>');
         } elseif (Auth::user()->id == e($data['seller_id'])) {
             return Redirect::back()->with('error', '<strong>您不能购买自己出售的商品</strong>');
         } else {
             // Custom validation message
             $messages = $this->validatorMessages;
             // Begin verification
             $validator = Validator::make($data, $rules, $messages);
             if ($validator->passes()) {
                 // Verification success
                 // Add recource
                 $model = new ShoppingCart();
                 $model->buyer_id = Auth::user()->id;
                 $model->quantity = e($data['quantity']);
                 $model->product_id = e($data['product_id']);
                 $model->price = e($data['price']);
                 $model->payment = e($data['quantity']) * e($data['price']);
                 $model->seller_id = e($data['seller_id']);
                 if ($model->save()) {
                     // Add success
                     return Redirect::back()->with('success', '<strong>' . $this->resourceName . '已添加到购物车:</strong>您可以继续选购' . $this->resourceName . ',或立即结算。');
                 } else {
                     // Add fail
                     return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '添加到购物车失败。</strong>');
                 }
             } else {
                 // Verification fail
                 return Redirect::back()->withInput()->withErrors($validator);
             }
         }
     }
 }
Пример #4
0
 /**
  * Delete a comment, grade and report data
  *
  * @return boolean succeed
  */
 public function delete()
 {
     parent::delete();
     ProductComment::deleteGrades($this->id);
     ProductComment::deleteReports($this->id);
     ProductComment::deleteUsefulness($this->id);
 }
Пример #5
0
 protected function ajaxProcessCommentIsUsefull()
 {
     if (!Tools::isSubmit('id_product_comment') || !Tools::isSubmit('value')) {
         die('0');
     }
     if (ProductComment::isAlreadyUsefulness(Tools::getValue('id_product_comment'), $this->context->cookie->id_customer)) {
         die('0');
     }
     if (ProductComment::setCommentUsefulness((int) Tools::getValue('id_product_comment'), (bool) Tools::getValue('value'), $this->context->cookie->id_customer)) {
         die('1');
     }
     die('0');
 }
Пример #6
0
        $productComment = new ProductComment($app);
        echo $productComment->getUserCommentList($ConsumerId);
    });
    #
    # 查询商品评论—详细信息
    #
    # GET	https://<endpoint>/ProductComment/[CommentId]
    #
    $app->get('/:CommentId', function ($CommentId) use($app) {
        $productComment = new ProductComment($app);
        echo $productComment->getCommentId($CommentId);
    });
    #
    # 删除商品评论
    #
    # DELETE	https://<endpoint>/ProductComment/[CommendId]
    #
    $app->delete('/:CommentId', function ($CommentId) use($app) {
        $productComment = new ProductComment($app);
        echo $productComment->delete($CommentId);
    });
    #
    # 查询用户商品评论—总数
    #
    # GET	https://<endpoint>/ProductComment/[ConsumerId]/Count/
    #
    $app->get('/:ConsumerId/Count/', function ($ConsumerId) use($app) {
        $productComment = new ProductComment($app);
        echo $productComment->getConsumerCommentCount($ConsumerId);
    });
});
Пример #7
0
 public function actionDeleteComment($id)
 {
     if (Yii::app()->request->isPostRequest) {
         $productCommentModel = ProductComment::model()->findByPk($id);
         $productModel = Product::model()->findByAttributes(array('product_id' => $productCommentModel->product_id));
         $productModel->product_mark_sum = $productModel->product_mark * $productModel->product_marked_times - $productCommentModel->amazing_level;
         --$productModel->product_marked_times;
         $productModel->product_mark = $productModel->product_marked_times === 0 ? 5 : $productModel->product_mark_sum / $productModel->product_marked_times;
         $productModel->save();
         $productCommentModel->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Пример #8
0
 public function displayTop()
 {
     //if (!$this->isCached('blocktopmenu2.tpl', $this->getCacheId()))
     //{
     $this->user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $categoryMain = current(Category::getNestedCategories(146, $this->context->language->id, true, $this->user_groups));
     //$this->loadCategories(146);
     //            $categoryComplects = new Category(129, $this->context->language->id);
     //            $categoryWholesale = new Category(148, $this->context->language->id);
     //            $cmsopt = new CMS(11, $this->context->language->id);
     $categoryComplects = current(Category::getNestedCategories(129, $this->context->language->id, true, $this->user_groups));
     $categoryComplectsDecor = current(Category::getNestedCategories(198, $this->context->language->id, true, $this->user_groups));
     $categoryFurniture = current(Category::getNestedCategories(7, $this->context->language->id, true, $this->user_groups));
     //$this->loadCategories(7);
     $shop_id = (int) $this->context->shop->id;
     $shop_group_id = Shop::getGroupFromShop($shop_id);
     $item_day_id = Db::getInstance()->getValue("SELECT id_product FROM " . _DB_PREFIX_ . "product WHERE item_for_day=1  AND active=1 ORDER BY RAND()");
     if ($item_day_id) {
         require_once dirname(dirname(__FILE__)) . '/productcomments/ProductComment.php';
         $prodict_day = new Product($item_day_id, true, $this->context->language->id, $this->context->shop->id);
         $average = ProductComment::getAverageGrade($prodict_day->id);
         $cover = Product::getCover((int) $prodict_day->id, $this->context);
         $this->context->smarty->assign(array('priceDisplayPrecisionDay' => _PS_PRICE_DISPLAY_PRECISION_, 'have_image_day' => isset($cover['id_image']) && (int) $cover['id_image'] ? true : false, 'cover_day' => $cover, 'categoryComplects' => $categoryComplects, 'categoryComplectsDecor' => $categoryComplectsDecor, 'averageTotalDay' => round($average['grade']), 'ratingsDay' => ProductComment::getRatings((int) $prodict_day->id), 'nbCommentsDay' => (int) ProductComment::getCommentNumber((int) $prodict_day->id)));
     } else {
         $prodict_day = null;
     }
     $this->context->smarty->assign(array('prodict_day' => $prodict_day, 'prodict_day_url' => is_object($prodict_day) ? $this->context->link->getProductLink($prodict_day) : null, 'search' => Configuration::get('MOD_blocktopmenu2_SEARCH', null, $shop_group_id, $shop_id), 'categoryMain' => $categoryMain, 'categoryComplects' => $categoryComplects, 'categoryComplectsDecor' => $categoryComplectsDecor, 'categoryWholesale' => new Category(148, $this->context->language->id), 'cmsopt' => new CMS(11, $this->context->language->id), 'categoryFurniture' => $categoryFurniture));
     // echo '<pre>'; var_dump($this->context->smarty->getTemplateVars('categoryMain')); echo '</pre>'; die();
     //}
     return $this->display(__FILE__, 'blocktopmenu2.tpl', $this->getCacheId());
 }
Пример #9
0
 public function hookExtraProductComparison($params)
 {
     global $smarty, $cookie;
     $list_grades = array();
     $list_product_grades = array();
     $list_product_average = array();
     $list_product_comment = array();
     foreach ($params['list_ids_product'] as $id_product) {
         $grades = ProductComment::getAveragesByProduct((int) $id_product, (int) $cookie->id_lang);
         $criterions = ProductCommentCriterion::getByProduct((int) $id_product, (int) $cookie->id_lang);
         $grade_total = 0;
         if (sizeof($grades) > 0) {
             foreach ($criterions as $criterion) {
                 $list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
                 $grade_total += (double) $grades[$criterion['id_product_comment_criterion']];
                 if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades)) {
                     $list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
                 }
             }
             $list_product_average[$id_product] = $grade_total / sizeof($criterion);
             $list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
         }
     }
     if (sizeof($list_grades) < 1) {
         return false;
     }
     $smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'], 'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment));
     return $this->display(__FILE__, '/products-comparison.tpl');
 }
Пример #10
0
 public function hookProductTabContent($params)
 {
     global $smarty, $cookie, $nbProducts;
     $commentNumber = intval(ProductComment::getCommentNumber(intval(Tools::getValue('id_product'))));
     $averages = ProductComment::getAveragesByProduct(intval(Tools::getValue('id_product')), intval($cookie->id_lang));
     $customerComment = ProductComment::getByCustomer(intval(Tools::getValue('id_product')), intval($cookie->id_customer), true);
     $averageTotal = 0;
     foreach ($averages as $average) {
         $averageTotal += floatval($average);
     }
     $averageTotal = count($averages) ? $averageTotal / count($averages) : 0;
     $smarty->assign(array('logged' => intval($cookie->id_customer), 'action_url' => Tools::safeOutput($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING'], 'comments' => ProductComment::getByProduct(intval(Tools::getValue('id_product'))), 'criterions' => ProductCommentCriterion::getByProduct(intval(Tools::getValue('id_product')), intval($cookie->id_lang)), 'averages' => $averages, 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal, 'too_early' => $customerComment and strtotime($customerComment['date_add']) + self::DELAY * 3600 > time(), 'delay' => self::DELAY));
     $nbProducts = $commentNumber;
     require_once dirname(__FILE__) . '/../../pagination.php';
     return $this->display(__FILE__, '/productcomments.tpl');
 }
Пример #11
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ProductComment::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #12
0
 public function DataForFrontSearch($date_from, $date_to, $id_hotel, $id_product = 0, $for_room_type = 0, $adult = 0, $children = 0, $ratting = -1, $amenities = 0, $price = 0, $id_cart = 0, $id_guest = 0)
 {
     require_once _PS_MODULE_DIR_ . 'productcomments/ProductComment.php';
     $this->context = Context::getContext();
     $booking_data = $this->getBookingData($date_from, $date_to, $id_hotel, $id_product, $adult, $children, 0, 0, 1, 0, 0, 0, $id_cart, $id_guest);
     // ddd($booking_data);
     if (!$for_room_type) {
         if (!empty($booking_data)) {
             $obj_rm_type = new HotelRoomType();
             foreach ($booking_data['rm_data'] as $key => $value) {
                 if (empty($value['data']['available'])) {
                     unset($booking_data['rm_data'][$key]);
                 } else {
                     $prod_ratting = ProductComment::getAverageGrade($value['id_product'])['grade'];
                     if ($prod_ratting === NULL) {
                         $prod_ratting = 0;
                     }
                     if ($prod_ratting < $ratting && $ratting != -1) {
                         unset($booking_data['rm_data'][$key]);
                     } else {
                         $product = new Product($value['id_product'], false, $this->context->language->id);
                         $product_feature = $product->getFrontFeaturesStatic($this->context->language->id, $value['id_product']);
                         $prod_amen = array();
                         if (!empty($amenities) && $amenities) {
                             $prod_amen = $amenities;
                             foreach ($product_feature as $a_key => $a_val) {
                                 if (($pa_key = array_search($a_val['id_feature'], $prod_amen)) !== false) {
                                     unset($prod_amen[$pa_key]);
                                     if (empty($prod_amen)) {
                                         break;
                                     }
                                 }
                             }
                             if (!empty($prod_amen)) {
                                 unset($booking_data['rm_data'][$key]);
                             }
                         }
                         if (empty($prod_amen)) {
                             $prod_price = Product::getPriceStatic($value['id_product']);
                             if (empty($price) || $price['from'] <= $prod_price && $price['to'] >= $prod_price) {
                                 $cover_image_arr = $product->getCover($value['id_product']);
                                 if (!empty($cover_image_arr)) {
                                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'home_default');
                                 } else {
                                     $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'home_default');
                                 }
                                 $room_left = count($booking_data['rm_data'][$key]['data']['available']);
                                 $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($value['id_product']);
                                 $booking_data['rm_data'][$key]['name'] = $product->name;
                                 $booking_data['rm_data'][$key]['image'] = $cover_img;
                                 $booking_data['rm_data'][$key]['description'] = $product->description_short;
                                 $booking_data['rm_data'][$key]['feature'] = $product_feature;
                                 $booking_data['rm_data'][$key]['price'] = $prod_price;
                                 if ($room_left <= (int) Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER')) {
                                     $booking_data['rm_data'][$key]['room_left'] = $room_left;
                                 }
                                 $booking_data['rm_data'][$key]['adult'] = $rm_dtl['adult'];
                                 $booking_data['rm_data'][$key]['children'] = $rm_dtl['children'];
                                 $booking_data['rm_data'][$key]['ratting'] = $prod_ratting;
                                 $booking_data['rm_data'][$key]['num_review'] = ProductComment::getCommentNumber($value['id_product']);
                                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                                     $booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product) . '?date_from=' . $date_from . '&date_to=' . $date_to;
                                 } else {
                                     $booking_data['rm_data'][$key]['product_link'] = $this->context->link->getProductLink($product) . '&date_from=' . $date_from . '&date_to=' . $date_to;
                                 }
                             } else {
                                 unset($booking_data['rm_data'][$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $booking_data;
 }
Пример #13
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $flag_pack = true;
     if (!$this->errors) {
         //                        if(!isset($_GET['quick_view']))
         //                            if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id))
         //                        if (Pack::isPack((int)$this->product->id))
         //                            $this->product->quantity = 0;
         //                        else
         //                            $flag_pack = false;
         //                        else
         //                            $flag_pack = false;
         if (!Pack::isPack((int) $this->product->id)) {
             $flag_pack = false;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } else {
             if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
             }
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         $this->assign3dImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         if (is_array($pack_items) && count($pack_items)) {
             foreach ($pack_items as &$pack_item) {
                 $pack_item['features'] = Product::getFrontFeaturesStatic($this->context->language->id, $pack_item['id_product']);
             }
         }
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         //reviews
         //                        $average = ProductComment::getAverageGrade((int)Tools::getValue('id_product'));
         $nbComments = (int) ProductComment::getCommentNumber((int) Tools::getValue('id_product'));
         $act_pack = 0;
         //паки
         if (!$flag_pack) {
             $sql = "SELECT DISTINCT(id_product_pack) FROM " . _DB_PREFIX_ . "pack WHERE id_product_item={$this->product->id}";
             $pack_products = array();
             $result_packs = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
             if (is_array($result_packs) && count($result_packs)) {
                 foreach ($result_packs as $k => $id_product_pack) {
                     $prod = new Product($id_product_pack['id_product_pack'], $this->context->language->id, true);
                     $cover = $prod->getCover((int) $prod->id);
                     if ($cover) {
                         $pack_products[$k]['id_image'] = $cover['id_image'];
                     } else {
                         $pack_products[$k]['id_image'] = null;
                     }
                     $price = $prod->getPrice(true, null, 2);
                     $price_old = $prod->getPriceWithoutReduct(false, null, 2);
                     if (isset($prod->specificPrice) && is_array($prod->specificPrice)) {
                         $pack_products[$k]['sale_percentage'] = $prod->specificPrice['reduction_type'] == 'percentage' ? $prod->specificPrice['reduction'] * 100 : $prod->specificPrice['reduction'] / $price_old * 100;
                     }
                     $pack_products[$k]['active'] = $prod->active;
                     if ($prod->active) {
                         $act_pack = 1;
                     }
                     $pack_products[$k]['count_reviews'] = (int) ProductComment::getCommentNumber((int) $prod->id);
                     $pack_products[$k]['star_reviews'] = ProductComment::getRatings((int) $prod->id);
                     $pack_products[$k]['price'] = $price;
                     $pack_products[$k]['price_old'] = $price_old;
                     $pack_products[$k]['on_sale'] = (bool) ($price != $price_old);
                     $pack_products[$k]['id_product_pack'] = $prod->id;
                     $pack_products[$k]['link'] = $this->context->link->getProductLink($prod);
                     $pack_products[$k]['name'] = $prod->name;
                     $pack_products[$k]['link_rewrite'] = $prod->link_rewrite;
                     $pack_products[$k]['items'] = Pack::getItemTable($prod->id, $this->context->language->id, true);
                     unset($prod);
                 }
             }
         } else {
             $pack_products = null;
         }
         //var_dump($pack_products);exit();
         //текстовой блок доставка
         $cms_block = '';
         $cms = new CMS($this->block_cms_id, $this->context->language->id);
         if (is_object($cms)) {
             $cms_block = $cms->content;
         }
         $sql = "SELECT id_category FROM ps_category_product WHERE id_product={$this->product->id}";
         $result_cats = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
         $params_image = null;
         foreach ($result_cats as $cat) {
             $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.png') ? '/img/c_icon/' . $cat['id_category'] . '.png' : null;
             if (!$params_image) {
                 $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.jpg') ? '/img/c_icon/' . $cat['id_category'] . '.jpg' : null;
             }
             if ($params_image) {
                 break;
             }
         }
         //{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}
         $this->context->smarty->assign(array('is_bestsaler' => ProductSale::isBestsaler($this->product->id), 'og_type' => 'product', 'params_image' => $params_image, 'cms_block' => $cms_block, 'pack_products' => $pack_products, 'act_pack' => $act_pack, 'url' => $this->context->link->getProductLink($this->product), 'minimal_quantity' => $this->product->minimal_quantity > 1 ? $this->product->minimal_quantity : 1, 'nbComments' => $nbComments, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE')));
     }
     if (isset($_GET['quick_view'])) {
         $this->ajax = true;
         if ($flag_pack) {
             $this->setTemplate(_PS_THEME_DIR_ . 'preview_pack.tpl');
         } else {
             $this->setTemplate(_PS_THEME_DIR_ . 'preview.tpl');
         }
     } else {
         if ($flag_pack) {
             $this->setTemplate(_PS_THEME_DIR_ . 'product-pack.tpl');
         } else {
             $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
         }
     }
 }
Пример #14
0
 }
 if ($title == '' || $content == '' || !$id_product || count($grades) == 0) {
     die('0');
 }
 $allow_guests = (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
 if (Context::getContext()->customer->id || !Context::getContext()->customer->id && $allow_guests) {
     $id_guest = !($id_customer = (int) Context::getContext()->cookie->id_customer) ? (int) Context::getContext()->cookie->id_guest : false;
     $customerComment = ProductComment::getByCustomer((int) $id_product, Context::getContext()->cookie->id_customer, true, (int) $id_guest);
     if (!$customerComment || $customerComment && strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME') < time()) {
         $errors = array();
         $customer_name = false;
         if ($id_guest && !($customer_name = Context::getContext()->customer->firstname . ' ' . Context::getContext()->customer->lastname)) {
             $errors[] = $productCom->l('Please fill your name');
         }
         if (!count($errors) && $content) {
             $comment = new ProductComment();
             $comment->content = strip_tags($content);
             $comment->id_product = (int) $id_product;
             $comment->id_customer = (int) Context::getContext()->cookie->id_customer;
             $comment->id_guest = (int) $id_guest;
             $comment->customer_name = pSQL($customer_name);
             if (!$comment->id_customer) {
                 $comment->customer_name = pSQL($name);
             }
             $comment->title = pSQL($title);
             $comment->grade = 0;
             $comment->validate = 0;
             $tgrade = 0;
             $comment->save();
             foreach ($grades as $grade) {
                 $tgrade += $grade['grade'];
Пример #15
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!$this->errors) {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         $this->product->customization_required = false;
         $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false;
         if (is_array($customization_fields)) {
             foreach ($customization_fields as $customization_field) {
                 if ($this->product->customization_required = $customization_field['required']) {
                     break;
                 }
             }
         }
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = Pack::isPack($this->product->id) ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         $accessories = $this->product->getAccessories($this->context->language->id);
         if ($this->product->cache_is_pack || count($accessories)) {
             $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
         }
         if ($this->product->customizable) {
             $customization_datas = $this->context->cart->getProductCustomization($this->product->id, null, true);
         }
         // by webkul
         $htl_features = array();
         $obj_hotel_room_type = new HotelRoomType();
         $room_info_by_product_id = $obj_hotel_room_type->getRoomTypeInfoByIdProduct($this->product->id);
         $hotel_id = $room_info_by_product_id['id_hotel'];
         if (isset($hotel_id) && $hotel_id) {
             $obj_hotel_branch = new HotelBranchInformation();
             $hotel_info_by_id = $obj_hotel_branch->hotelBranchInfoById($hotel_id);
             $hotel_policies = $hotel_info_by_id['policies'];
             $hotel_name = $hotel_info_by_id['hotel_name'];
             $country = Country::getNameById($this->context->language->id, $hotel_info_by_id['country_id']);
             $state = State::getNameById($hotel_info_by_id['state_id']);
             $hotel_location = $hotel_info_by_id['city'] . ', ' . $state . ', ' . $country;
             $obj_hotel_feaures_ids = $obj_hotel_branch->getFeaturesOfHotelByHotelId($hotel_id);
             if (isset($obj_hotel_feaures_ids) && $obj_hotel_feaures_ids) {
                 foreach ($obj_hotel_feaures_ids as $key => $value) {
                     $obj_htl_ftr = new HotelFeatures();
                     $htl_info = $obj_htl_ftr->getFeatureInfoById($value['feature_id']);
                     $htl_features[] = $htl_info['name'];
                 }
             }
         }
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         if (!($date_from = Tools::getValue('date_from'))) {
             $date_from = date('Y-m-d');
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         if (!($date_to = Tools::getValue('date_to'))) {
             $date_to = date('Y-m-d', strtotime($date_from) + 86400);
         }
         $obj_booking_detail = new HotelBookingDetail();
         $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to);
         $priceDisplay = Group::getPriceDisplayMethod(Group::getCurrent()->id);
         if (!$priceDisplay || $priceDisplay == 2) {
             $price_tax = true;
         } elseif ($priceDisplay == 1) {
             $price_tax = false;
         }
         $price_tax_incl = Product::getPriceStatic($this->product->id, $price_tax);
         $total_price = $price_tax_incl * $num_days;
         $obj_booking_dtl = new HotelBookingDetail();
         $hotel_room_data = $obj_booking_dtl->DataForFrontSearch($date_from, $date_to, $hotel_id, $this->product->id, 1);
         $obj_htl_cart_booking_data = new HotelCartBookingData();
         $num_cart_rooms = $obj_htl_cart_booking_data->getCountRoomsByIdCartIdProduct($this->context->cart->id, $this->product->id, $date_from, $date_to);
         if ($hotel_room_data) {
             $total_available_rooms = $hotel_room_data['stats']['num_avail'] - $num_cart_rooms;
         }
         //end
         $location_enable = Configuration::get('WK_HOTEL_LOCATION_ENABLE');
         $hotel_branch_obj = new HotelBranchInformation();
         $hotel_info = $hotel_branch_obj->getActiveHotelBranchesInfo();
         $search_data['date_from'] = $date_from;
         $search_data['date_to'] = $date_to;
         $search_data['htl_dtl'] = $hotel_branch_obj->hotelBranchInfoById($hotel_id);
         if (Tools::getValue('error')) {
             $this->context->smarty->assign('error', Tools::getValue('error'));
         }
         $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'id_customization' => empty($customization_datas) ? null : $customization_datas[0]['id_customization'], 'accessories' => $accessories, 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'ratting_img_path' => _MODULE_DIR_ . 'hotelreservationsystem/views/img/Slices/icons-sprite.png', 'num_reviews' => ProductComment::getCommentNumber($this->product->id), 'ratting' => ProductComment::getAverageGrade($this->product->id)['grade'], 'total_available_rooms' => $total_available_rooms, 'all_hotels_info' => $hotel_info, 'location_enable' => $location_enable, 'total_price' => $total_price, 'product_controller_url' => $this->context->link->getPageLink('product'), 'num_days' => $num_days, 'date_from' => $date_from, 'date_to' => $date_to, 'hotel_location' => $hotel_location, 'hotel_name' => $hotel_name, 'hotel_policies' => $hotel_policies, 'hotel_features' => $htl_features, 'ftr_img_src' => _PS_IMG_ . 'rf/', 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'), 'search_data' => $search_data));
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }
Пример #16
0
 public static function getAveragesByProduct($id_product, $id_lang)
 {
     /* Get all grades */
     $grades = ProductComment::getGradeByProduct((int) $id_product, (int) $id_lang);
     $total = ProductComment::getGradedCommentNumber((int) $id_product);
     if (!count($grades) || !$total) {
         return array();
     }
     /* Addition grades for each criterion */
     $criterionsGradeTotal = array();
     $count_grades = count($grades);
     for ($i = 0; $i < $count_grades; ++$i) {
         if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false) {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = (int) $grades[$i]['grade'];
         } else {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] += (int) $grades[$i]['grade'];
         }
     }
     /* Finally compute the averages */
     $averages = array();
     foreach ($criterionsGradeTotal as $key => $criterionGradeTotal) {
         $averages[(int) $key] = (int) $total ? (int) $criterionGradeTotal / (int) $total : 0;
     }
     return $averages;
 }
Пример #17
0
 public static function getAveragesByProduct($id_product, $id_lang)
 {
     /* Get all grades */
     $grades = ProductComment::getGradeByProduct(intval($id_product), intval($id_lang));
     $total = ProductComment::getGradedCommentNumber(intval($id_product));
     if (!sizeof($grades) or !$total) {
         return array();
     }
     /* Addition grades for each criterion */
     $criterionsGradeTotal = array();
     for ($i = 0; $i < count($grades); ++$i) {
         if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false) {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = intval($grades[$i]['grade']);
         } else {
             $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] += intval($grades[$i]['grade']);
         }
     }
     /* Finally compute the averages */
     $averages = array();
     foreach ($criterionsGradeTotal as $key => $criterionGradeTotal) {
         $averages[intval($key)] = intval($total) ? intval($criterionGradeTotal) / intval($total) : 0;
     }
     return $averages;
 }
    function content_55574d9fd07494_75530310($_smarty_tpl)
    {
        ?>
 
<?php 
        if (!$_smarty_tpl->tpl_vars['content_only']->value && ($_smarty_tpl->tpl_vars['nbComments']->value == 0 && $_smarty_tpl->tpl_vars['too_early']->value == false && ($_smarty_tpl->tpl_vars['is_logged']->value || $_smarty_tpl->tpl_vars['allow_guests']->value) || $_smarty_tpl->tpl_vars['nbComments']->value != 0)) {
            ?>



<div id="product_comments_block_extra" class="no-print" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<?php 
            $_smarty_tpl->tpl_vars["nbComments"] = new Smarty_variable(ProductComment::getCommentNumber($_smarty_tpl->tpl_vars['id_product_comment_form']->value), null, 0);
            $_smarty_tpl->tpl_vars["ratings"] = new Smarty_variable(ProductComment::getRatings($_smarty_tpl->tpl_vars['id_product_comment_form']->value), null, 0);
            $_smarty_tpl->tpl_vars["average"] = new Smarty_variable(ProductComment::getAverageGrade($_smarty_tpl->tpl_vars['id_product_comment_form']->value), null, 0);
            $_smarty_tpl->tpl_vars["averageTotal"] = new Smarty_variable(round($_smarty_tpl->tpl_vars['average']->value['grade']), null, 0);
            ?>
	<?php 
            if ($_smarty_tpl->tpl_vars['nbComments']->value != 0) {
                ?>
		<div class="comments_note clearfix">
			<div class="star_content clearfix">
				<?php 
                if (isset($_smarty_tpl->tpl_vars['smarty']->value['section']["i"])) {
                    unset($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]);
                }
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['name'] = "i";
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] = (int) 0;
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'] = is_array($_loop = 5) ? count($_loop) : max(0, (int) $_loop);
                unset($_loop);
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'] = (int) 1 == 0 ? 1 : (int) 1;
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['show'] = true;
                $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'];
                if ($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] < 0) {
                    $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] = max($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'] > 0 ? 0 : -1, $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'] + $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start']);
                } else {
                    $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] = min($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'] > 0 ? $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'] : $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'] - 1);
                }
                if ($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['show']) {
                    $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['total'] = min(ceil(($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'] > 0 ? $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['loop'] - $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] : $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'] + 1) / abs($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'])), $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['max']);
                    if ($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['total'] == 0) {
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['show'] = false;
                    }
                } else {
                    $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['total'] = 0;
                }
                if ($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['show']) {
                    for ($_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration'] = 1; $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['total']; $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration']++) {
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration'];
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'];
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['step'];
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['first'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration'] == 1;
                        $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['last'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']["i"]['total'];
                        ?>
					<?php 
                        if ($_smarty_tpl->tpl_vars['averageTotal']->value <= $_smarty_tpl->getVariable('smarty')->value['section']['i']['index']) {
                            ?>
						<div class="star"></div>
					<?php 
                        } else {
                            ?>
						<div class="star star_on"></div>
					<?php 
                        }
                        ?>
				<?php 
                    }
                }
                ?>
				<meta itemprop="worstRating" content = "0" />
				<meta itemprop="ratingValue" content = "<?php 
                if (isset($_smarty_tpl->tpl_vars['ratings']->value['avg'])) {
                    echo htmlspecialchars(round($_smarty_tpl->tpl_vars['ratings']->value['avg'], 1), ENT_QUOTES, 'UTF-8', true);
                } else {
                    echo htmlspecialchars(round($_smarty_tpl->tpl_vars['averageTotal']->value, 1), ENT_QUOTES, 'UTF-8', true);
                }
                ?>
" />
				<meta itemprop="bestRating" content = "5" />
			</div>
		</div> <!-- .comments_note -->
	<?php 
            }
            ?>

	<ul class="comments_advices">
		<?php 
            if ($_smarty_tpl->tpl_vars['nbComments']->value != 0) {
                ?>
			<li>
				<a href="#idTab5" class="reviews">
					<?php 
                echo smartyTranslate(array('s' => 'Based on', 'mod' => 'productcomments'), $_smarty_tpl);
                ?>
 <span itemprop="reviewCount"><?php 
                echo $_smarty_tpl->tpl_vars['nbComments']->value;
                ?>
</span> <?php 
                echo smartyTranslate(array('s' => 'ratings', 'mod' => 'productcomments'), $_smarty_tpl);
                ?>

				</a>
			</li>
		<?php 
            }
            ?>
		<?php 
            if ($_smarty_tpl->tpl_vars['too_early']->value == false && ($_smarty_tpl->tpl_vars['is_logged']->value || $_smarty_tpl->tpl_vars['allow_guests']->value)) {
                ?>
			<li>
				<a class="open-comment-form" href="#new_comment_form">
					<?php 
                echo smartyTranslate(array('s' => 'Write a review', 'mod' => 'productcomments'), $_smarty_tpl);
                ?>

				</a>
			</li>
		<?php 
            }
            ?>
	</ul>
</div>
<?php 
        }
        ?>
<!--  /Module ProductComments -->
<?php 
    }
Пример #19
0
 public function hookProductTabContent($params)
 {
     global $smarty, $cookie, $nbProducts;
     $commentNumber = intval(ProductComment::getCommentNumber(intval($_GET['id_product'])));
     $averages = ProductComment::getAveragesByProduct(intval($_GET['id_product']), intval($cookie->id_lang));
     $averageTotal = 0;
     foreach ($averages as $average) {
         $averageTotal += floatval($average);
     }
     $averageTotal = count($averages) ? $averageTotal / count($averages) : 0;
     $smarty->assign(array('logged' => intval($cookie->id_customer), 'action_url' => $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], 'comments' => ProductComment::getByProduct(intval($_GET['id_product'])), 'criterions' => ProductCommentCriterion::getByProduct(intval($_GET['id_product']), intval($cookie->id_lang)), 'averages' => $averages, 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal));
     $nbProducts = $commentNumber;
     require_once dirname(__FILE__) . '/../../pagination.php';
     return $this->display(__FILE__, '/productcomments.tpl');
 }
Пример #20
0
 public function hookExtraProductComparison($params)
 {
     require_once dirname(__FILE__) . '/ProductComment.php';
     require_once dirname(__FILE__) . '/ProductCommentCriterion.php';
     $list_grades = array();
     $list_product_grades = array();
     $list_product_average = array();
     $list_product_comment = array();
     foreach ($params['list_ids_product'] as $id_product) {
         $grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
         $criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
         $grade_total = 0;
         if (count($grades) > 0) {
             foreach ($criterions as $criterion) {
                 if (isset($grades[$criterion['id_product_comment_criterion']])) {
                     $list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
                     $grade_total += (double) $grades[$criterion['id_product_comment_criterion']];
                 } else {
                     $list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = 0;
                 }
                 if (!array_key_exists($criterion['id_product_comment_criterion'], $list_grades)) {
                     $list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
                 }
             }
             $list_product_average[$id_product] = $grade_total / count($criterions);
             $list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
         }
     }
     if (count($list_grades) < 1) {
         return false;
     }
     $this->context->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'], 'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment));
     return $this->display(__FILE__, '/products-comparison.tpl');
 }
Пример #21
0
 public function actionDeleteComment($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         ProductComment::model()->findByPk($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }