Jump to content

Another Override Admin Controllers 1.5 Question


Rhapsody

Recommended Posts

In another thread, I had a question on how to make override work for AdminCustomersController.php

Thanks to Terragg, he pointed out the needed fix that required a call back to the AdminController.

 

I have a similar issue trying to override AdminImportController.php - below is the code that does not wok in an override, but work fine if I modify the core code. Any tips here?

 

<?php
class AdminImportController extends AdminImportControllerCore
{
public function __construct()
{
 $this->entities = array(
  $this->l('Categories'),
  $this->l('Products'),
  $this->l('Combinations'),
  $this->l('Customers'),
  $this->l('Addresses'),
  $this->l('Manufacturers'),
  $this->l('Suppliers'),
 );
 // @since 1.5.0
 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
 {
  $this->entities = array_merge(
   $this->entities,
   array(
 $this->l('SupplyOrders'),
 $this->l('SupplyOrdersDetails'),
   )
  );
 }
 $this->entities = array_flip($this->entities);
 switch ((int)Tools::getValue('entity'))
 {
  case $this->entities[$this->l('Combinations')]:
   $this->required_fields = array(
 'id_product',
 'group',
 'attribute'
   );
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id_product' => array('label' => $this->l('Product ID').'*'),
 'group' => array(
  'label' => $this->l('Attribute (Name:Type:Position)').'*'
 ),
 'attribute' => array(
  'label' => $this->l('Value (Value:Position)').'*'
 ),
 'supplier_reference' => array('label' => $this->l('Supplier reference')),
 'reference' => array('label' => $this->l('Reference')),
 'ean13' => array('label' => $this->l('EAN13')),
 'upc' => array('label' => $this->l('UPC')),
 'wholesale_price' => array('label' => $this->l('Wholesale price')),
 'price' => array('label' => $this->l('Impact on price')),
 'ecotax' => array('label' => $this->l('Ecotax')),
 'quantity' => array('label' => $this->l('Quantity')),
 'minimal_quantity' => array('label' => $this->l('Minimal quantity')),
 'weight' => array('label' => $this->l('Impact on weight')),
 'default_on' => array('label' => $this->l('Default (0 = No, 1 = Yes)')),
 'image_position' => array(
  'label' => $this->l('Image position')
 ),
 'image_url' => array('label' => $this->l('Image URL')),
 'delete_existing_images' => array(
  'label' => $this->l('Delete existing images (0 = No, 1 = Yes)')
 ),
 'shop' => array(
  'label' => $this->l('ID / Name of shop'),
  'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, default shop will be used'),
 )
   );
   self::$default_values = array(
 'reference' => '',
 'supplier_reference' => '',
 'ean13' => '',
 'upc' => '',
 'wholesale_price' => 0,
 'price' => 0,
 'ecotax' => 0,
 'quantity' => 0,
 'minimal_quantity' => 1,
 'weight' => 0,
 'default_on' => 0,
   );
  break;
  case $this->entities[$this->l('Categories')]:
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id' => array('label' => $this->l('ID')),
 'active' => array('label' => $this->l('Active (0/1)')),
 'name' => array('label' => $this->l('Name *')),
 'parent' => array('label' => $this->l('Parent category')),
 'is_root_category' => array(
  'label' => $this->l('Root category (0/1)'),
  'help' => $this->l('A category root is where a category tree can begin. This is used with multistore')
  ),
 'description' => array('label' => $this->l('Description')),
 'meta_title' => array('label' => $this->l('Meta-title')),
 'meta_keywords' => array('label' => $this->l('Meta-keywords')),
 'meta_description' => array('label' => $this->l('Meta-description')),
 'link_rewrite' => array('label' => $this->l('URL rewritten')),
 'image' => array('label' => $this->l('Image URL')),
 'shop' => array(
  'label' => $this->l('ID / Name of shop'),
  'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, default shop will be used'),
 ),
   );
   self::$default_values = array(
 'active' => '1',
 'parent' => Configuration::get('PS_HOME_CATEGORY'),
 'link_rewrite' => ''
   );
  break;
  case $this->entities[$this->l('Products')]:
   self::$validators['image'] = array(
 'AdminImportController',
 'split'
   );
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id' => array('label' => $this->l('ID')),
 'active' => array('label' => $this->l('Active (0/1)')),
 'name' => array('label' => $this->l('Name *')),
 'category' => array('label' => $this->l('Categories (x,y,z...)')),
 'price_tex' => array('label' => $this->l('Price tax excl.')),
 'price_tin' => array('label' => $this->l('Price tax incl.')),
 'id_tax_rules_group' => array('label' => $this->l('Tax rules ID')),
 'wholesale_price' => array('label' => $this->l('Wholesale price')),
 'on_sale' => array('label' => $this->l('On sale (0/1)')),
 'reduction_price' => array('label' => $this->l('Discount amount')),
 'reduction_percent' => array('label' => $this->l('Discount percent')),
 'reduction_from' => array('label' => $this->l('Discount from (yyyy-mm-dd)')),
 'reduction_to' => array('label' => $this->l('Discount to (yyyy-mm-dd)')),
 'reference' => array('label' => $this->l('Reference #')),
 'supplier_reference' => array('label' => $this->l('Supplier reference #')),
 'supplier' => array('label' => $this->l('Supplier')),
 'manufacturer' => array('label' => $this->l('Manufacturer')),
 'ean13' => array('label' => $this->l('EAN13')),
 'upc' => array('label' => $this->l('UPC')),
 'ecotax' => array('label' => $this->l('Ecotax')),
 'weight' => array('label' => $this->l('Weight')),
 'quantity' => array('label' => $this->l('Quantity')),
 'description_short' => array('label' => $this->l('Short description')),
 'description' => array('label' => $this->l('Description')),
 'tags' => array('label' => $this->l('Tags (x,y,z...)')),
 'meta_title' => array('label' => $this->l('Meta-title')),
 'meta_keywords' => array('label' => $this->l('Meta-keywords')),
 'meta_description' => array('label' => $this->l('Meta-description')),
 'link_rewrite' => array('label' => $this->l('URL rewritten')),
 'available_now' => array('label' => $this->l('Text when in stock')),
 'available_later' => array('label' => $this->l('Text when backorder allowed')),
 'available_for_order' => array('label' => $this->l('Available for order (0 = No, 1 = Yes)')),
 'date_add' => array('label' => $this->l('Product creation date')),
 'show_price' => array('label' => $this->l('Show price (0 = No, 1 = Yes)')),
 'image' => array('label' => $this->l('Image URLs (x,y,z...)')),
 'delete_existing_images' => array(
  'label' => $this->l('Delete existing images (0 = No, 1 = Yes)')
 ),
 'features' => array('label' => $this->l('Feature(Name:Value:Position)')),
 'online_only' => array('label' => $this->l('Available online only (0 = No, 1 = Yes)')),
 'condition' => array('label' => $this->l('Condition')),
 'shop' => array(
  'label' => $this->l('ID / Name of shop'),
  'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, default shop will be used'),
 )
   );
   self::$default_values = array(
 'id_category' => array((int)Configuration::get('PS_HOME_CATEGORY')),
 'id_category_default' => (int)Configuration::get('PS_HOME_CATEGORY'),
 'active' => '1',
 'quantity' => 0,
 'price' => 0,
 'id_tax_rules_group' => 0,
 'description_short' => array((int)Configuration::get('PS_LANG_DEFAULT') => ''),
 'link_rewrite' => array((int)Configuration::get('PS_LANG_DEFAULT') => ''),
 'online_only' => 0,
 'condition' => 'new',
 'date_add' => date('Y-m-d H:i:s'),
 'condition' => 'new',
   );
  break;
  case $this->entities[$this->l('Customers')]:
   //Overwrite required_fields AS only email is required whereas other entities
   $this->required_fields = array('email', 'passwd', 'lastname', 'firstname');
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id' => array('label' => $this->l('ID')),
 'active' => array('label' => $this->l('Active  (0/1)')),
 'id_gender' => array('label' => $this->l('Titles ID (Mr = 1, Ms = 2, else 0)')),
 'email' => array('label' => $this->l('E-mail *')),
 'passwd' => array('label' => $this->l('Password *')),
 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')),
 'lastname' => array('label' => $this->l('Lastname *')),
 'firstname' => array('label' => $this->l('Firstname *')),
 'newsletter' => array('label' => $this->l('Newsletter (0/1)')),
 'optin' => array('label' => $this->l('Opt-in (0/1)')),
 'spouse' => array('label' => $this->l('Spouse Name')),
 'yachtclub' => array('label' => $this->l('YC Name')),
 'boat' => array('label' => $this->l('Boat Name')),
 'model' => array('label' => $this->l('Boat Model')),
 'sailnum' => array('label' => $this->l('Sail Number')),
 'phrfspin' => array('label' => $this->l('PHRF Spinnaker')),
 'phrfnonspin' => array('label' => $this->l('PHRF Non-Spinnaker')),
 'note' => array('label' => $this->l('Notes')),
 'id_shop' => array(
  'label' => $this->l('ID / Name of shop'),
  'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, default shop will be used'),
 ),
   );
   self::$default_values = array(
 'active' => '1',
 'id_shop' => Configuration::get('PS_SHOP_DEFAULT'),
   );
  break;
  case $this->entities[$this->l('Addresses')]:
   //Overwrite required_fields
   $this->required_fields = array(
 'lastname',
 'firstname',
 'address1',
 'postcode',
 'country',
 'customer_email',
 'city'
   );
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id' => array('label' => $this->l('ID')),
 'alias' => array('label' => $this->l('Alias *')),
 'active' => array('label' => $this->l('Active  (0/1)')),
 'customer_email' => array('label' => $this->l('Customer e-mail')),
 'id_customer' => array('label' => $this->l('Customer ID')),
 'manufacturer' => array('label' => $this->l('Manufacturer')),
 'supplier' => array('label' => $this->l('Supplier')),
 'company' => array('label' => $this->l('Company')),
 'lastname' => array('label' => $this->l('Lastname *')),
 'firstname' => array('label' => $this->l('Firstname *')),
 'address1' => array('label' => $this->l('Address 1 *')),
 'address2' => array('label' => $this->l('Address 2')),
 'postcode' => array('label' => $this->l('Postcode*/ Zipcode*')),
 'city' => array('label' => $this->l('City *')),
 'country' => array('label' => $this->l('Country *')),
 'state' => array('label' => $this->l('State')),
 'other' => array('label' => $this->l('Other')),
 'phone' => array('label' => $this->l('Phone')),
 'phone_mobile' => array('label' => $this->l('Mobile Phone')),
 'vat_number' => array('label' => $this->l('VAT number')),
   );
   self::$default_values = array(
 'alias' => 'Alias',
 'postcode' => 'X'
   );
  break;
  case $this->entities[$this->l('Manufacturers')]:
  case $this->entities[$this->l('Suppliers')]:
   //Overwrite validators AS name is not MultiLangField
   self::$validators = array(
 'description' => array('AdminImportController', 'createMultiLangField'),
 'short_description' => array('AdminImportController', 'createMultiLangField'),
 'meta_title' => array('AdminImportController', 'createMultiLangField'),
 'meta_keywords' => array('AdminImportController', 'createMultiLangField'),
 'meta_description' => array('AdminImportController', 'createMultiLangField'),
   );
   $this->available_fields = array(
 'no' => array('label' => $this->l('Ignore this column')),
 'id' => array('label' => $this->l('ID')),
 'active' => array('label' => $this->l('Active (0/1)')),
 'name' => array('label' => $this->l('Name *')),
 'description' => array('label' => $this->l('Description')),
 'short_description' => array('label' => $this->l('Short description')),
 'meta_title' => array('label' => $this->l('Meta-title')),
 'meta_keywords' => array('label' => $this->l('Meta-keywords')),
 'meta_description' => array('label' => $this->l('Meta-description')),
 'shop' => array(
  'label' => $this->l('ID / Name of group shop'),
  'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, default shop will be used'),
 ),
   );
   self::$default_values = array(
 'shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')),
   );
  break;
  // @since 1.5.0
  case $this->entities[$this->l('SupplyOrders')]:
   if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
   {
 // required fields
 $this->required_fields = array(
  'id_supplier',
  'id_warehouse',
  'reference',
  'date_delivery_expected',
 );
 // available fields
 $this->available_fields = array(
  'no' => array('label' => $this->l('Ignore this column')),
  'id' => array('label' => $this->l('ID')),
  'id_supplier' => array('label' => $this->l('Supplier ID *')),
  'id_lang' => array('label' => $this->l('Lang ID')),
  'id_warehouse' => array('label' => $this->l('Warehouse ID *')),
  'id_currency' => array('label' => $this->l('Currency ID *')),
  'reference' => array('label' => $this->l('Supply Order Reference *')),
  'date_delivery_expected' => array('label' => $this->l('Delivery Date (Y-M-D)*')),
  'discount_rate' => array('label' => $this->l('Discount Rate')),
  'is_template' => array('label' => $this->l('Template')),
 );
 // default values
 self::$default_values = array(
  'id_lang' => (int)Configuration::get('PS_LANG_DEFAULT'),
  'id_currency' => Currency::getDefaultCurrency()->id,
  'discount_rate' => '0',
  'is_template' => '0',
 );
   }
  break;
  // @since 1.5.0
  case $this->entities[$this->l('SupplyOrdersDetails')]:
   if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
   {
 // required fields
 $this->required_fields = array(
  'supply_order_reference',
  'id_product',
  'unit_price_te',
  'quantity_expected',
 );
 // available fields
 $this->available_fields = array(
  'no' => array('label' => $this->l('Ignore this column')),
  'supply_order_reference' => array('label' => $this->l('Supply Order Reference *')),
  'id_product' => array('label' => $this->l('Product ID *')),
  'id_product_attribute' => array('label' => $this->l('Product Attribute ID')),
  'unit_price_te' => array('label' => $this->l('Unit Price (tax excl.)*')),
  'quantity_expected' => array('label' => $this->l('Quantity Expected *')),
  'discount_rate' => array('label' => $this->l('Discount Rate')),
  'tax_rate' => array('label' => $this->l('Tax Rate')),
 );
 // default values
 self::$default_values = array(
  'discount_rate' => '0',
  'tax_rate' => '0',
 );
   }
 }
 $this->separator = strval(trim(Tools::getValue('separator', ';')));
 if (is_null(Tools::getValue('multiple_value_separator')) || trim(Tools::getValue('multiple_value_separator')) == '')
  $this->multiple_value_separator = ',';
 else
  $this->multiple_value_separator = Tools::getValue('multiple_value_separator');
 parent::__construct();
}
}

