Jump to content

Override productPrice variable


Gugis

Recommended Posts

Is it possible to override productPrice variable? I've tried to do it by overriding ProductController

<?php
class ProductController extends ProductControllerCore{
    public function initContent()
	{
		self::$smarty->assign('productPrice', 10 . 'extra text');
		parent::initContent();
	}
}

I had more success by overriding Product class, but "extra text" string vas removed:

<?php
class Product extends ProductCore
{
	public static function priceCalculation(){
		return 10 . 'extra text';
	}
}
Edited by Gugis (see edit history)
Link to comment
Share on other sites

The key to these is WHEN you override. I used the following in override/classes/Product.php to add an RRP (set in each product as a group price) to products:

public static function getTaxesInformations($row, Context $context = null)
    {
        $row = parent::getTaxesInformations($row, $context);
        
        $module = Module::getInstanceByName('yourmodulethatcontainsthefunction');
        $row['rrp_price'] = $module->getGroupPriceStatic($row['id_product'], (int)MembershipCard::getRRPGroup(), true, 6,  ((isset($row['id_product_attribute']) AND !empty($row['id_product_attribute'])) ? (int)($row['id_product_attribute']) : null));
        return $row;
    }

$row is an array that contains the source data that's passed to the theme.....

It's not really clear though what you're trying to achieve - is it to change the actual price charged (which the above won't achieve) or to modify how the price is displayed (which the above type of solution COULD achieve)?

Edited by Paul C (see edit history)
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...