Jump to content

Adding an additionnal input to an order


Nerloggz

Recommended Posts

 Hi ! 

 

So what I want to do seems quite simple : allowing the customers to choose a precise hour of delivery for their order (to be displayed in the back-office).

 

I did some research and this is what I did so far :

 

    - Added "myVariable" to ps_cart table.

    - Added public $myVariable in Cart.php

    - Added 'myVariable' => array('type' => self::TYPE_DATE) in $definition in Cart.php

    - Created a module :

<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class heureLivraison extends Module
{
	public function __construct()
	{
		$this->name = 'heurelivraison';
		$this->tab = 'front_office_features';
		$this->version = '1.0';
		$this->author = 'COLIN Théotime';
		$this->need_instance = 0;
		$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
		$this->bootstrap = true;
		
		parent::__construct();
		
		$this->displayName = $this->l('Heure livraison');
		$this->description = $this->l('Permet aux clients de choisir une heure de livraison précise.');
		
		$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
		
		if (!Configuration::get('HEURELIVRAISON_NAME'))      
		  $this->warning = $this->l('No name provided');
	}
  
	public function install()
	{
		if (!parent::install())
		return false;
		return true;
	}
	
	public function uninstall()
	{
		if (!parent::uninstall())
		return false;
		return true;
	}
	
	public function hookActionCarrierProcess($params)
	{
		$cart = $params['cart'];
		$cart->myVariable = Tools::getValue('myVariable'); 
	}
}

   - Installed it and hooked it to ActionCarrierProcess.

   - Added an input on the check out page.

 

Though, the variable isn't added to the table. I think my module isn't working as even with a fixed date, nothing is added.

 

Thanks for help ! May give away a little reward (Amazon gift card or anything else) if anyone can help me figure this out. 

Link to comment
Share on other sites

I expect the cart isn't saved during the checkout process anymore.

 

Maybe add the variable/field to the Order class/table, instead of the cart. Then when the order is saved (when confirming the order), it should be saved automatically.

 

My 2 cents,

pascal

Link to comment
Share on other sites

Hmmm, so basically in which file do I need to get the value and add it to $order ? (using Tools::getValue('myVariable'); I guess ?)

I'm sorry, I'm really new to this but I'm slowly beginning to understand !

 

Thanks a lot for the answer.

Link to comment
Share on other sites

Hi Nerloggz,

 

You should at first have a look at the Prestashop developer documentation  :

 

Your module should consist of some of these :

1- a form : /themes/Mytheme/appli.tpl

2- optional Css or Js files : /themes/Mytheme/css or /themes/Mytheme/js or /themes/Mytheme/modules/XXX/css or /themes/Mytheme/modules/XXX/js

3- controller or override files :

        - front : /controllers/front/AppliController.php

        - admin :  /controllers/admin/AdminAppliController.php  (for the backoffice management)

4- classes : /classes/Db.php contains some variables and the definition (fields) of the database table.

5- Database : using sql command or phpmyadmin, you have to prealably update your database, insert all new fields

 

Hope this help.

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...