Link to comment
Share on other sites

Where exactly does it go wrong/What exactly goes wrong?

I suspect that you should call the "parent::__construct();" BEFORE you do your stuff.

 

Alternatively, when you override the destruct, first destroy your added stuff, then at the end, call the parent's destroy.

The override does not appear to do anything. It is supposed to add extra fields for import on customers and addresses. It does work fine if I modify the core BO with the same code.

 

All I did was take the

public function __construct()

from the core and inserted it into the override file with the new fields to import.

 

I tried moving the "parent::__construct();" in the beginning after

public function __construct()
{

but that did not work.

 

I'm not sure what you mean about "when you override the destruct, first destroy your added stuff, then at the end, call the parent's destroy".

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

 

The override does not appear to do anything. It is supposed to add extra fields for import on customers and addresses. It does work fine if I modify the core BO with the same code.

 

All I did was take the

public function __construct()

from the core and inserted it into the override file with the new fields to import.

 

I tried moving the "parent::__construct();" in the beginning after

public function __construct()
{

but that did not work.

 

I'm not sure what you mean about "when you override the destruct, first destroy your added stuff, then at the end, call the parent's destroy".

 

Hi,

Sorry for confusion. I should have just asked for the symptoms, not guessing what went wrong...

If it doesn't do anything, please double check where you put your file. Can't recall exactly, but see docs.prestashop.com and go to developers guide. There they tell in detail where to put it.

Also, please tell us where you put it, so we can check it out ourselves.

 

The destruct comment was similar to construct comment, first destroy your added stuff in the overridden __destroy function, then call parent's destroy after this. Sorry for confusion ("alternatively" was badly chosen word here)

 

So let us know where you put the file, so we can check it out. Thx.

Pascal

 

NB what presta version do you use?

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

.....

Also, please tell us where you put it, so we can check it out ourselves.

 

\override\controllers\admin\

 

.....

NB what presta version do you use?

1.5.3.1

 

Thanks for the follow up. If you are able to find something I need to change, I'm game to try it. I have done other controller overrides for both admin and front that are working fine. This one has me stumped.

Link to comment
Share on other sites

\override\controllers\admin\

 

 

1.5.3.1

 

Thanks for the follow up. If you are able to find something I need to change, I'm game to try it. I have done other controller overrides for both admin and front that are working fine. This one has me stumped.

 

Hi Rhapsody,

I am not behind my computer now, so I cannot check anything yet, but if I see Terrag's reply to your other question, I just wanted to double check if you already tried a similar solution as Terrag's, by using :

 

AdminController::__construct();

 

instead of parent::__construct(); ?

 

I sounds similar to the other problem, that the parent::__construct() voids any changes you made in your overriding function. I expect you tried this already, but just to make sure, so we don't have to try this option ourselves.

 

Sorry, no crystal clear solution yet...

Pascal

  • Like 1
Link to comment
Share on other sites

Hi Rhapsody,

I am not behind my computer now, so I cannot check anything yet, but if I see Terrag's reply to your other question, I just wanted to double check if you already tried a similar solution as Terrag's, by using :

 

AdminController::__construct();

 

instead of parent::__construct(); ?

 

I sounds similar to the other problem, that the parent::__construct() voids any changes you made in your overriding function. I expect you tried this already, but just to make sure, so we don't have to try this option ourselves.

 

Sorry, no crystal clear solution yet...

Pascal

Yes - I did try the AdminController::__construct(); change to replace parent::__construct();

This was tried with it in the location shown in the script from my 1st post, and moving it to the top immediately before

public function __construct()

Link to comment
Share on other sites

  • 2 months later...

Hello,

 

i can't override AdminTagsController.php in the Prestashop 1.5.4 ...

 

www/override/controllers/admin/AdminTagsController.php

class AdminTagsController extends AdminTagsControllerCore
{
   public function __construct()
   {
    parent::__construct();
    ....
   }
}

Link to comment
Share on other sites

Hello Airclic,

 

Have a look in cache->cachefs->class_index.php

 

  'AdminTagsControllerCore' => 'controllers/admin/AdminTagsController.php',
 'AdminTagsController' => '',

 

  'AdminTagsController' => 'override/controllers/admin/AdminTagsController.php',

 

Qu'est-ce que tu veux faire ?

Edited by indesign (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 11 months later...
  • 3 years later...

Hi Rhapsody,

I am not behind my computer now, so I cannot check anything yet, but if I see Terrag's reply to your other question, I just wanted to double check if you already tried a similar solution as Terrag's, by using :

 

AdminController::__construct();

 

instead of parent::__construct(); ?

 

I sounds similar to the other problem, that the parent::__construct() voids any changes you made in your overriding function. I expect you tried this already, but just to make sure, so we don't have to try this option ourselves.

 

Sorry, no crystal clear solution yet...

Pascal

 

 

Just wanna confirm that the above works for me. So do we need to change all "parent::" to "AdminController::" if it appears in the original code?

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