Jump to content
thirty bees forum

Product list BO with manufacturers and suppliers columns


zimmer-media

Recommended Posts

From the PS forum I have extended the product list with the columns for manufacturers and suppliers. Adapted to TB programming. Either: controllers / admin / AdminProductsController.php or via override override / controllers / admin / AdminProductsController.php

As an an example (german text on image):

0_1513384576213_6f758b72-5da5-4d16-9589-97803f5fec5f-grafik.png

The customized file 01513384537636AdminProductsController.php

Link to comment
Share on other sites

Here you can see the changed code. If it is not completely needed, you can eg omit the lines and the array for the manufacturer or the supplier.

original part 1

``` $idShop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXTSHOP ? (int) $this->context->shop->id : 'a.idshopdefault'; $this->join .= ' JOIN '._DB_PREFIX_.'product_shop sa ON (a.id_product = sa.id_product AND sa.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON ('.$alias.'.id_category_default = cl.id_category AND b.id_lang = cl.id_lang AND cl.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'shop shop ON (shop.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'image_shop imageshop ON (imageshop.id_product = a.id_product AND imageshop.cover = 1 AND imageshop.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_image = image_shop.id_image) LEFT JOIN '._DB_PREFIX_.'product_download pd ON (pd.id_product = a.id_product AND pd.active = 1)';

new $idShop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXTSHOP ? (int) $this->context->shop->id : 'a.idshopdefault'; $this->join .= ' JOIN '._DB_PREFIX_.'product_shop sa ON (a.id_product = sa.id_product AND sa.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON ('.$alias.'.id_category_default = cl.id_category AND b.id_lang = cl.id_lang AND cl.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'shop shop ON (shop.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'image_shop imageshop ON (imageshop.id_product = a.id_product AND imageshop.cover = 1 AND imageshop.idshop = '.$idShop.') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_image = imageshop.id_image) LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = a.id_manufacturer) LEFT JOIN '._DB_PREFIX_.'supplier supp ON (supp.idsupplier = a.id_supplier) LEFT JOIN '._DB_PREFIX_.'product_download pd ON (pd.id_product = a.id_product AND pd.active = 1)'; ```

original part 2

