Jump to content

how to change default order status for some payment module?


Recommended Posts

  • 5 months later...

if still interested, (and for others with same problem). here is my take on this:

1) in config/config.inc.php find /* Order states */ (line N°100 i think)
2) copy the name of your desired order status. (ex: _PS_OS_PAYMENT_)

3) in /modules/cacheondelivery/validation.php find the validateOrderCOD function ex:

$cashOnDelivery->validateOrderCOD(intval($cart->id), _PS_OS_PREPARATION_, $total, $cashOnDelivery->displayName);



4) replace the _PS_OS_PREPARATION_ with the one you picked from config.inc.php

here are Order status default titles (titles are editable in BO Orders > Order status)
1 _PS_OS_CHEQUE_ : wailting for cheque payment
2_PS_OS_PAYMENT_ : payement successful
3_PS_OS_PREPARATION_ : preparing order
4_PS_OS_SHIPPING_ : order shipped
5_PS_OS_DELIVERED_ : order delivered
6_PS_OS_CANCELED_ : order canceled
7_PS_OS_REFUND_ : order refunded
8_PS_OS_ERROR_ : payement error
9_PS_OS_OUTOFSTOCK_ : product out of stock
10_PS_OS_BANKWIRE_ : wailting for bank wire

  • Like 3
Link to comment
Share on other sites

  • 4 years later...
  • 2 months later...
In backend navigate to following: Orders > Statuses > Add New (Button in top right of screen)
Thats adding a status by hand, not by module ;)

 

To create an order status by module in Prestashop v1.5.x add the following to your module's install function:

change code in red to your needs

// create new order status STATUSNAME

$values_to_insert = array(

'invoice' => 1,

'send_email' => 1,

'module_name' => $this->name,

'color' => 'RoyalBlue',

'unremovable' => 0,

'hidden' => 0,

'logable' => 1,

'delivery' => 0,

'shipped' => 0,

'paid' => 1,

'deleted' => 0);

 

if(!Db::getInstance()->autoExecute(_DB_PREFIX_.'order_state', $values_to_insert, 'INSERT'))

return false;

$id_order_state = (int)Db::getInstance()->Insert_ID();

$languages = Language::getLanguages(false);

foreach ($languages as $language)

Db::getInstance()->autoExecute(_DB_PREFIX_.'order_state_lang', array('id_order_state'=>$id_order_state, 'id_lang'=>$language['id_lang'], 'name'=>'Status name', 'template'=>''), 'INSERT');

if (!@copy(dirname(__FILE__).DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'logo.gif', _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'os'.DIRECTORY_SEPARATOR.$id_order_state.'.gif'))

return false;

Configuration::updateValue('PS_OS_STATUSNAME', $id_order_state);

unset($id_order_state);

 

To set the order status in a module's function (for ex. validation) call:

change code in red to your needs

$this->module->validateOrder($this->context->cart->id, Configuration::get('PS_OS_STATUSNAME'), $this->context->cart->getOrderTotal(true, 3), 'payment method name', 'Optional transaction message', array(), false, false, $this->context->cart->secure_key);

Edited by scorpionsworld (see edit history)
  • Like 4
Link to comment
Share on other sites

To create an order status by module in Prestashop v1.5.x add the following to your module's install function:

change code in red to your needs

// create new order status STATUSNAME

$values_to_insert = array(

'invoice' => 1,

'send_email' => 1,

'module_name' => $this->name,

'color' => 'RoyalBlue',

'unremovable' => 0,

'hidden' => 0,

'logable' => 1,

'delivery' => 0,

'shipped' => 0,

'paid' => 1,

'deleted' => 0);

 

if(!Db::getInstance()->autoExecute(_DB_PREFIX_.'order_state', $values_to_insert, 'INSERT'))

return false;

$id_order_state = (int)Db::getInstance()->Insert_ID();

$languages = Language::getLanguages(false);

foreach ($languages as $language)

Db::getInstance()->autoExecute(_DB_PREFIX_.'order_state_lang', array('id_order_state'=>$id_order_state, 'id_lang'=>$language['id_lang'], 'name'=>'Status name', 'template'=>''), 'INSERT');

if (!@copy(dirname(__FILE__).DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'logo.gif', _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'os'.DIRECTORY_SEPARATOR.$id_order_state.'.gif'))

return false;

Configuration::updateValue('PS_OS_STATUSNAME', $id_order_state);

unset($id_order_state);

 

 

This sure answer it.

Thanks :)

