Jump to content

No puedo modificar un proveedor,


pablobuendiaelvira

Recommended Posts

Hola a todos,

 

Quiero modificar un proveedor que tengo guardado en mi BBDD y a la hora de hacerlo me aparecen todos los campos en blanco, como si se crease nuevo.

 

He añadido algunos campos que necesitaba y he modificado el archivo supplier.php

class SupplierCore extends ObjectModel
{
    public $id;

    /** @var int supplier ID */
    public $id_supplier;

    /** @var string Name */
    public $name;

    public $telefonoContacto;
    public $email;
    public $personaContacto;
    public $cif;
    public $nombreFiscal;
    public $direccionFiscal;


    /** @var string A short description for the discount */
    public $description;

    /** @var string Object creation date */
    public $date_add;

    /** @var string Object last modification date */
    public $date_upd;

    /** @var string Friendly URL */
    public $link_rewrite;

    /** @var string Meta title */
    public $meta_title;

    /** @var string Meta keywords */
    public $meta_keywords;

    /** @var string Meta description */
    public $meta_description;

    /** @var bool active */
    public $active;

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
        'table' => 'supplier',
        'primary' => 'id_supplier',
        'multilang' => true,
        'fields' => array(
            'name' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
            'telefonoContacto' =>       array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 9),
            'email' =>         array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 100),
            'personaContacto' =>    array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 100),
            'cif' =>        array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 10),
            'nombreFiscal' =>   array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 100),
            'direccionFiscal' =>    array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 150),            
            'active' =>            array('type' => self::TYPE_BOOL),
            'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
            'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate'),

            /* Lang fields */
            'description' =>        array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
            'meta_title' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
            'meta_description' =>    array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
            'meta_keywords' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
        ),
    ); 

Luego he modificado el archivo supplier.tpl quedándome así:

{include file="$tpl_dir./errors.tpl"}

