Happening now | Office Hours: Customizing Your Theme With Dan-From-Ryviu | Ask your questions now!

hide product from collection which first variant inventory is 0

hide product from collection which first variant inventory is 0

tortoise
Shopify Partner
3 0 3

hi 

this is my store url : https://tortoise.net.in

where in backpack i want to show only that product  which first inventory is not equal to 0

 

but still product is visible on listing page and when click to go product page other variant is selected which have inventory. 

Replies 2 (2)

magecomp
Shopify Partner
469 31 48

Hello @tortoise 

To show only the products in your Backpack store which have inventory greater than zero, you can use a filter on the "Product" model in your backpack's product controller.

Here's an example code snippet that you can add to your product controller:

 

 

public function index()
{
    $this->crud->addClause('where', 'inventory', '>', 0);
    return parent::index();
}

 

 

This code will filter out all products with an inventory of zero or less, and only display products with an inventory greater than zero.

However, keep in mind that this will only affect the products displayed on the listing page. If a customer clicks on a product that has a variant with zero inventory, they may still be able to see that variant on the product page.

To prevent this, you can modify your product page template to only display variants with inventory greater than zero. You can do this by adding an additional filter to the variant loop in your product view template:

 

 

@foreach($product->variants->where('inventory', '>', 0) as $variant)
    // display variant information here
@endforeach

 

 

This code will only display variants with inventory greater than zero on the product page.

I hope this helps!

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website

gr_trading
Shopify Partner
2045 149 206

Hi @tortoise 

 

You have to modify the card-product.liquid to achieve this and can be done using custom code in your theme.

 

Let me know if you still want to implement this.

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee