Jump to content

Add an input field near Product price


Recommended Posts

Hi, I'm trying to add an input field where user can enter his pincode and check for delivery availability, for that I'm creating my own module but so far nothing has been able to print out on the front. Here's what I've done so far:

1. Disabled all cache and enabled force compilation.

2. Added mymodule folder. In it I have

mymodule.php

<?php
if (!defined('_PS_VERSION_'))
exit;

class myModule extends Module
{
  public function __construct()
  {
    $this->name = 'mymodule';
    $this->tab = 'shipping_logistics';
    $this->version = '0.1';
    $this->author = 'Vipul Kapoor';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
    $this->bootstrap = true;

    parent::__construct();
 
    $this->displayName = $this->l('Serviceable Pincodes');
    $this->description = $this->l('Adds a field where user can enter his Pincode and check if delivery is available in his area.');

    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
  }


public function install()
{
  if (Shop::isFeatureActive())
    Shop::setContext(Shop::CONTEXT_ALL);


  if (!parent::install() ||
  !$this->registerHook('myCustomHook') ||
   !$this->registerHook('header')
  )
  return false;

  return true;
}


public function uninstall()
{
  if (!parent::uninstall())
    return false;

  return true;
}


  public function hookDisplayMyCustomHook($params)
  {
     return $this->display(__FILE__, 'mymodule.tpl');
  }

  public function hookDisplayHeader()
  {
    $this->context->controller->addCSS($this->_path.'css/mymodule.css', 'all');
    $this->context->controller->addJS($this->_path.'js/mymodule.js', 'all');
  }
}
 
mymodule.tpl file in views/templates/hook/
<!-- Block mymodule -->
<div id="mymodule">
  <h4>Check delivery availability in your Area.</h4>
  <form>
    <input type="text" name="mymmodule_pincode" placeholder="Enter Pincode" required>
    <button type="submit">Check</button>
  </form>
</div>
<!-- /Block mymodule -->

 

Then I installed the module and checked on "Positions" page but my module doesn't show up there. I think the hook name/position isn't right. Any ideas?

 

Edit: Code updated above. I added my custom hook and I can see it has been registered on Positions page under my custom hook. But the front end isn't showing anything.

 

In my products.tpl file of my theme I added my custom hook where I want to display the form:

{hook h='myCustomHook'}

I also tried adding {debug} to products.tpl but my hook isn't there. The css and js files have been included though. Please help.

Edited by Vee.K727 (see edit history)
Link to comment
Share on other sites

For some reason, adding the word "display" to the hook name made it work. I don't know how but would like to hear from an expert. So now I have this

if (!parent::install() ||
!$this->registerHook('displayMyCustomHook') ||
   !$this->registerHook('header')
)
public function hookDisplayMyCustomHook($params)
{
return $this->display(__FILE__, 'mymodule.tpl');
}
{hook h='displayMyCustomHook'}
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...