{if !isset($errors) OR !sizeof($errors)}
	<h1 class="page-heading product-listing">
		{l s='List of products by supplier:'} {$supplier->name|escape:'html':'UTF-8'}
	</h1>
	{if !empty($supplier->description)}
		<div class="description_box rte">
			<p>{$supplier->description}</p>
		</div>
	{/if}
	
	{if $supplier->telefonoContacto}
				<div id="telefonoContacto" class="rte align_justify" itemprop="telefonoContacto">{$supplier->telefonoContacto}</div>
	{/if}

	{if $supplier->email}
				<div id="email" class="rte align_justify" itemprop="email">{$supplier->email}</div>
	{/if}

	{if $supplier->personaContacto}
				<div id="personaContacto" class="rte align_justify" itemprop="personaContacto">{$supplier->personaContacto}</div>
	{/if}

	{if $supplier->cif}
				<div id="cif" class="rte align_justify" itemprop="cif">{$supplier->cif}</div>
	{/if}

	{if $supplier->direccionFiscal
				<div id="direccionFiscal" class="rte align_justify" itemprop="direccionFiscal">{$supplier->direccionFiscal}</div>
	{/if}

	{if $supplier->nombreFiscal}
				<div id="nombreFiscal" class="rte align_justify" itemprop="nombreFiscal">{$supplier->nombreFiscal}</div>
	{/if}

	{if $products}
		<div class="content_sortPagiBar">
	    	<div class="sortPagiBar clearfix">
				{include file="./product-sort.tpl"}
				{include file="./nbr-product-page.tpl"}
			</div>
	    	<div class="top-pagination-content clearfix">
	        	{include file="./product-compare.tpl"}
	            {include file="$tpl_dir./pagination.tpl" no_follow=1}
	        </div>
		</div>

Y por último he modificado el archivo AdminSupplierController.php quedándome así:

 public function renderForm()
    {
        // loads current warehouse
        if (!($obj = $this->loadObject(true))) {
            return;
        }

        $image = _PS_SUPP_IMG_DIR_.$obj->id.'.jpg';
        $image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
            $this->imageType, true, true);
        $image_size = file_exists($image) ? filesize($image) / 1000 : false;

        $tmp_addr = new Address();
        $res = $tmp_addr->getFieldsRequiredDatabase();
        $required_fields = array();
        foreach ($res as $row) {
            $required_fields[(int)$row['id_required_field']] = $row['field_name'];
        }

        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Suppliers'),
                'icon' => 'icon-truck'
            ),
            'input' => array(
                array(
                    'type' => 'hidden',
                    'name' => 'id_address',
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Name'),
                    'name' => 'name',
                    'required' => true,
                    'col' => 4,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                ),
                (in_array('company', $required_fields) ?
                    array(
                        'type' => 'text',
                        'label' => $this->l('Company'),
                        'name' => 'company',
                        'display' => in_array('company', $required_fields),
                        'required' => in_array('company', $required_fields),
                        'maxlength' => 16,
                        'col' => 4,
                        'hint' => $this->l('Company name for this supplier')
                    )
                    : null
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Description'),
                    'name' => 'description',
                    'lang' => true,
                    'hint' => array(
                        $this->l('Invalid characters:').' <>;=#{}',
                        $this->l('Will appear in the list of suppliers.')
                    ),
                    'autoload_rte' => 'rte' //Enable TinyMCE editor for short description
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('TelefonoContacto'),
                    'name' => 'telefonoContacto',
                    'required' => in_array('telefonoContacto', $required_fields),
                    'maxlength' => 9,
                    'col' => 4,
                    'hint' => $this->l('Phone number for contact this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('email'),
                    'name' => 'email',
                    'required' => in_array('email', $required_fields),
                    'maxlength' => 100,
                    'col' => 4,
                    'hint' => $this->l('Email for this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('PersonaContacto'),
                    'name' => 'personaContacto',
                    'required' => in_array('personaContacto', $required_fields),
                    'maxlength' => 100,
                    'col' => 4,
                    'hint' => $this->l('Person contact for this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('cif'),
                    'name' => 'cif',
                    'required' => in_array('cif', $required_fields),
                    'maxlength' => 10,
                    'col' => 4,
                    'hint' => $this->l('cif for this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('Direccion Fiscal'),
                    'name' => 'direccionFiscal',
                    'required' => in_array('direccionFiscal', $required_fields),
                    'maxlength' => 150,
                    'col' => 4,
                    'hint' => $this->l('Fiscal address for this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('Nombre Fiscal'),
                    'name' => 'nombreFiscal',
                    'required' => in_array('nombreFiscal', $required_fields),
                    'maxlength' => 100,
                    'col' => 4,
                    'hint' => $this->l('Fiscal name for this supplier')
                ),

                array(
                    'type' => 'text',
                    'label' => $this->l('Phone'),
                    'name' => 'phone',
                    'required' => in_array('phone', $required_fields),
                    'maxlength' => 16,
                    'col' => 4,
                    'hint' => $this->l('Phone number for this supplier')
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Mobile phone'),
                    'name' => 'phone_mobile',
                    'required' => in_array('phone_mobile', $required_fields),
                    'maxlength' => 16,
                    'col' => 4,
                    'hint' => $this->l('Mobile phone number for this supplier.')
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Address'),
                    'name' => 'address',
                    'maxlength' => 128,
                    'col' => 6,
                    'required' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Address').' (2)',
                    'name' => 'address2',
                    'required' => in_array('address2', $required_fields),
                    'col' => 6,
                    'maxlength' => 128,
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Zip/postal code'),
                    'name' => 'postcode',
                    'required' => in_array('postcode', $required_fields),
                    'maxlength' => 12,
                    'col' => 2,
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('City'),
                    'name' => 'city',
                    'maxlength' => 32,
                    'col' => 4,
                    'required' => true,
                ),
                array(
                    'type' => 'select',
                    'label' => $this->l('Country'),
                    'name' => 'id_country',
                    'required' => true,
                    'col' => 4,
                    'default_value' => (int)$this->context->country->id,
                    'options' => array(
                        'query' => Country::getCountries($this->context->language->id, false),
                        'id' => 'id_country',
                        'name' => 'name',
                    ),
                ),
                array(
                    'type' => 'select',
                    'label' => $this->l('State'),
                    'name' => 'id_state',
                    'col' => 4,
                    'options' => array(
                        'id' => 'id_state',
                        'query' => array(),
                        'name' => 'name'
                    )
                ),
                array(
                    'type' => 'file',
                    'label' => $this->l('Logo'),
                    'name' => 'logo',
                    'display_image' => true,
                    'image' => $image_url ? $image_url : false,
                    'size' => $image_size,
                    'hint' => $this->l('Upload a supplier logo from your computer.')
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta title'),
                    'name' => 'meta_title',
                    'lang' => true,
                    'col' => 4,
                    'hint' => $this->l('Forbidden characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta description'),
                    'name' => 'meta_description',
                    'lang' => true,
                    'col' => 6,
                    'hint' => $this->l('Forbidden characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'tags',
                    'label' => $this->l('Meta keywords'),
                    'name' => 'meta_keywords',
                    'lang' => true,
                    'col' => 6,
                    'hint' => array(
                        $this->l('To add "tags" click in the field, write something and then press "Enter".'),
                        $this->l('Forbidden characters:').' <>;=#{}'
                    )
                ),
                array(
                    'type' => 'switch',
                    'label' => $this->l('Enable'),
                    'name' => 'active',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => array(
                        array(
                            'id' => 'active_on',
                            'value' => 1,
                            'label' => $this->l('Enabled')
                        ),
                        array(
                            'id' => 'active_off',
                            'value' => 0,
                            'label' => $this->l('Disabled')
                        )
                    )
                )
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            )
        );

        // loads current address for this supplier - if possible
        $address = null;
        if (isset($obj->id)) {
            $id_address = Address::getAddressIdBySupplierId($obj->id);

            if ($id_address > 0) {
                $address = new Address((int)$id_address);
            }
        }

        // force specific fields values (address)
        if ($address != null) {
            $this->fields_value = array(
                'id_address' => $address->id,
                'telefonoContacto' => $address->telefonoContacto,
                'email' => $address->email,
                'personaContacto' => $address->personaContacto,
                'cif' => $address->cif,
                'direccionFiscal' => $address->direccionFiscal,
                'nombreFiscal' => $nombreFiscal->nombreFiscal,
                'phone' => $address->phone,
                'phone_mobile' => $address->phone_mobile,
                'address' => $address->address1,
                'postcode' => $address->postcode,
                'city' => $address->city,
                'id_country' => $address->id_country,
                'id_state' => $address->id_state,
            );        
        } else {
            $this->fields_value = array(
                'id_address' => 0,
                'id_country' => Configuration::get('PS_COUNTRY_DEFAULT')
            );
        }


        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array(
                'type' => 'shop',
                'label' => $this->l('Shop association'),
                'name' => 'checkBoxShopAsso',
            );
        }

        return parent::renderForm();
    }

    /**
     * AdminController::initToolbar() override
     * @see AdminController::initToolbar()
     *
     */

Por qué ahora no puedo modificar un proveedor??

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