Jump to content

Display in module product with price drop


Recommended Posts

Hi I prepare custom module (code in module I pasted under), I would like to display list od product with price drop, I used

Product::getPricesDrop((int)$this->context->language->id, 0, 10);

But I get notice: Notice w linii 2376 w pliku C:\wamp64\www\...\classes\Product.php [8] Trying to get property of non-object; 

Please tell me where I have misteak:

<?php

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

class productofthemonth extends Module {

    public function __construct() {

        $this->name = 'productofthemonth';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Imoli';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
        $this->bootstrap = true;

        parent::__construct();
 
        $this->displayName = $this->l('Product of the month');
        $this->description = $this->l('The module that displays the product of the month with the countdown of time.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
    }

    public function install() {
        if (!parent::install() || 
            !$this->registerHook('displayHeader') ||
            !$this->registerHook('displayTopColumn')
        )
            return false;
        return true;
    }

    public function uninstall() {
        if (!parent::uninstall())
            return false;
        return true;
    }

    public function displayForm() {
        // Get default language
        $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
       
        Product::getPricesDrop((int)$this->context->language->id, 0, 10);


        if ($products) {
             foreach($products as $product) {
                 $options[] = array (
                    'id_option' => $product['id_product'],       // The value of the 'value' attribute of the <option> tag.
                    'name' => $product['name']    // The value of the text content of the  <option> tag.
                 );
             }
            
             // Init Fields form array
             $fields_form[0]['form'] = array(
                 'legend' => array(
                     'title' => $this->l('Settings'),
                 ),
                'input' => array(
                     array(
                         'type' => 'select',                              
                         'label' => $this->l('Product:'),
                         'name' => 'productOFTHEMonth',
                        'required' => false,
                         'options' => array(
                             'query' => $options,
                             'id' => 'id_option', 
                             'name' => 'name'
                         ),
                     )
                 ),
                 'submit' => array(
                     'title' => $this->l('Save'),
                     'class' => 'btn btn-default pull-right'
                 )
             );
            
             $helper = new HelperForm();
            
             // Module, token and currentIndex
             $helper->module = $this;
             $helper->name_controller = $this->name;
             $helper->token = Tools::getAdminTokenLite('AdminModules');
             $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
            
             // Language
             $helper->default_form_language = $default_lang;
             $helper->allow_employee_form_lang = $default_lang;
            
             // Title and toolbar
             $helper->title = $this->displayName;
             $helper->show_toolbar = true;        // false -> remove toolbar
             $helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
             $helper->submit_action = 'submit'.$this->name;
             $helper->toolbar_btn = array(
                 'save' =>
                 array(
                     'desc' => $this->l('Save'),
                     'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
                     '&token='.Tools::getAdminTokenLite('AdminModules'),
                 ),
                 'back' => array(
                     'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
                     'desc' => $this->l('Back to list')
                 )
             );
            
             // Load current value
             $helper->fields_value['productOFTHEMonth'] = Configuration::get('productOFTHEMonth');
            
             return $helper->generateForm($fields_form);
         }
    }

    public function getContent() {

        return $this->displayForm();
    }
}

 

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