Jump to content

appropriate use of delete() function


sicine
 Share

Recommended Posts

hello everyone, i'm developing a module where I have to to add my products to an other table 'products' in my prestashop  database. well i did it using the AddProduct hook  and it works perfectly. now I want to work on the delete function. i tried to do the same thing  with the appropriate hook but the product is not deleted from the products  table.

 

NB: my 'products' table does not have any prefix

 

this is my hookDeleteProduct function :

public function hookDeleteProduct($params)
	{
	  	if (!isset($params['product']->id))
			return false;

		$id_product = (int)$params['product']->id;
		
		$sql = 'DELETE FROM products WHERE ID ='.$id_product ;
		Db::getInstance()->execute($sql);
				
	} 

please  help 

Edited by sicine (see edit history)

Share this post


Link to post
Share on other sites

Assumuming that you add a $this->registerHook('actionObjectProductDeleteAfter') in the module's install() method (and reset or uninstall/install the module before testing) I would probably be tempted to use:

public function hookActionObjectProductDeleteAfter($params)
    {
        $product = $params['object'];
        
        if ($product instanceof Product)
            Db::getInstance()->execute('DELETE FROM products WHERE ID ='.$product->id);  
    } 
Edited by Paul C (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Can you post an export of the table  structure? Have you looked in the server error log to see if there's an error?

 

The reason I mention an uninstall/install is because people often forget that the registerHook() call is only made during an install, so you can't add extra functions to a module that's already installed and expect them to work ;)

  • Like 1

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More