Jump to content

Adjusting price before inserting into DB


Saulyx

Recommended Posts

Hi there,

 

I need to adjust(via hard edit) price of an item before it's inserted into DB also I need to do same thing when updating a product, could someone point me to the right file/line? I've looked for quite a while and was not able to find it.

 

Thank you

Link to comment
Share on other sites

ObjectModel class fires an hook called 'actionObjectProductAddBefore' before adding itself in the DB. You can hook a module there and do your work. Here's an example:

class AdjustProductPriceModule extends Moduel {

  public function hookActionObjectProductBeforeAdd($params) {
    $product = $params['object'];
    $product->price = //your computation here
  }
}

The problem is ObjectModel passes the value of $this to the hook, not the reference. You should open 'root/classes/ObjectModel.php' and apply this change:

Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => $this));

becomes

Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => &$this));
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...