Jump to content

Product availability auto update problem


Christofferjonsson

Recommended Posts

Hello,

Right now we have this fix to display product availability.

      {if {$product->quantity} < 1}
      <div class="cj-outstock">
        <img src="https://bollnasbilvard.se/img/cms/Ikoner/yellow.png" alt="Delivery" width="20" height="20">
        {$product.availability_message}
      </div>
      {else}
      <div class="cj-instock">
      
        <img src="https://bollnasbilvard.se/img/cms/Ikoner/green.png" alt="Delivery" width="20" height="20"> I lager
      </div>

      {/if}

This is because if you have a product that is Out of stock, but still buyable, Prestashop will still display a green checker, which is a bit misleading, even though you change the text. That why we want a Yellow checker / icon when a product is out of stock, but still buyable. And a green when it's in stock. I know its a basic and flawed solution.

The problem is when you have a product with combinations, if you select a combination that is Out of stock, the availability message does not update, until you refresh the whole page, then the availability message refreshes. Does anyone have a solution for this or maybe a better solution with the original availability message.

Product example:

https://www.bollnasbilvard.se/foam-lance/6393-612-bbv-foam-lance-dysa.html#/153-diameter-150_mm

1. Try changing to 1,50mm that is out of stock.

2. Refresh page.

3.Select another in stock option.

Thanks in advance

 

Original:

	<span id="product-availability">
        {if $product.show_availability && $product.availability_message}

         {if $product.availability == 'available' || {$product->quantity} < 1}

            <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i>

          {elseif $product.availability == 'last_remaining_items'}

            <i class="material-icons product-last-items">&#xE002;</i>

          {else}

            <i class="material-icons product-unavailable">&#xE14B;</i>

          {/if}

          {$product.availability_message}

        {/if}
      </span>

 

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

  • 1 month later...
3 hours ago, MEG Venture said:

Have you found a solution?

Yes, i did like this

	<span id="product-availability">
        {if $product.show_availability && $product.availability_message}

         {if $product.availability == 'available' && {$product->quantity} > 0}

          <!--  <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i>-->
<img src="https://bollnasbilvard.se/img/cms/Ikoner/green.png" alt="Delivery" width="20" height="20">
          {elseif $product.availability == 'last_remaining_items'}

            <i class="material-icons product-last-items">&#xE002;</i>

          {elseif $product.availability == 'available' && {$product->quantity} < 1}
           <img src="https://bollnasbilvard.se/img/cms/Ikoner/yellow.png" alt="Delivery" width="20" height="20">
          {else}

          <i class="material-icons product-unavailable">&#xE14B;</i>

          {/if}

          {$product.availability_message}

        {/if}
      </span>

<!-- My first try, which is trashed
      {if {$product->quantity} < 1}
      <div class="cj-outstock">
        <img src="https://bollnasbilvard.se/img/cms/Ikoner/yellow.png" alt="Delivery" width="20" height="20">
        {$product.availability_message}
      </div>
      {else}
      <div class="cj-instock">
        <!--<span id="product-availability">  <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i></span>
        <img src="https://bollnasbilvard.se/img/cms/Ikoner/green.png" alt="Delivery" width="20" height="20"> I lager
      </div>-->

  <!-- {/if}-->

 

Link to comment
Share on other sites

Are you telling me that {$product-> quantity} works for Prestashop 1.7 ? 😁
In Prestashop version 1.7, use a dot instead of ->.
Prestashop 1.7 uses {$product.quantity} or {$product.quantity_all_versions}

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

45 minutes ago, Guest said:

Are you telling me that {$product-> quantity} works for Prestashop 1.7 ? 😁
In Prestashop version 1.7, use a dot instead of ->.
Prestashop 1.7 uses {$product.quantity} or {$product.quantity_all_versions}

I've noticed that it works on some places and some not. For example when wanted to make a sleek design that shows product stock in list-view like this https://prnt.sc/s2sfrr i used $product.quantity Like this:

<!--Visa lagerstatus i list-view-->

            {if {$product.quantity} < 1}

          <div class="cj-stock-list">

          </div>
            {elseif $product.availability == 'available' && {$product.quantity} < 1}
          <div class="cj-stock-list-open">
            
          </div>
            {else}
          <div class="cj-stock-list-out">

          </div>
            {/if}
<!-- Visa lagerstatus i list-view-->

But in product-add-to-cart.tpl i used  {$product-> quantity}, i do get value from  {$product-> quantity} {$product.quantity}  and {$product.quantity_all_versions} so all 3 seem to work for me in PS1.7.5

Maybe i'll change to {$product.quantity} when one stops working :)

Link to comment
Share on other sites

  • 1 year later...
  <div class="product_availability">
{if $product.show_price}
        {if !$configuration.is_catalog}
            {block name='product_availability'}
                {if $product.show_availability && $product.availability_message}
                    <span id="product-availability"
                          class="badge {if $product.availability == 'available'} {if $product.quantity <= 0  && !$product.allow_oosp} badge-danger product-unavailable  {elseif $product.quantity <= 0  && $product.allow_oosp}badge-warning product-unavailable-allow-oosp {else}badge-success product-available{/if}{elseif $product.availability == 'last_remaining_items'}badge-warning product-last-items{else}badge-danger product-unavailable{/if}">
                  {if $product.availability == 'available'}
                      <i class="fa fa-check rtl-no-flip" aria-hidden="true"></i>
                                                     {$product.availability_message}
                  {elseif $product.availability == 'last_remaining_items'}
                      <i class="fa fa-exclamation" aria-hidden="true"></i>
                                                     {$product.availability_message}
                  {else}
                      <i class="fa fa-ban" aria-hidden="true"></i>
                              {$product.availability_message}
                      {if isset($product.available_date) && $product.available_date != '0000-00-00'}
                      {if $product.available_date|strtotime > $smarty.now}<span
                              class="available-date">{l s='until' d='Shop.Theme.Catalog'} {$product.available_date}</span>{/if}
                  {/if}
                  {/if}
                </span>
                {/if}
            {/block}
{/if}
{/if}

I also have problems with the refresh of the stock icon in the combinations of the product page. I want to place it somewhere else on the product page, but if I add it before "add-to-cart.tpl it doesn't refresh the stock. Only when it refreshes the whole page.

I attach the code that I place above where I want to place it.

Please help me...😥

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

  • 5 months later...
  • 1 year later...

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