cscreenstore Posted May 27, 2018 Share Posted May 27, 2018 Hello, I am trying to add the Product Comments - add a review feature in the product list, but when I do I get the following 2 Notices and and a Fatal Error. Notice: Undefined index: product in C:\wamp64\www\msmpresta1.6.1.14\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 183 Notice: Trying to get property of non-object in C:\wamp64\www\msmpresta1.6.1.14\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 183 Fatal error: Call to undefined method CategoryController::getProduct() in C:\wamp64\www\msmpresta1.6.1.14\modules\productcomments\productcomments.php on line 783 Line 783 is $product = $this->context->controller->getProduct(); Any help on what is causing the errors and how to fix them would be appreciated. I am using Prestashop version 1.6.1.14 and Product Comments version 3.6.1 Thank you. Kathleen Link to comment Share on other sites More sharing options...
cscreenstore Posted June 14, 2018 Author Share Posted June 14, 2018 It has been 18 days since I asked this question and I still have no reply. Isn't there anyone out there who can help with this problem? Thanks Kathleen Link to comment Share on other sites More sharing options...
razaro Posted June 14, 2018 Share Posted June 14, 2018 Hi Kathleen You did not mention how you are trying to add comment on product list page. I mean what code you tried, what hook you use ? Do you use custom theme ? But error message is clear, you need to pass current product so it would get review. But I think you just need to check if module is hooked to right place "displayProductListReviews" and also do you have in your theme, in file product-list.tpl code similar to this : {capture name='displayProductListReviews'}{hook h='displayProductListReviews' product=$product}{/capture} {if $smarty.capture.displayProductListReviews} <div class="hook-reviews"> {hook h='displayProductListReviews' product=$product} </div> {/if} Link to comment Share on other sites More sharing options...
cscreenstore Posted June 14, 2018 Author Share Posted June 14, 2018 Hello Razaro, Thank you for replying!!! I have managed to add the review feature via a custom hook, and in that hook I have the following code: include_once dirname(__FILE__).'/ProductComment.php'; include_once dirname(__FILE__).'/ProductCommentCriterion.php'; $id_guest = (!$id_customer = (int) $this->context->cookie->id_customer) ? (int) $this->context->cookie->id_guest : false; $customerComment = ProductComment::getByCustomer((int) (Tools::getValue('id_product')), (int) $this->context->cookie->id_customer, true, (int) $id_guest); $average = ProductComment::getAverageGrade((int) Tools::getValue('id_product')); $product = $this->context->controller->getProduct(); $image = Product::getCover((int) Tools::getValue('id_product')); $cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], 'medium_default'); $this->context->smarty->assign(array( 'id_product_comment_form' => (int) Tools::getValue('id_product'), 'product' => $product, 'secure_key' => $this->secure_key, 'logged' => $this->context->customer->isLogged(true), 'allow_guests' => (int) Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), 'productcomment_cover' => (int) Tools::getValue('id_product').'-'.(int) $image['id_image'], // retro compat 'productcomment_cover_image' => $cover_image, 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'criterions' => ProductCommentCriterion::getByProduct((int) Tools::getValue('id_product'), $this->context->language->id), 'action_url' => '', 'averageTotal' => round($average['grade']), 'ratings' => ProductComment::getRatings((int) Tools::getValue('id_product')), 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), 'nbComments' => (int) (ProductComment::getCommentNumber((int) Tools::getValue('id_product'))), )); return $this->display(__FILE__, '/mytemplate.tpl'); The link is via a pencil icon. But when I try to add a review by clicking on the icon, the fancybox with the form opens, but it is always the same product, that is I have 6 products in the list, but every link shows the same product - the first product in the list. I am assuming this is happening as it was written to be used on the products page where there is only one product. When I enabled the debug, I received the fatal error message. The code that opens the fancybox is: <script> $(document).ready(function() { if (!!$.prototype.fancybox) $('.open-comment-form').fancybox({ 'autoSize' : false, 'width': 800, 'height': auto, 'hideOnContentClick': false, 'title' : null, }); }); </script> {if (!$too_early AND ($is_logged OR ($PRODUCT_COMMENTS_ALLOW_GUESTS == 0)))} <p class="align_center"> <a class="open-comment-form" href="#new_comment_form" title="{l s='Write your review' mod='productcomments'}!"></a> </p> {/if} Any help you can give me will be greatly appreciated, as it is beyond my knowledge to fix it. Thank you. Kathleen Link to comment Share on other sites More sharing options...
cscreenstore Posted June 15, 2018 Author Share Posted June 15, 2018 Hello razaro, Don't give up on me now! As you can see from my reply, I want to add the feature that enables a customer to add a review, not the feature that shows the ratings. I have already done that. Thanks Kathleen Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now