Jump to content

Creating module: uploading images via BO


CrossY

Recommended Posts

Hi there,

 

I've created my first module today. Even though it works, I will have to manually edit my images via the FTP, I would like to be able to upload them via the module BO.

 

The current code i'm using is pretty much this from this page: http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module

 

homebuttons.php

<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class homebuttons extends Module
{
  public function __construct()
  {
    $this->name = 'homebuttons';
    $this->tab = 'front_office_features';
    $this->version = '1.0';
    $this->author = 'Dave';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.5.5'); 
    $this->dependencies = array('minicslider');
 
    parent::__construct();
 
    $this->displayName = $this->l('Home Buttons');
    $this->description = $this->l('Displays three clickable buttons on homepage');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('MYMODULE_NAME'))       
      $this->warning = $this->l('No name provided');
  }
	
	
public function install()
{
  if (Shop::isFeatureActive())
    Shop::setContext(Shop::CONTEXT_ALL);
 
  return parent::install() &&
    $this->registerHook('Home') &&
    Configuration::updateValue('MYMODULE_NAME', 'test');
  }	
	
	public function uninstall()
{
  return parent::uninstall() && Configuration::deleteByName('MYMODULE_NAME');
}



public function hookDisplayHome($params)
{
 	$this->context->controller->addCSS($this->_path.'css/homebuttons.css', 'all');
  $this->context->smarty->assign(
      array(
          'my_module_name' => Configuration::get('MYMODULE_NAME'),
          'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display')
      )
  );
  return $this->display(__FILE__, 'homebuttons.tpl');
}
   
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
public function getContent()
{
    $output = null;
 
    if (Tools::isSubmit('submit'.$this->name))
    {
        $my_module_name = strval(Tools::getValue('MYMODULE_NAME'));
        if (!$my_module_name  || empty($my_module_name) || !Validate::isGenericName($my_module_name))
            $output .= $this->displayError( $this->l('Invalid Configuration value') );
        else
        {
            Configuration::updateValue('MYMODULE_NAME', $my_module_name); 
            $output .= $this->displayConfirmation($this->l('Settings updated'));
        }
    }
    return $output.$this->displayForm();
}


public function displayForm()
{
    // Get default Language
    $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
     
    // Init Fields form array
    $fields_form[0]['form'] = array(
        'legend' => array(
            'title' => $this->l('Settings'),
        ),
        'input' => array(
            array(
                'type' => 'text',
                'label' => $this->l('Configuration value'),
                'name' => 'MYMODULE_NAME',
                'size' => 20,
                'required' => true
            )
        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'button'
        )
    );
     
    $helper = new HelperForm();
     
    // Module, t    oken 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['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME');
     
    return $helper->generateForm($fields_form);
}
	
	
}
?>

.tpl file:

<!-- Block homebuttons -->
<div id="homebuttons">
<div class="image1"> <a href="#"><img src="/modules/homebuttons/img/image1.jpg" alt="" />	</a>			 </div>
<div class="image2">	<a href="#"><img src="/modules/homebuttons/img/image2.jpg" alt="" />	</a>			 </div>
<div class="image3">	<a href="#"><img src="/modules/homebuttons/img/image3.jpg" alt="" />	</a>	   	 </div>				</div>
<!-- /Block homebuttons -->

.css file

#homebuttons {
    width: 980px;
    margin-left: auto:
    margin-right: auto;
}

.image1 a, .image2 a, .image3 a {
    border: 0px solid;
    float: left;
    display: block !important;
} 

.image1 a {
    float: left;
    margin-left: 0px;
    margin-right: 0px;
}

Is basically 3 images with a CSS style, and a link for each.

 

 

So how would I go about to:

- Uploading (and overwriting) the images from the module BO

- Change the destination of the link from the module BO

 

Even if you could point me in the right direction (extended tutorial for beginners?) i'd much appreciate it!

 

Regards,

Dave

Edited by CrossY (see edit history)
Link to comment
Share on other sites

  • 1 month later...

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