Jump to content

Get database info in cart-detailed-product-line.tpl


Florian644

Recommended Posts

Hello,

I would need to get database info to be displayed in cart-detailed-product-line.tpl
I need to access the ps_cart table and display infos from a column I created in it. There already is a $cart variable available in this tpl file but it looks like it doesn't get datas from ps_cart. I looked for the php file from where I could call those datas with SQL requests but I don't get to find it...

How can I manage to do it ?

Thanks.

Link to comment
Share on other sites

The best way to do this is to override Cart.php and insert your columns.

class Cart extends CartCore
{
	public $my_column_one; // INTEGER or 1 / 0
	public $my_column_two; // HTML text

	public function __construct($id = null, $idLang = null)
	{
		self::$definition['fields']['my_column_one'] = array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt');
		self::$definition['fields']['my_column_two'] = array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml');
		parent::__construct($id);
	}
}

 

Link to comment
Share on other sites

Hello, thanks but that is not what I needed. I manage to find a way by using the displayCartExtraProductActions hook (which is available cart-detailed-product-line.tpl) in my custom module, assign a tpl file and the SQL request to get the data and put this hook where I need in cart-detailed-product-line.tpl.

public function hookDisplayCartExtraProductActions()
    {   
        $result = 'SELECT `my_custom_field`
        FROM `' . _DB_PREFIX_ . 'cart`
        WHERE `id_cart` = ' . $this->context->cookie->id_cart;

        $templates = Db::getInstance()->getValue($result);

        $this->context->smarty->assign([
            'templates' => unserialize($templates)
        ]);

        return $this->display(__FILE__, 'cart-templates-customs.tpl');
    }

 

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