Add extra field to product selection in admin orders



  • Hi everyone,

    I’ve been struggling to make an extra field visible in the dropdown box that shows up after searching for a product to add in the admin order view.

    I’m pretty new to Thirty Bees but managed to add my own fields to products, product lists, imports etc. But I can’t seem to figure this out.

    Any help is much appreciated.



  • No one who’s had the same need at some point?



  • Could you please describe the issue more in in detail? I don’t understand what you mean with extra field. Do you have coded a module?



  • I have made a “title” field on my products. I sell vinyl records and CD’s, and the product name is the artist, and my custom title field is the name of their record. Because of this I have severals product with the same name. When I then search for products to add when creating orders in the back office, I get multiple results with same name. That’s why it would nice to add my title field to the results. Hope it makes sense.



  • Why do just write the artist as product name? I would do it like that: artist - album name



  • @b_otho

    I join the comment from @wakabayashi. My additional recommendation to deposit the artist in the article features and then set up as a filter for the end user. You may also set up and enter additional features such as the type of disc CD / DVD / LP, etc.



  • @b_otho

    Alternatively, I do not know if you need, for example, information in the manufacturer lists or supplier lists. If they are invisible / deactivated for the customer, then use them, for example. you can use artist as manufacturer or supplier.
    So you can separately customize the product list view and filter such as from this topic:
    https://forum.thirtybees.com/topic/1223/product-list-bo-with-manufacturers-and-suppliers-columns



  • @wakabayashi: I see your point. The only reason I’m not writing it as “artist - album name” is because I need to be able to export csv files with the two fields in their own columns. Otherwise it would make my life so much easier also with friendly urls, how it appears on invoices etc…

    @zimmer-media: I’m going to use either manufacturer or supplier as the record label, haven’t decided on which one yet, but I guess I could use the one left as my artist. I’ll look into that. I’ve already added my own custom field, as mentioned in the post you link to, so it’s not a problem for me to edit that list and add extra fields if needed.

    It still doesn’t really solve my problem though as either supplier or manufacturer won’t come up in the results when I create orders. The ideal solution for me, no matter which kind of input field I use, is that both artist name and album name come up in these results.



  • @b_otho said in Add extra field to product selection in admin orders:

    I see your point. The only reason I’m not writing it as “artist - album name” is because I need to be able to export csv files with the two fields in their own columns. Otherwise it would make my life so much easier also with friendly urls, how it appears on invoices etc…

    If this is the only reason then I believe the best you could do is to either

    • modify csv export to output name as two columns
    • use a module that can do this split during export automatically (wink wink, shameless plug)


  • @datakick that’s interesting. Can your module do something like that?



  • @b_otho yeah, sure, quite easily.

    My module let you create list of (almost) any data in your system. Columns can contain expressions, similar to excel formulas. For examle you can replace string, perform mathematical operation, etc… So basically you can get the data out in any format you need.

    Once you have a list, you can export it to csv manually, schedule it to generate csv file periodically, or even create endpoint (url) that, when accessed, will return up-to-date csv file.

    I have prepared a short youtube video that shows how to create list and split product name to two columns.

    The module is paid, but there’s a 14 day trial period, so feel free to test it out. And shoot me an email if you need any help



  • That does indeed look quite awesome. I’ll have a look at it and get back to you. Thanks!



  • @b_otho

    You can also follow the hints of Nemo and customize your code in your files / overrides.
    Continuing then only the invoice and the produkt.tpl would have to be adjusted. If necessary, additional files where the additional field should appear.

    The other note from the forum, which I have previously used even with PS, I can not find right now.

    https://mypresta.eu/en/art/developer/new-field-product-backoffice.html



  • its not perfect, but helpful as example to add extra field for product name

    step 1
    Add an entry to the database in the table prefix_product
    0_1513990536778_dc836d8c-85fd-4bd4-b056-c03ec51d8d08-grafik.png

    step 2.1
    modify the file “Product.php” from “/classes/Product.php”, preferably in the folder classes Override “/override/classes/Product.php” save
    see the lines

       /** @var int Supplier id */
        public $id_supplier;
        /** @var int default Category id */
        public $id_category_default;
        /** @var int default Shop id */
        public $id_shop_default;
        /** @var string Manufacturer name */
        public $manufacturer_name;
    

    just add the following

        /** @var string Artist name */
        public $artist_name;
    

    step 2.2
    for example find

                'id_supplier'               => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
                'reference'                 => ['type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32],
    

    after this add

                'artist_name'         => ['type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 200],
    

    step 3
    copy your informations.tpl under override / controllers / admin / templates / products / informations.tpl
    and find the code

    	<div class="form-group">
    		<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="name" type="default" multilang="true"}</span></div>
    		<label class="control-label col-lg-2 required" for="name_{$id_lang}">
    			<span class="label-tooltip" data-toggle="tooltip" title="{l s='The public name for this product.'} {l s='Invalid characters:'} &lt;&gt;;=#{}">
    				{l s='Name'}
    			</span>
    		</label>
    		<div class="col-lg-5">
    			{include file="controllers/products/input_text_lang.tpl"
    				languages=$languages
    				input_class="{$class_input_ajax}{if !$product->id || Configuration::get('PS_FORCE_FRIENDLY_PRODUCT')}copy2friendlyUrl{/if} updateCurrentText"
    				input_value=$product->name
    				input_name="name"
    				required=true
    			}
    		</div>
    	</div>
    

    after this insert

    	<div class="form-group">
    		<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="name" type="default" multilang="true"}</span></div>
    		<label class="control-label col-lg-2">
    			<span class="label-tooltip" data-toggle="tooltip" title="{l s='The second public name for this product.'} {l s='Invalid characters:'} &lt;&gt;;=#{}">
    				{l s='Artist Name'}
    			</span>
    		</label>
    		<div class="col-lg-5">
                                <input type="text" id="artist_name" name="artist_name" value="{$product->artist_name|default:''}"/>
    		</div>
    	</div>
    

    step 4
    product view - in your theme product.tpl

    <h1 {if $enable_google_rich_snippets}itemprop="name"{/if} class="product_main_name">{$product->name|escape:'html':'UTF-8'}</h1>
    

    change to

    <h1 {if $enable_google_rich_snippets}itemprop="name"{/if} class="product_main_name">{$product->name|escape:'html':'UTF-8'} - {$product->artist_name|escape:'html':'UTF-8'}</h1>
    

    my result:
    0_1513991609169_9c7387b1-e087-4617-ad03-833cdd9963f2-grafik.png
    0_1513991628699_a97051d2-0791-404e-8836-6bb7c2ce8056-grafik.png
    0_1513991651931_c003730f-b868-4f43-98e1-5bfca89215fc-grafik.png

    For the invoice etc, you should include {$product-> artist_name | escape: ‘html’: ‘UTF-8’}



  • I expand my information

    In the product list of the BO for filtering, adjust the following parameters in the code:

    for example under “/override/controllers/admin/AdminProductsController.php”

    after the code

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

    add:

            $this->fields_list['artist_name'] = [
                'title'      => $this->l('Artist'),
            ];
    

    0_1513997230548_f416c4df-2db9-4e93-adf1-8381684a167e-grafik.png

    with filter
    0_1513997252533_c4c295db-82a5-4196-b77f-2fcc1bb1c7e5-grafik.png

    0_1513997890723_12773df1-7aef-4dcc-a11d-2af9f3a99a8a-grafik.png

    0_1513997902225_489825ca-e342-4927-a6fb-9faa30009851-grafik.png



  • @zimmer-media: Thanks for all you work you’re putting into this. I have already made a field as you describe by using Nemo’s tutorials though, but got stuck when I wanted to add this field to dropdown that comes up after searching for products in bo order creation.


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.