0

I'm new to Magento(2) and I'm trying to display Stock Status, stock count, and quantity field in category view like in product view. I don't know where to get theses values and where to put it... I'm using magento 2.2.10 and I'm using the default luma theme

I found that if i comment some containers in catalog_product_view.xml at rootFolder/vendor/magento/module-catalog/view/frontend/layout, it disable it from the product page, so i suppose that i need to copy this code to some other file but i can't figure it out...

Thanks in advance for your help guys

Where I want to add information: My category view here, where i want to add some informations

Where I want to copy values into category view: My Product View, where I want to copy values into category view

0

To display qty on category page, there are 2 methods either create your custom module and call its block on both places or add code directly using $ObjectManager.

This method is not recommended but since you need some quick and easy solution that is why I am giving it here :

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

    echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
 ?>

for adding on listing page Go to your theme folder Magento_Catalog/templates/product/list.phtml file and add below code where you want to show it i.e underneath product name etc.

| improve this answer | |
0

First of all thank you for your response @Supravat_M

I just tried your solution by pasting this piece of code into "/var/www/html/vendor/magento/theme-frontend-luma/Magento_Catalog/templates/product/list.phtml" but when I refresh the cache all products disappear ..

I tried in "/var/www/html/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml" and there it does nothing at all.

I restored the files to their original format but my problem remains ...

Thank you all the same for your help ..

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.