Edited by rahumateo (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Hi,

I am using Prestahsop 1.4.7.0, with the Cash on delivery module v0.4.

In that module, is the /module/cashondelivery/validation.php file, where one can find the here below line :
$cashOnDelivery->validateOrder((int)$cart->id, Configuration::get('PS_OS_PREPARATION'), $total, $cashOnDelivery->displayName, NULL, array(), NULL, false, $customer->secure_key);

So, by default the orders made with this way of payment get the "In preparation" status.

I would like to do the following :
a-create a new status called "Cash on delivery payment"
    - that's easy to do here : "Control panel > Orders > Status"
b-assign this status by default to any order made with this way of payment.

The status list is located in  /config.inc.php
As an example one status is defined as :
        - define('_PS_OS_CHEQUE_',      Configuration::get('PS_OS_CHEQUE'));
So to add the new status in /config.inc.php, does I need only to add the here below line ?
        - define('_PS_OS_xxxxxx_',      Configuration::get('PS_OS_xxxxxx'));
And if I does only need to do that, what I have to put in place of xxxxxx ?

Thank you very much in advance for any reply.

Patrick

Edited by patrmich (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Its simple way.

 

edit: /modules/cashondelivery/controllers/front/validation.php 

 

change line:

 

$this->module->validateOrder((int)$this->context->cart->id, Configuration::get('PS_OS_PREPARATION'), $total, $this->module->displayName, null, array(), null, false, $customer->secure_key); 

 
repleace with:
 

$this->module->validateOrder((int)$this->context->cart->id, 22, $total, $this->module->displayName, null, array(), null, false, $customer->secure_key);

 

 

ex. 22 - its status ID in your BO

 
  • Like 1
Link to comment
Share on other sites

  • 3 months later...

I did try with bankwire validation add Configuration::get('PS_OS_PREPARATION'and if I used got the error that somethin goes wrong, and not got final screen with bank acounts price to pay. 

Can be possible that bankwire module work diferent then others because of final screen ?

 

Thanks

Jan

Link to comment
Share on other sites

  • 2 months later...

Thats adding a status by hand, not by module ;)

 

To create an order status by module in Prestashop v1.5.x add the following to your module's install function:

change code in red to your needs

 

 

To set the order status in a module's function (for ex. validation) call:

change code in red to your needs

Sorry but there's something wrong during the database creation of a new status.

I mean in "ps_configuration" table. The id value is "null", it doesn't generate a valid id (es. 14), so the module can't work properly.

Thanks.

 

Edit:

 

Solved. Just cancel the line "unset($id_order_state);" , it's contradictory.

Edited by Rain_xx (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...

3) in /modules/cacheondelivery/validation.php find the validateOrderCOD function ex:

$cashOnDelivery->validateOrderCOD(intval($cart->id), _PS_OS_PREPARATION_, $total, $cashOnDelivery->displayName);

 

Where can I find it in prestashop 1.7.4.3 ?  

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

In 1.7 you will need to go to:

modules / ps_cashondelivery / controllers / front / validation.php

Find $this->module->validateOrder (around line 57) and swap out Configuration::get('PS_OS_PREPARATION') with the id you want.

i.e.

$this->module->validateOrder((int)$this->context->cart->id, Configuration::get('PS_OS_PREPARATION'), $total, $this->module->displayName, null, array(), null, false, $customer->secure_key);

becomes

$this->module->validateOrder((int)$this->context->cart->id, X, $total, $this->module->displayName, null, array(), null, false, $customer->secure_key);

where X is the id of the order status that you want it to use.

Link to comment
Share on other sites

  • 2 months later...

An alternative is to make a similar implementation as Cash on delivery where AdminOrdersControllerCore is setting $defaults_order_state according to PS_OS_COD_VALIDATION set in ps_configuration table:

$defaults_order_state = array(
	'cheque' => (int)Configuration::get('PS_OS_CHEQUE'),
	'bankwire' => (int)Configuration::get('PS_OS_BANKWIRE'),
	'cashondelivery' => Configuration::get('PS_OS_COD_VALIDATION') ? (int)Configuration::get('PS_OS_COD_VALIDATION') : (int)Configuration::get('PS_OS_PREPARATION'),
	'other' => (int)Configuration::get('PS_OS_PAYMENT')
);

This is the way it is implemented in PS1.6.1.17.

In my case i updated PS_OS_COD_VALIDATION from 14 (pending payment at delivery) to 3 (preparing order) directly in the database.

Edited by nbowlinger (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
On 9/8/2014 at 5:22 PM, Rain_xx said:

Sorry but there's something wrong during the database creation of a new status.

I mean in "ps_configuration" table. The id value is "null", it doesn't generate a valid id (es. 14), so the module can't work properly.

Thanks.

 

Edit:

 

Solved. Just cancel the line "unset($id_order_state);" , it's contradictory.

Hi, I am new to Prestashop.

I tried the steps to add CustomOrderStatus within the module.
But, while installing module, it gives out an error.
I tried to install the function in the install() as suggested as well.
 

 public function install()
    {

        if (!parent::install()
            || !$this->registerHook('paymentOptions')
            || !$this->registerHook('paymentReturn')
            || !$this->registerHook('backOfficeHeader')
            || $this->addCustomOrderStatus()
        ) {
            return false;
        }
        return true;
    }

Tried to log the error and surrounded the DB step into a try catch but no luck there as well using PrestashopLogger::addLog().
Can you suggest what am i missing as well as how to log the errors?

 

  • Like 1
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...