Jump to content

[SOLVED] Help to the problem: product not available because it is already in the cart


Recommended Posts

Hi,
it happened several times that they called me saying that a product was out of stock when instead it was available in quantity 1. This happens when the customer does not realize that he already has the product in the cart and then the system shows him the product not available (precisely because he took the last one).

I would like to make sure that if the customer already has the last product in the cart, he is notified that he already has the latest available product in the cart.

Reading this thread https://www.prestashop.com/forums/topic/1008079-risoltosolazione-al-problema-prodotto-non-disponibile-perchè-già-nel-carrello/ in the Italian forum I made these changes to the product-add-to-cart.tpl file:

1. Just after the code:

{if !$configuration.is_catalog}

add the following:

{$in_cart = 0}
{foreach from=$cart['products'] item='cart_product'}
  {if $cart_product['id_product'] == $product.id}
    {$in_cart = 1}
  {/if}
{/foreach}

Change the code:

{block name='product_availability'}
  <span id="product-availability">
    {if $product.show_availability && $product.availability_message}
      {if $product.availability == 'available'}
        <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>
{/block}

with the following:

{block name='product_availability'}
  <span id="product-availability">
  {if $product.show_availability && $product.availability_message}
    {if $product.availability == 'available'}
      <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i>
      {$product.availability_message}
    {elseif $product.availability == 'last_remaining_items'}
      <i class="material-icons product-last-items">&#xE002;</i>
      {$product.availability_message}
    {else}
      {if !$in_cart}
        <i class="material-icons product-unavailable">&#xE14B;</i>
      {/if}
    {/if}
    {if !$in_cart}
      {$product.availability_message}
    {/if}
  {/if}
  </span>
{/block}

Everything works fine except that when a product is available I find myself with the word "Available Available" (twice) under the product ... can you please help me solve this problem?

Thanks and best regards,
Fabrizio.

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

5 hours ago, Fabrizio Carloni said:

Everything works fine except that when a product is available I find myself with the word "Available Available" (twice) under the product ... can you please help me solve this problem?

First thing you do is to change the title of this thread from Solution to help.

Second where did you find "Available Available"?? In which Prestashop theme and version are you?

Link to comment
Share on other sites

  • Fabrizio Carloni changed the title to Help to the problem: product not available because it is already in the cart

I'm using AngarTheme but it's not a theme problem but a code problem ... in practice the additions in bold I made to the product-add-to-cart.tpl file remove the word "Not available" when a user has the latest product in cart but unfortunately adds the double word "Available Available" when a product is available:

{$in_cart = 0}
{foreach from=$cart['products'] item='cart_product'}
  {if $cart_product['id_product'] == $product.id}
    {$in_cart = 1}
  {/if}
{/foreach}

{block name='product_availability'}
  <span id="product-availability">
  {if $product.show_availability && $product.availability_message}
    {if $product.availability == 'available'}
      <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i>
      {$product.availability_message}
    {elseif $product.availability == 'last_remaining_items'}
      <i class="material-icons product-last-items">&#xE002;</i>
      {$product.availability_message}
    {else}
      {if !$in_cart}
        <i class="material-icons product-unavailable">&#xE14B;</i>
      {/if}
    {/if}
    {if !$in_cart}
      {$product.availability_message}
    {/if}
  {/if}
  </span>
{/block}

Best regards,
Fabrizio.

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

As you can see the theme name is not without importance:

/themes/nome-del-tema-utilizzato/templates/catalog/_partials/  is where you changed something. Undoing that change, setting it back to a state before does actually what?

After every change you should empty the cache. If not you won't see any difference.

Link to comment
Share on other sites

I can confirm that I've made the change to my theme's product-add-to-cart.tpl file but I don't want to go back because I need this functionality.
If I use the original file the double "Available Available" disappears and becomes "Available" but this is not what I want. What I am asking for is help modifying this code so that it works well in this situation as well. Is there please someone who can help me?

Best regards,
Fabrizio.

Link to comment
Share on other sites

If it could be useful to someone by modifying the second part of the code (I highlighted in bold what I changed) I was able to solve the problem of the word "Available Available" (twice) under the product:

{block name='product_availability'}
  <span id="product-availability">
  {if $product.show_availability && $product.availability_message}
    {if $product.availability == 'available'}
      <i class="material-icons rtl-no-flip product-available">&#xE5CA;</i>
      {$product.availability_message}
    {elseif $product.availability == 'last_remaining_items'}
      <i class="material-icons product-last-items">&#xE002;</i>
      {$product.availability_message}
    {else}
      {if !$in_cart}
        <i class="material-icons product-unavailable">&#xE14B;</i>
        {$product.availability_message}
      {/if}
    {/if}
    {if !$in_cart}
      {$product.availability_message}
    {/if}

  {/if}
  </span>
{/block}

Greetings,
Fabrizio.

  • Like 1
Link to comment
Share on other sites

  • Fabrizio Carloni changed the title to [SOLVED] Help to the problem: product not available because it is already in the cart

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