Jump to content

thadaninilesh

Members
  • Posts

    1
  • Joined

  • Last visited

About thadaninilesh

  • Birthday 07/19/1994

Contact Methods

Profile Information

  • Location
    India
  • First Name
    Nilesh
  • Last Name
    Thadani

thadaninilesh's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hello, I have been trying to develop a custom module in prestashop for the customers to add testimonials after getting their order delivered. Being a newbie in prestashop I'm stuck on a very silly issue of form submit. I have a module in which there is a module file whose location is root/modules/Testimonialmodule/TestimonialModule.php class TestimonialModule extends Module{ public function __construct(){ $this->name = 'testimonialmodule'; $this->displayName = 'Testimonials Module'; $this->tab = 'front_office_features'; $this->version = '0.1'; $this->author = 'Nilesh Thadani'; $this->description = 'Using this module customer will be able to see testimonials on the home page and write reviews about their purchases from the My Account tab'; $this->bootstrap = true; parent::__construct(); } public function install(){ parent::install(); $this->registerHook('displayProductTabContent'); $this->registerHook('displayHome'); $this->registerHook('displayCustomerAccount'); $this->registerHook('displayTestimonialForm'); $this->registerHook('displayTestimonial'); } public function processTestimonialForm(){ if(Tools::isSubmit('submit_testimonial')){ $customer_id = $this->context->cookie->id_customer; $comment = Tools::getValue('comment'); $rating = Tools::getValue('rating'); $img_name = Tools::getValue('fileUpload'); $order_id = Tools::getValue('order_id'); $testimonial_allow = Tools::getValue('testimonial_allow'); if(empty($comment) || empty($rating)){ $this->errors[] = Tools::displayError('Message and rating must be filled while writing a review'); } else { if (isset($_FILES['fileUpload']) && !empty($_FILES['fileUpload'])) { $temp = explode(".", $_FILES['fileUpload']['name']); $img_name = $order_id.'_'.$customer_id . '_' . round(microtime(true)) . '_testimonial.' . end($temp); $move_result = move_uploaded_file($_FILES['fileUpload']['tmp_name'], _PS_IMG_DIR_ . 'testimonials/' . $img_name); if(empty($move_result)){ $this->errors[] = Tools::displayError('We could not upload your photo, please try again'); } } $insert = array( 'order_id' => $order_id, 'customer_id' => (int)$customer_id, 'comment' => pSQL($comment), 'ratings' => (int)$rating, 'img_name' => pSQL($img_name), 'testimonial' => $testimonial_allow, 'date' => date('Y-m-d H:i:s') ); print_r($insert); Db::getInstance()->insert('testimonials', $insert); } } } public function assignTestimonialForm(){ $customer_id = $this->context->cookie->id_customer; $comments = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'testimonials WHERE customer_id='.(int)$customer_id); $this->context->smarty->assign('comments', $comments); } public function hookDisplayTestimonialForm($params){ $this->processTestimonialForm(); $this->assignConfiguration(); $this->assignTestimonialForm(); $this->context->smarty->assign('link',$this->context->link->getModuleLink('testimonialmodule')); return $this->display(__FILE__, 'displayTestimonialForm.tpl'); } Here is my .tpl file which is associated with my custom hook located at root/modules/TestimonialModule/views/templates/hook/displayTestimonialForm.tpl <h3 class="page-product-heading">Product Comments</h3> <div class="rte"> <form action="" method="post" id="comment-form"> {if $enable_order_select eq '1'} <input type="hidden" value="{$order->id}" name="order_id"> {/if} {if $enable_ratings eq '1'} <div class="form-group"> <label for="rating">Rating</label> <div class="row"> <div class="col-xs-4"> <select name="rating" id="rating" class="form-control" required> <option value="0">--Choose--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> </div> </div> {/if} {if $enable_comments eq '1'} <div class="form-group"> <label for="comment">Comments:</label> <textarea name="comment" id="comment" rows="3" class="form-control" required></textarea> </div> {/if} {if $enable_photo_upload eq '1'} <div class="form-group"> <label for="fileUpload">Upload Image </label> <input type="file" name="fileUpload" id="fileUpload" /> </div> {/if} {if $enable_testimonial eq '1'} <div class="form-group"> <input type="checkbox" name="testimonial_allow" id="testimonial_allow" class="form-control" value="1"> <label for="testimonial_allow">Allow this review to be uploaded as a testimonial</label> </div> {/if} {if $enable_testimonial eq '1' OR $enable_comments eq '1' OR $enable_photo_upload eq '1' OR $enable_ratings eq '1' OR $enable_order_select eq '1'} <button type="submit" class="btn btn-default button-medium" name="submit_testimonial" id="submit_testimonial"> <span>Save <i class="icon-chevron-right right"></i></span> </button> {/if} </form> </div> The problem is when i try to submit the form, isSubmit function return false and hence the code does not get executed. I have placed this hook on the bottom of the order-detail.tpl file located in the root of my theme's directory. Any help on this will be highly appreciated. Thank you.
×
×
  • Create New...