Jump to content

Add custom fields during order.


player.c64

Recommended Posts

Hi everyone.

This is my problem.

I need add custom field during order same as message field and save it in created column in table ps_message.

 

So far I've added to the order-carriers.tpl

<p>Please insert
your purchase order number in the space provided.</p>
<p><textarea cols="120" rows="3" name="pon" id="pon">{if isset($oldMessage)}{$oldMessage}{/if}</textarea></p>

 

OrderController.php

if (Tools::isSubmit('pon'))
$this->_updateMessage(Tools::getValue('pon'));

 

ParentOrderController.php

protected function _checkFreeOrder()
{
if ($this->context->cart->getOrderTotal() <= 0)
{
$order = new FreeOrder();
$order->free_order_class = true;
$order->validateOrder($this->context->cart->id, Configuration::get('PS_OS_PAYMENT'), 0, Tools::displayError('Free order', false), null, array(), null, false, $this->context->cart->secure_key);
return (int)Order::getOrderByCartId($this->context->cart->id);
}
return false;
}

protected function _updateMessage($messageContent)
{
if ($messageContent)
{
if (!Validate::isMessage($messageContent))
$this->errors[] = Tools::displayError('Invalid message');
else if ($oldMessage = Message::getMessageByCartId((int)($this->context->cart->id)))
{
$message = new Message((int)($oldMessage['id_message']));
$message->message = $messageContent;
$message->pon = $_POST['pon'];
$message->update();
}
else
{
$message = new Message();
$message->message = $messageContent;
$message->pon = $messageContent;
$message->id_cart = (int)($this->context->cart->id);
$message->id_customer = (int)($this->context->cart->id_customer);
$message->add();
}
}
else
{
if ($oldMessage = Message::getMessageByCartId($this->context->cart->id))
{
$message = new Message($oldMessage['id_message']);
$message->delete();
}
}
return true;
}

 

My question is how to save field 'pon' to created column "pon" in the table 'ps_message'.

 

I've also tried custom function but nothing works.

protected function PurchaseOrderNumber($txtPon)  {

Db::getInstance()->execute("INSERT INTO `"._DB_PREFIX_."message` (`id_cart`, `id_employee`, `id_order`, `message`, `private`, `date_add`, `pon`) VALUES (".intval($cart->id).", 0, 0, '".$messageContent."', 0, NOW(),".$_POST['pon'].")");
}

 

Thanks for any advance.

Link to comment
Share on other sites

  • 4 months later...
  • 11 months later...
  • 11 months later...

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