Jump to content

SOLVED: stock/quantity is updated when adding product to cart


BlackEdition

Recommended Posts

Hi,

I noticed in PrestaShop 1.7.5.0 the stock or quantity for the product is updated right after someone adds the product to the cart and there's no way to configure how this works in the backoffice!

This is a very bad idea and not a good move to run a business. Because someone might add all the quantity available in the store but they are not serious about completing the order, so they will just ruin it for all other customers because it will say out of stock, or maybe they're not in a hurry and are planning to buy in a couple of days.

This will make me lose a lot of sales from other potential buyers!

I tried to google this but all I found was people wanting the other way around, which is what's happening right now in the newer PS versions so im guessing the PS team changed that in the last updates.

Im ok with buying a module that can manage stock in a better way with more flexibility, any suggestions? I couldn't find anything.

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

Ok my bad, it appears to be working correctly but I didn't test it the right way.

I was testing this with the same account which results in updating the quantity only for my account and saying I can't add anymore, so it's not actually updating it for everyone.

I tested it now with 2 different accounts and it is working as it should be. I added the last quantity in 2 different carts/accounts and if one of them checkout and place the order first, then the other user can't proceed and will get an error message saying the quantity is not enough.

This is great! I don't remember it being this way before in PS 1.7.

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

  • BlackEdition changed the title to SOLVED: stock/quantity is updated when adding product to cart
  • 1 year later...
  • 3 weeks later...
  • 1 year later...

Hi.

I have EXACTLY the same issue like @WebDesign-Entreprise.

Anybody have some idea how to fix this?

 

Thank you.

Andrej

 

On 11/11/2020 at 6:12 PM, WebDesign-Entreprise said:

Hello,

I have also noticed this feature as you :)
My problem is that I have a lot of product with only 1 unit in stock. So when customer add product in cart it display Out of stock on the product page.
So the customer is confused and didn't know if the product is in stock or not..

Any idea about it ?

Thanks

 

Link to comment
Share on other sites

Hello,

Here is the code:

						{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}

You can add it in any tpl file in your theme.
For me : themes/yourtheme/templates/catalog/_partials/product-add-to-cart.tpl 

Regard

Link to comment
Share on other sites

2 hours ago, WebDesign-Entreprise said:

Hello,

Here is the code:

						{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}

You can add it in any tpl file in your theme.
For me : themes/yourtheme/templates/catalog/_partials/product-add-to-cart.tpl 

Regard

Hi.

Thank you so much. This works perfectly! I have even added another condition, because the message was showing even with products that are more than 1 piece in stock.

{if $inCart == true && $product.quantity < 2}

Now it works only with products that have ONLY last 1 piece in stock.

Thank you very much again!

Wishing the best.

Andrej

Link to comment
Share on other sites

9 hours ago, WebDesign-Entreprise said:

Hello,

Here is the code:

						{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}

You can add it in any tpl file in your theme.
For me : themes/yourtheme/templates/catalog/_partials/product-add-to-cart.tpl 

Regard

@WebDesign-Entreprise one last thing. I realised that the condition for quantity works also for 0 and less. Do you have an idea how to set it only if quantity is 1?

I have tried  {if $inCart == true && $product.quantity == 1}, but for some reason it is not working.

 

Thanks a lot!

Andrej

Link to comment
Share on other sites

5 hours ago, www.exclusivepen.eu said:

@WebDesign-Entreprise one last thing. I realised that the condition for quantity works also for 0 and less. Do you have an idea how to set it only if quantity is 1?

I have tried  {if $inCart == true && $product.quantity == 1}, but for some reason it is not working.

 

Thanks a lot!

Andrej

Ok, I think I have solved it. Thing is that it should be ZERO, not ONE. Like this {if $inCart == true && $product.quantity == 0}.

I think logic behind this is that since the quantity is calculated after the item is put to the cart, there will be never quantity 1. When you put it into the cart, the actual quantity is 0. With this code it is showing properly.

Cheers!

Andrej

Link to comment
Share on other sites

Actually, here my complete block:

{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}
					  
					  	{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}
						
					  {/if}
					{/if}
				  </span>
				{/block}

 

Link to comment
Share on other sites

2 hours ago, WebDesign-Entreprise said:

Actually, here my complete block:

{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}
					  
					  	{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}
						
					  {/if}
					{/if}
				  </span>
				{/block}

 

Thank you very much!!

Andrej

Link to comment
Share on other sites

  • 1 year later...

Hi,

 

I'm sorry, I can't find this code in the file themes/yourtheme/templates/catalog/_partials/product-add-to-cart.tpl 

Here is this file (PS 1.7.8) :

 

{strip}
    <div class="product-add-to-cart">
        {if !$configuration.is_catalog}
        {block name='product_quantity'}
        <div class="product-quantity">
            <span class="control-label">{l s='Quantity : ' d='Shop.Theme.Catalog'}</span>
            <div class="qty">
                <input type="text" name="qty" id="quantity_wanted" value="{$product.quantity_wanted}" class="input-group" min="{$product.minimal_quantity}" aria-label="{l s='Quantity' d='Shop.Theme.Actions'}">
            </div>
        </div>
        
        <div class='tvwishlist-compare-wrapper-page add tv-product-page-add-to-cart-wrapper'>
            <div class="tvcart-btn-model">
                <button class="tvall-inner-btn add-to-cart {if !$product.add_to_cart_url} disabled {/if}" data-button-action="add-to-cart" type="submit" {if !$product.add_to_cart_url} disabled {/if}> {if !$product.add_to_cart_url} <i class='material-icons block'>&#xe14b;</i>
                    <span>{l s='Contact us' d='Shop.Theme.Actions'}</span>
                    {else}
                    <i class="material-icons shopping-cart">&#xE547;</i>
                    <span>{l s='Add to cart' d='Shop.Theme.Actions'}</span>
                    {/if}
                </button>
                {* {if $page.page_name == 'product'}
                <button type="button" class="tvall-inner-btn tvclick-model" data-toggle="modal" data-target="#exampleModalCenter">
                    <i class="tvcustom-btn"></i>
                    <span>Buy in one click</span>
                </button>
                {/if} *}
            </div>
            <div class="tvproduct-wishlist-compare">
                {hook h='displayWishlistProductPage' product=$product}
                {hook h='displayProductCompareProductPage' product=$product}
            </div>
            <div class="tvproduct-stock-social">
              
                {block name='product_additional_info'}
                {include file='catalog/_partials/product-additional-info.tpl'}
                {/block}
            </div>
        </div>
        {/block}
        {/if}
    </div>
{/strip}

 

Link to comment
Share on other sites

  • 5 months later...

It's working here in my PS 8.1.5, but the message isn't updating automatically. I need to refresh the page to see "the last item is in your basket". 

How can I make it to change automatically??

 

On 7/27/2022 at 3:12 AM, WebDesign-Entreprise said:

Actually, here my complete block:

{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}
					  
					  	{assign var="inCart" value=false}
					  	{foreach from=$cart.products item=cartproduct}
					    	{if $cartproduct.id_product == $product.id_product}
					         {assign var="inCart" value=true}
					   		{/if}
					 	 {/foreach}
					 	 
					 	 
						{if $inCart == true}
						   <i class="material-icons product-last-items">&#xE002;</i>
						 	Vous avez le dernier dans votre panier !
						{else}
							<i class="material-icons product-unavailable">&#xE14B;</i>
						 	{$product.availability_message}
						{/if}
						
					  {/if}
					{/if}
				  </span>
				{/block}

 

 

Link to comment
Share on other sites

  • 5 months later...
16 hours ago, Retro All-Stars said:

Hi,

Your code works for me, but how do you check the product combination that is currently in the cart? Because my message "last item in cart" displays even if I select an other combination of the product that is NOT in the cart.

Thanks!

You can change the test in the foreach loop by

{if ($cartproduct.id_product == $product.id_product) && ($cartproduct.id_product_attribute == $product.id_product_attribute)}

Thanks

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