Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How To Add Custom Order Fields To Orders Table In Database. Rate Topic   - - - - -

 
  • Jmoffat
  • Member
  • Members
  • Join Date: 15-Oct 12
  • 24 posts

Posted 20 March 2018 - 10:24 AM #1

I'm new to addon development and am trying to add a new field to the notes section of the checkout like so: 

 

in notes.pre.tpl: 

<!-- Select Delivery Date -->
<h3>{__("dd_title")}</h3>
<div>
    <p>{__("dd_message")}</p>
    <input type="date" name="delivery_date">
</div>

In my func.php file I have:

function fn_delivery_date_place_order($order_id, $action, $order_status, $cart, $auth)
{
    if(!empty($cart['delivery_date'])){
        db_query('UPDATE ?:orders SET ?u WHERE order_id = ?i', array(
            'delivery_date' =>$cart['delivery_date']
        ), $order_id);
    }
}

the function runs but $cart['delivery_date']; is empty when i submit the order, I'm clearly missing a step. 

 

I have a new column "delivery_date" int the orders table in the database. Could someone please suggest what additional steps I'd need to take to add my custom field into this column in the orders table?

 

 

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 17267 posts

Posted 20 March 2018 - 01:29 PM #2

Notes value is added to the cart array in the fn_checkout_update_steps (app/functions/fn.cart.php) function:

    if (!empty($params['customer_notes'])) {
        $cart['notes'] = $params['customer_notes'];
    }

You should use the same logic. In this case even the fn_delivery_date_place_order is not required. Just add the delivery_date field to cscart_orders table


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Jmoffat
  • Member
  • Members
  • Join Date: 15-Oct 12
  • 24 posts

Posted 20 March 2018 - 03:27 PM #3

Notes value is added to the cart array in the fn_checkout_update_steps (app/functions/fn.cart.php) function:

    if (!empty($params['customer_notes'])) {
        $cart['notes'] = $params['customer_notes'];
    }

You should use the save logic. In this case even the fn_delivery_date_place_order is not required. Just add the delivery_date field to cscart_orders table

 

 

Excellent thanks. I'll give that a try. 



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10563 posts

Posted 26 March 2018 - 06:35 PM #4

If you have the delivery date in a smarty variable aready, then do't modify core files, use the 'final_section_customer_notes' hook to add your display below the customer notes.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.