Show "Out of stock" message on product listing pages

Open to all! Ask other shopowners for help.
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Re: Show "Out of stock" message on product listing pages

Post by lecarlb »

shopify wrote: Sat Jul 10, 2021 11:20 pm Sold Out.jpgI've done this using if ($listing['in_stock'] == 0 {
//Show add to cart button
} else {
//Show sold out button
}

But I like the look of that @lecarlb sold out button. I wonder how he did that button.
It's the older version of @zipurman Product Manager


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Show "Out of stock" message on product listing pages

Post by Kofod95 »

Using something similar to what Burt suggested, we have this:
Screenshot_20210711-191634.png
We are not measuring stock, as we have a physical store that is too small for POS-systems, but when we sell the last item of any sort, we change the product status to '2' ('0' is the red cross, '1' is the green check, '2' is something we have added to signify 'still visible, but out of stock'.). We have added a class to the product cards so they include the status, allowing us to target the sold out products with css.

//Daniel
You do not have the required permissions to view the files attached to this post.
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Show "Out of stock" message on product listing pages

Post by burt »

Per the two posts above, you could drop a copy of this file:

/templates/default/includes/components/product_card.php

into the following location:

/templates/override/includes/components/product_card.php (note that if you use a different template to override, you should drop it into what template you are using)

Now find:

Code: Select all

    if (!$product->get('has_attributes')) {
      echo PHP_EOL, tep_draw_button(
        IS_PRODUCT_BUTTON_BUY,
        '',
        tep_href_link(basename($GLOBALS['PHP_SELF']), tep_get_all_get_params(['action', 'products_id']) . 'action=buy_now&products_id=' . (int)$product->get('id')),
        null,
        ['params' => 'data-has-attributes="0" data-in-stock="' . (int)$product->get('in_stock') . '" data-product-id="' . (int)$product->get('id') . '"'],
        'btn-light btn-product-listing btn-buy');
    }
Change to:

Code: Select all

    if ($product->get('in_stock') > 0) {  // is stock greater than zero? YES:
      if (!$product->get('has_attributes')) { 
         echo PHP_EOL, tep_draw_button(
        IS_PRODUCT_BUTTON_BUY,
        '',
        tep_href_link(basename($GLOBALS['PHP_SELF']), tep_get_all_get_params(['action', 'products_id']) . 'action=buy_now&products_id=' . (int)$product->get('id')),
        null,
        ['params' => 'data-has-attributes="0" data-in-stock="' . (int)$product->get('in_stock') . '" data-product-id="' . (int)$product->get('id') . '"'],
        'btn-light btn-product-listing btn-buy');
      }
    }
    else { // NO:
      echo tep_draw_button('<i class="fas fa-battery-empty"></i>', '', $product->get('link'), null, ['params' => 'title="OOS"'], 'btn-danger btn-product-listing btn-view');
    }
This is the stunning beauty of Matts templating system. You can do similar in the other places that show product lists (eg new roducts for month etc), but note that some files are in the older style of coding (but still templatable and over-rideable), it is just that the code will look slightly different.
I am not here to build for you.
I am here to build with you. Let's help each other.
shopify
Member
Posts: 54
Joined: Tue Mar 30, 2021 3:36 pm
Phoenix Version:
Has thanked: 23 times
Been thanked: 3 times

Re: Show "Out of stock" message on product listing pages

Post by shopify »

burt wrote: Tue Jul 13, 2021 10:55 am Per the two posts above, you could drop a copy of this file:

/templates/default/includes/components/product_card.php

into the following location:

/templates/override/includes/components/product_card.php (note that if you use a different template to override, you should drop it into what template you are using)

Now find:

Code: Select all

    if (!$product->get('has_attributes')) {
      echo PHP_EOL, tep_draw_button(
        IS_PRODUCT_BUTTON_BUY,
        '',
        tep_href_link(basename($GLOBALS['PHP_SELF']), tep_get_all_get_params(['action', 'products_id']) . 'action=buy_now&products_id=' . (int)$product->get('id')),
        null,
        ['params' => 'data-has-attributes="0" data-in-stock="' . (int)$product->get('in_stock') . '" data-product-id="' . (int)$product->get('id') . '"'],
        'btn-light btn-product-listing btn-buy');
    }
Change to:

