Jump to content

Event fire when adding new product


Recommended Posts

I am trying to develop a module that listens for a new product add, then prints to screen a message that a new product has added for debug.

I implemented the hook: 

<?php

if (!defined('_PS_VERSION_')) {
    exit;
}

class IZerSync extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'iZerSync';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'LightX';
        $this->need_instance = 1;

        /**
         * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
         */
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('iZerSync');
        $this->description = $this->l('synchronize prestashop with iZer system. ');

        $this->confirmUninstall = $this->l('');

        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        Configuration::updateValue('IZERSYNC_LIVE_MODE', false);

        include(dirname(__FILE__).'/sql/install.php');

        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader') &&
            $this->registerHook('actionOrderDetail') &&
            $this->registerHook('actionOrderSlipAdd') &&
            $this->registerHook('actionOrderStatusUpdate') &&
            $this->registerHook('actionProductAdd') &&
            $this->registerHook('actionProductDelete') &&
            $this->registerHook('actionProductUpdate') &&
            $this->registerHook('actionValidateOrder');
    }

    public function uninstall()
    {
        Configuration::deleteByName('IZERSYNC_LIVE_MODE');

        include(dirname(__FILE__).'/sql/uninstall.php');

        return parent::uninstall();
    }

    /**
    * Add the CSS & JavaScript files you want to be loaded in the BO.
    */
    public function hookBackOfficeHeader()
    {
        if (Tools::getValue('module_name') == $this->name) {
            $this->context->controller->addJS($this->_path.'views/js/back.js');
            $this->context->controller->addCSS($this->_path.'views/css/back.css');
        }
    }

    /**
     * Add the CSS & JavaScript files you want to be added on the FO.
     */
    public function hookHeader()
    {
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }

    public function hookActionProductAdd($prod)
    {
        $test = "testing!";
        /* Place your code here. */
        echo "<script>console.log('$test')</script>";
    }
}

 

but i dont see the test in the console.
Edited by lightx
added code (see edit history)
Link to comment
Share on other sites

When you add/edit a product, Prestashop call to execute hookActionProductAdd, then redirect to another method.

You can change to

public function hookActionProductAdd($prod)
    {
        $test = "testing!";
        echo $test;
		die;
    }

 

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