4

I would like to monitor which dashboard user ("admin") added new product to the database.

The solution i was thinking about is simply adding another insert under admin > model > catalog > product.tpl under function addProduct(), which adds the user id to the custom column added before under oc_product.

$userID = // currently logged in

public function addProduct($data) {

$this->event->trigger('pre.admin.product.add', $data);

$this->db->query("INSERT INTO " . DB_PREFIX . "product SET addedby = $userID, .......");

.......

}

The only problem I have now is how to call / get the currently logged admin id inside this file (model/catalog/product.tpl).

This is just how i think about it, if this idea is completely wrong, please do write some better solutions.

devbull
  • 227
  • 1
  • 4
  • 16

2 Answers2

5

It would be better if you create another table to store this information since it will save you from altering the core table. In new table you store the user_id and product_id and set product_id as primary key. Now you will be able to fetch this data as you require by joining these two tables ON basis of product_id match.

elembivos
  • 399
  • 2
  • 14
  • I don't think that this is a good idea, there is no problem at all in altering the DB schema because he is already altering the core of OC, besides that, product to admin is a 1-2-1 relationship and does not require extra tables, an extra table means a slower insertion, and retrieval, what do you think? – Abdo Adel Feb 13 '15 at 11:15
  • 4
    I suggested this idea because altering of core code can be easily neglected by using **vqmod** however with core tables it is not possible. Changing core tables sometimes raises complexities while modifying something big. However you are right about slower insertion and retrieval. But there are tables such as product_option, product_discount, product_related so having another table as product_owner can't be wrong as it seems to me. – elembivos Feb 13 '15 at 11:51
3
  • The idea is correct (at least for me, this is how I was going to do it)
  • You can get the id of the currently logged-in admin through a call to $this->user->getId()
  • Add this code fragment $userID = $this->user->getId() inside the addProduct function, not inside the class declaration
  • There is no such a column named added_by in product table, you will have to alter the table structure and add it
Abdo Adel
  • 1,177
  • 2
  • 17
  • 30