Pulling Custom Fields From Data Base

Hello!

I made a separate "tracking_id" column in the cscart_orders database which is given a random alphanumeric string everytime an order is placed. I wanted to display the tracking ID instead of the Order_ID in the orders.search page but calling {o.tracking_id} in the .TPL file only resulted in a blank output. Can anyone help with this?

Thanks!

You should use the pre_get_orders hook in the fn_get_orders function (app/functions/fn.cart.php) to extend the $fields array with your custom column name

Hello
If you want to have access to this field in new templates you must create the schema file app / addons / your_addon / schemas / documents / order.post.php
$schema['your_addon'] = array (
     'class' => '\Tygh\Addons\YourAddon\Documents\Order\YourAddonVariable',
     'arguments' => array ('# context', '@formatter'),
);

return $ schema;

and file
/app/addons/your_addon/Tygh/Addons/YourAddon/Documents/Order/YourAddonVariable.php
containing information
namespace Tygh\Addons\YourAddon\Documents\Order;

use Tygh\Template\Document\Order\Context;
use Tygh\Template\IVariable;
use Tygh\Tools\Formatter;

/ **

  • Class Parcel LockersVariable

  • /
    class YourAddonVariable implements IVariable
    {
    public tracking_id;

    public function __construct (Context $context, Formatter $formatter)
    {
    $order = $context->getOrder();

     if (! empty ($order-> data['order_id'])) {
         $tracking_id = db_get_field ("SELECT tracking_id FROM?: orders WHERE order_id =?i", $order->data['order_id']);
         if (tracking_id) {
             $this->tracking_id = $tracking_id;
         } else {
             $this->tracking_id = "";
         } // end if
     } // end if
    

    }
    }

Not tested !

Best regards

Robert

eComLabs

Posted 10 January 2020 - 09:42 PM

You should use the pre_get_orders hook in the fn_get_orders function (app/functions/fn.cart.php) to extend the $fields array with your custom column name

Hello!

Thank you for this! It worked like a charm.
Also I'm pretty sure I botched how to reply in the forums but thats a topic for another time.

You are welcome!