1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can i set default value to a form, in Prestashop platform admin?

Discussion in 'PHP' started by RaulLucian, Sep 29, 2016.

  1. #1
    Hello,
    SEMrush
    I would like to set an automatic default value to all products, in "Displayed text when in-stock" form, in quantities produtcs tab. Can someone help?

    This is what i had discovered so far:

    In Prestashop Admin the form is here:
    Admin->Catalog->Products->Quantities->Displayed text when in-stock

    Here is what it looks like in Prestashop Admin:
    [​IMG]

    On the server the file that must be edited is:
    /public_html/admin/themes/default/template/controllers/products/quantities.tpl

    Here is what it looks like on the server:
    [​IMG]

    On quantities.tpl file i need to edit line 248: "input_value=$product->available_now"


    {if $ps_stock_management}
    <div class="form-group">
    <div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="available_now" type="default" multilang="true"}</span></div>
    <label class="control-label col-lg-2" for="available_now_{$default_language}">
    <span class="label-tooltip" data-toggle="tooltip" title="{l s='Forbidden characters:'} &#60;&#62;;&#61;#&#123;&#125;">
    {l s='Displayed text when in-stock'}
    </span>
    </label>
    <div class="col-lg-9">
    {include file="controllers/products/input_text_lang.tpl"
    languages=$languages
    input_value=$product->available_now
    input_name='available_now'}
    </div>
    </div>

    ====================================================================

    My question is:
    How can i edit this line: input_value=$product->available_now
    so the automatic default value "In stock" is set to all products in shop?

    PS:
    I have replaced input_value=$product->available_now with input_value="In stock" but in admin shop is displayed only "s" value.

    Thanks!
     
    RaulLucian, Sep 29, 2016 IP
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,626
    Likes Received:
    719
    Best Answers:
    151
    Trophy Points:
    420
    #2
    Won't the "In stock"-text show as long as the item is actually in stock? Ie, the amount of items in stock is more than 0?
     
    PoPSiCLe, Sep 29, 2016 IP
  3. RaulLucian

    RaulLucian Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Hello,

    If all the products that are in stock, will by default, automaticly show the value "in stock" it would be perfect.
    But right now, you need to manually fill the form, with the text "in stock" for every product that is in stock.
     
    RaulLucian, Sep 29, 2016 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,626
    Likes Received:
    719
    Best Answers:
    151
    Trophy Points:
    420
    #4
    Aha. Okay, I would probably just check the database to see where that information is stored, and update the database directly (instead of using the form to fill it out for every product). That way you will have what you want, don't have to change anything on-site, and it will even show up if you go into a product later and change it to something different.
     
    PoPSiCLe, Sep 30, 2016 IP
  5. RaulLucian

    RaulLucian Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    Thanks for your answer! That would be a solution, in general, but unfortunatelly, not in this case.

    The client is posting products every day, for a few hours a day. This will need multiple update of the database/day.
    That is why it will need an automatic solution.

    The problem is I am not so familiar whith php sintax so i can edit that fragment of code.
     
    RaulLucian, Sep 30, 2016 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,626
    Likes Received:
    719
    Best Answers:
    151
    Trophy Points:
    420
    #6
    I'm hoping at least that the client runs this on his own server / VPS / something?
    If so, set up a cron-job, with a tiny PHP-script running an update on the database every... hour? "UPDATE table_name SET status_text = 'In stock' WHERE status_text = ''" (or something similar). Simple, easy, and will run in the background on the server (as long as the script works and is put into crontab)
     
    PoPSiCLe, Sep 30, 2016 IP
  7. Einheijar

    Einheijar Well-Known Member

    Messages:
    537
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    115
    #7

    Isn't he posting the updates to the database multiple times a day? If so why would it be so hard to retrieve the data?
     
    Einheijar, Oct 2, 2016 IP
  8. RaulLucian

    RaulLucian Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #8
    The client is manually uploding products every day, so he would like that this section to be by default filled with "In stock" so that he can simplify his work.
     
    RaulLucian, Oct 3, 2016 IP
  9. RaulLucian

    RaulLucian Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    Thanks @PoPSiCLe. If we do not find a solution, using PHP coding, your solution is the next best thing!
     
    RaulLucian, Oct 3, 2016 IP
  10. RaulLucian

    RaulLucian Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    I have found the solution:

    In Prestashop 1.6 the file needed to be edited is product.tpl (/public_html/themes/YourTheme/product.tpl)

    1. I deactivated the lines 207-211

    <p id="availability_statut"{if !$PS_STOCK_MANAGEMENT || ($product->quantity <= 0 && !$product->available_later && $allow_oosp) || ($product->quantity > 0 && !$product->available_now) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
    <label id="availability_label" class="attribute_label">{l s='Availability:'}</label>
    <span id="availability_value" class="label{if $product->quantity <= 0 && !$allow_oosp} label-danger{elseif $product->quantity <= 0} label-warning{else} label-success{/if}">{if $product->quantity <= 0}{if $PS_STOCK_MANAGEMENT && $allow_oosp}{$product->available_later}{else}{l s='This product is no longer in stock'}{/if}{elseif $PS_STOCK_MANAGEMENT}{$product->available_now}{/if}</span></p>

    2. And added this code, under the original one:

    <p>
    <label>{if $product->quantity > 0}<div class='instoc'>{l s='Disponibilitate:'}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#41ae53">{l s='In stoc'}</span></div>{else}<div class='outofstoc'>{l s='Disponibilitate:'}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#F13340">{l s='Produsul nu se afla momentan pe stoc'}</span></div>{/if} </label>
    </p>

    Here is what the fix looks like:
    [​IMG]

    Thanks for your help!
     
    RaulLucian, Oct 4, 2016 IP