$this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= $aliasImage.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`'; new $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, '; $this->_select .= 'm.`name` AS `manufacturer_namen`, '; $this->_select .= 'shop.name as shopname, supp.`name` AS `supp`, '; $this->_select .= $aliasImage.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';

original part 3 ``` $this->fieldslist['active'] = [ 'title' => $this->l('Status'), 'active' => 'status', 'filterkey' => $alias.'!active', 'align' => 'text-center', 'type' => 'bool', 'class' => 'fixed-width-sm', 'orderby' => false, ];

    if ($joinCategory && (int) $this->id_current_category) {
        $this->fields_list['position'] = [
            'title'      => $this->l('Position'),
            'filter_key' => 'cp!position',
            'align'      => 'center',
            'position'   => 'position',
        ];

```

new ``` $this->fieldslist['active'] = [ 'title' => $this->l('Status'), 'active' => 'status', 'filterkey' => $alias.'!active', 'align' => 'text-center', 'type' => 'bool', 'class' => 'fixed-width-sm', 'orderby' => false, ];

    $this->fields_list['manufacturer_namen'] = [
        'title'      => $this->l('Manufacturer'),
        'filter_key' => 'm!name',
        'orderby'    => true,
    ];

    $this->fields_list['supp'] = [
        'title' => $this->l('Supplier'),
        'filter_key' => 'supp!name'
    ];

    if ($joinCategory && (int) $this->id_current_category) {
        $this->fields_list['position'] = [
            'title'      => $this->l('Position'),
            'filter_key' => 'cp!position',
            'align'      => 'center',
            'position'   => 'position',
        ];

```

Link to comment
Share on other sites

  • 10 months later...

@traumflug said in Product list BO with manufacturers and suppliers columns:

Why not? PageCache has its flaws, but the other cache systems should work just fine. Even for development I keep Smarty cache turned on, with “recompile if something has changed”.

It's a sandbox. I have no TB installation in production right now. I'm going to follow your advice for "recompile if something has changed".

Link to comment
Share on other sites

  • 7 months later...

Ok I was looking at this from Nemo's website.  Which he did the core file in his demo.  This post helped me figure out how to do the override..  Now the question is and I think I know the answer.  How do you do Multiple overrides to the same controller?  Example I have a module that needs to write out config to the Overridden file but it can't.

So in general you are you only allowed to override one controller one time or only in on file named the same thing?

Example controllers / admin / AdminProductsController.php or via override override / controllers / admin / AdminProductsController.php  we do this Manufacturer Change.  

The module wants to write to same file name.  It can't.

It seems you can't just create the file named  / controllers / admin / AdminProductsControllerMan.php

then create the class inside the file as.

class AdminProductsControllerMan extends AdminControllerCore 

Or can you and I am doing it incorrectly?  Not a coder. 

Link to comment
Share on other sites

It's really hard to understand your question. Not sure if I got it right. You want to use AdminProductsController.php in the override folder and in a module? I dont know what happens when multiple "places" try to override it. Once I read, that ps was trying to combine this files into one. Not sure if this is still true. Maybe @Traumflug can answer it!?

But in general I believe you are using too much overrides. In a module I try to avoid every override. I only use override very few times if I really need to change the core. What are you tryiing to achieve? If you want to change lists from a module, you can use some hooks like hookActionAdminProductsListingFieldsModifier.

Link to comment
Share on other sites

I bet.  It's hard to explain since I don't fully understand what overrides are for and their limitations.  Let me try again.

We will use the Manufacturer example.

The core system doesn't have this feature in it already E.G. you can't filter by manufacturer.  Since its not in the Core system we have 2 choices add it to the core file or create and override?  The first not a good solution since core files are overwritten by upgrade. So that leaves us with Overrides.  (Of course the other option is have it added by someone to the core system.)

So we do the override and it works.. All is great until...  We need to add more functionality to the same Controller E.G. AdminProductsController.php . How do we do this safely and correctly? Are we allowed to create AdminProductsController2.php , AdminProductsController3.php and so on?

In short how do we best add more functionality to the system.

Edited by Factor
Link to comment
Share on other sites

4 hours ago, Factor said:

add it to the core file or create and override?

Create override if no other solution is there. Never change core files. -> You got that right.

4 hours ago, Factor said:

We need to add more functionality to the same Controller E.G. AdminProductsController.php . How do we do this safely and correctly?

There is no need for a second file. As you can make all changes in this one file. Are you talking about the same function or different function? You can add different function into the override. You can even add function which aren't in the original core file.

Link to comment
Share on other sites

2 minutes ago, wakabayashi said:

Never change core files. -> You got that right.

I am trainable...

2 minutes ago, wakabayashi said:

no need for a second file.

Ok great.  what if someone writes a module that needs to write to my same override file.  The install fails and states 

image.png.70037639455f6def5c245ca225e99b4a.png

I have to figure out how to update my override manually?

5 minutes ago, wakabayashi said:

You can even add function which aren't in the original core file.

Got it.  However maintaining one file when you might have either multiple modules or multiple additions to the same controller file is not very modular in design. 😎 I think though you answered my questions. 

 

Which will actually lead to more questions...

Link to comment
Share on other sites

Yeah that's the heavy issue how have now. You try to override two times the same function. I believe that's just not possible to handle. At least I can't imagine how this could be handled.

Which module is doing the override? In general you should now bring this two function overrides together into one function. Probably you need to go like this:

- remove _displaySpecificPriceModificationForm from AdminProductsController.php
- install the module (which will probably add this function back into the AdminProductsController.php)
- Add the functionality, which you removed in step 1.

Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

This clutters up my product list too much, I have 17,700+ products and even when viewing via category it extends the list too far to the right so I can't see the "edit" buttons without collapsing the admin panel (on the left) ... very little consideration for the UI/UX when folks make things like this hardcoded in the distribution files.

Just my .02 worth!

Link to comment
Share on other sites

  • 1 month later...
On 10/2/2023 at 4:37 PM, Obi said:

This clutters up my product list too much, I have 17,700+ products and even when viewing via category it extends the list too far to the right so I can't see the "edit" buttons without collapsing the admin panel (on the left) ... very little consideration for the UI/UX when folks make things like this hardcoded in the distribution files.

Just my .02 worth!

How was the product list in PS? I guess exactly the same if I remember correctly?

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