Code: Select all

    if ($product->get('in_stock') > 0) {  // is stock greater than zero? YES:
      if (!$product->get('has_attributes')) { 
         echo PHP_EOL, tep_draw_button(
        IS_PRODUCT_BUTTON_BUY,
        '',
        tep_href_link(basename($GLOBALS['PHP_SELF']), tep_get_all_get_params(['action', 'products_id']) . 'action=buy_now&products_id=' . (int)$product->get('id')),
        null,
        ['params' => 'data-has-attributes="0" data-in-stock="' . (int)$product->get('in_stock') . '" data-product-id="' . (int)$product->get('id') . '"'],
        'btn-light btn-product-listing btn-buy');
      }
    }
    else { // NO:
      echo tep_draw_button('<i class="fas fa-battery-empty"></i>', '', $product->get('link'), null, ['params' => 'title="OOS"'], 'btn-danger btn-product-listing btn-view');
    }
I haven't a /templates/override/includes/components/ folder so I modified the file /templates/default/includes/components/product_card.php file but nothing changes. I still have the add to cart button even when I change stock to zero.
shopify
Member
Posts: 54
Joined: Tue Mar 30, 2021 3:36 pm
Phoenix Version:
Has thanked: 23 times
Been thanked: 3 times

Re: Show "Out of stock" message on product listing pages

Post by shopify »

By the way what file displays new products for the month?
User avatar
zipurman
Builder
Posts: 540
Joined: Tue Oct 13, 2020 5:20 pm
Phoenix Version: v
Has thanked: 93 times
Been thanked: 162 times

Re: Show "Out of stock" message on product listing pages

Post by zipurman »

shopify wrote: Sat Jul 24, 2021 11:50 am By the way what file displays new products for the month?
Modules - Content - New Products (index)
zipurman
-----------
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Show "Out of stock" message on product listing pages

Post by Kofod95 »

shopify wrote: Sat Jul 24, 2021 11:30 am I haven't a /templates/override/includes/components/ folder so I modified the file /templates/default/includes/components/product_card.php file but nothing changes. I still have the add to cart button even when I change stock to zero.
You should create the directory and copy the file into it, as that will preserve your changes throughout updates in the future - the point about templates is that it allows you to override core-layout instead of changing it directly.

However, on my 1.0.8.0 the product_card.php doesn't do anything (at least as far as I could tell), meaning the relevant change should be in product_listing.php instead (templates/override/includes/components/product_listing.php - just copy the one from the default template, and create the directories in the override template)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Show "Out of stock" message on product listing pages

Post by Kofod95 »

shopify wrote: Sat Jul 24, 2021 11:50 am By the way what file displays new products for the month?
The file is cm_i_card_products.php (includes/modules/content/index)

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
shopify
Member
Posts: 54
Joined: Tue Mar 30, 2021 3:36 pm
Phoenix Version:
Has thanked: 23 times
Been thanked: 3 times

Re: Show "Out of stock" message on product listing pages

Post by shopify »

Kofod95 wrote: Sat Jul 24, 2021 6:00 pm
shopify wrote: Sat Jul 24, 2021 11:50 am By the way what file displays new products for the month?
The file is cm_i_card_products.php (includes/modules/content/index)

//Daniel
This files does not have anything in it that display products for the month on the index.php page. I need to modify the file that displays these products like the product_listing.php file to show item is out of stock. The index page is first place customers see products and if product is not in stock, then I'd like to display the out of stock button here too.
shopify
Member
Posts: 54
Joined: Tue Mar 30, 2021 3:36 pm
Phoenix Version:
Has thanked: 23 times
Been thanked: 3 times

Re: Show "Out of stock" message on product listing pages

Post by shopify »

Kofod95 wrote: Sat Jul 24, 2021 5:58 pm
shopify wrote: Sat Jul 24, 2021 11:30 am I haven't a /templates/override/includes/components/ folder so I modified the file /templates/default/includes/components/product_card.php file but nothing changes. I still have the add to cart button even when I change stock to zero.
You should create the directory and copy the file into it, as that will preserve your changes throughout updates in the future - the point about templates is that it allows you to override core-layout instead of changing it directly.

However, on my 1.0.8.0 the product_card.php doesn't do anything (at least as far as I could tell), meaning the relevant change should be in product_listing.php instead (templates/override/includes/components/product_listing.php - just copy the one from the default template, and create the directories in the override template)

//Daniel
I created the folder as dvised and changes are picked up here. Next thing is applying to the index.php page.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply