cancel
Showing results for 
Search instead for 
Did you mean: 

Stock quantity 0

Stock quantity 0

Hi,

I have products that once they reach a quantity of 0 the still should be possible to be ordered on the frontend but the customer should be notified with a message next to the product with something like "1 to 3 delivery days". Or an image which show this.

The problem now is. My products that have a quantity of 0 are avaiable in the frontend and allowed to order, but the image won't change to "1 to 3 delivery days". They are shown as a normal in stock product.

So to make this more clear.
Situation prefered:

- Products with quantity more the 0 should be allowed to order with an image shown that says "delivery next day"
- Product with quantity 0 or lower should be allowed to order with an image shown "that says "delivery 1 to 3 working days".


Situation now:
- Products with quantity more the 0 are allowed to order with an image shown that says "delivery next day".
- Product with quantity 0 or lower are showing the same message as a product that is higher then quantity 0.

I hope it's clear what I'm trying to say Smiley Very Happy

 

Hope someone can point me in the right direction how to solve this.

13 REPLIES 13

Re: Stock quantity 0

@Jojobaa

 

You can check your product quantity and change the delivery status image accordingly.

 

Try this code.

 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');

$stockQty = $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());

if ($stockQty > 0) {
    // deliver next day
} else {
    // deliver in 1 to 3 days
}

 

If you find my answer useful, Please click Kudos & Accept as Solution.

Re: Stock quantity 0

swissup_text_logo.png

 

Check the Swissup ProLables module.

It has stock label option - so you can set it to be visible when product stock quantity is 0.

You can apply an text or image to label.

Did you find it helpful? Please give "Kudos" or "Accept as Solution".
Meet 70+ extensions and templates for M1 & M2 in one place


Re: Stock quantity 0

Thanks for your reply.

Where should I put this code?

And where the “// deliver next day” content comes in the code, how would I acces the delivery image and change this by code?

Thanks so far

Re: Stock quantity 0

@Jojobaa

 

I just gave an example with "// deliver next day".

Try to find out where your delivery image status is coming from.

 

Then put my if and else condition there.

If you find my answer useful, Please click Kudos & Accept as Solution.

Re: Stock quantity 0

Ok Thank you so far, i’ll try to find the specific code that handles the image.

Re: Stock quantity 0

I'm still not sure where to add the suggested code. Have tried by activating template path hints for developers on front-end, but still no clue on where to add this. 

Re: Stock quantity 0

Anyone?

Re: Stock quantity 0

No echo ...........................

Re: Stock quantity 0

@Jojobaa

 

Where do you exactly want to show the text?

 

Beside name in product detail page?

Beside SKU?

Beside Availability: InStock?

 

Let me know the exact section where you want to show the text so I can guide you that particular file where you can add this text.

If you find my answer useful, Please click Kudos & Accept as Solution.