Jump to content

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

Pulling Custom Fields From Data Base Rate Topic   - - - - -

 
  • horsipede
  • Newbie
  • Trial users
  • Join Date: 02-Dec 19
  • 7 posts

Posted 10 January 2020 - 07:49 AM #1

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!



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

Posted 10 January 2020 - 01:42 PM #2

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


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    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • soft-solid
  • Junior Member
  • Authorized Reseller
  • Join Date: 19-Apr 10
  • 997 posts

Posted 11 January 2020 - 11:33 AM #3

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


Team of SoftSolid
cs-cart.pl

 
  • horsipede
  • Newbie
  • Trial users
  • Join Date: 02-Dec 19
  • 7 posts

Posted 13 January 2020 - 04:14 AM #4

 

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.



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

Posted 13 January 2020 - 06:09 AM #5

You are welcome!


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    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)