Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Is there a way to limit the quantity displayed?

Is there a way to limit the quantity displayed?

Locked

Views: 2,324

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
23 Feb 2010, 6:59 PM
#1
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Is there a way to limit the quantity displayed?

Hi all,
I've searched the forums and the internet in general, but I haven't found an answer to this. Though it might just be that terms that I am using in my search are too broad.

Anyway, I would like to cap the quantity available for each item displayed at a maximum of 4.

So, so say I have 50 different product listings. For each product I have 1 to 30 in stock depending on the item. Is there a way for ZenCart to continue to keep track of inventory but to only display to the customer that I have a maximum of 4 of each item available?

To put this another way:

Lets say that I have the following items in stock:

Item A : 11 units in stock
Item B : 3 units in stock
Item C: 22 units in stock
Item D: 5 units in stock
Item E: 4 units in stock
Item F: 1 unit in stock

It would be ideal for me if, when a customer looked at the product listings and product info, the quantity displayed looked like the following:

Item A : 4 units in stock
Item B : 3 units in stock
Item C : 4 units in stock
Item D : 4 units in stock
Item E : 4 units in stock
Item F : 1 unit in stock

I want to set (or cap) the quantity displayed for each item at 4.

Hopefully this question makes sense.
Thanks in advance to anyone who can help shed some light on this.

23 Feb 2010, 7:38 PM
#2
apsona avatar

apsona

Zen Follower

Join Date:
Jan 2010
Posts:
190
Plugin Contributions:
1

Re: Is there a way to limit the quantity displayed?

I tried a quick test that seems to work: In the file includes/templates/template_default/templates/tpl_product_info_display.php, line 122 (approximately) looks like this:

<?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>' : '') . "\n"; ?>

Replace it with this:

<?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . min ($products_quantity,4) . TEXT_PRODUCT_QUANTITY . '</li>' : '') . "\n"; ?>

Hope this helps.

Apsona
http://apsona.com

23 Feb 2010, 8:10 PM
#3
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

Thank you, that worked for the individual Product Info pages.
Can you help me make a similar adjustment to the Product Listing pages?

I tried to take what you gave me and apply it elsewhere but I am not familiar enough with the coding languages being used =)

24 Feb 2010, 3:00 AM
#4
apsona avatar

apsona

Zen Follower

Join Date:
Jan 2010
Posts:
190
Plugin Contributions:
1

Re: Is there a way to limit the quantity displayed?

Very similar change in the file includes/templates/template_default/templates/tpl_modules_products_all_listing.php, line 59 changes from


$display_products_quantity = TEXT_PRODUCTS_QUANTITY . $products_all->fields['products_quantity'] . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

to


$display_products_quantity = TEXT_PRODUCTS_QUANTITY . min(4,$products_all->fields['products_quantity']) . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_QUANTITY, 3, 1));

Hope this helps.

Apsona
http://apsona.com

9 Mar 2010, 1:33 AM
#5
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

Hmm, this didn't seem to effect the Product Listing Pages.
Would this only affect the "All Products" listings? I don't use the All Products link.

I'm looking to make this change (Maximum 4 Qty Displayed) on the Product Listing Pages when you view a Category.

9 Mar 2010, 2:43 AM
#6
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

I should add that I looked for a similar string in tpl_index_products_list.php and tpl_index_default.php and tpl_modules_product_listing.php

But I didn't see a line similar to what you had posted above.

9 Mar 2010, 6:20 PM
#7
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

Is there something I could add to this line in tpl_modules_product_listing.php ?

<div id="productsListingBottomNumber" class="navSplitPagesResult back"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></div>

Just grasping at straws here =)

10 Mar 2010, 3:15 PM
#8
apsona avatar

apsona

Zen Follower

Join Date:
Jan 2010
Posts:
190
Plugin Contributions:
1

Re: Is there a way to limit the quantity displayed?

Hi rubbercarp,

I wasn't able to locate the particular file that renders the page you are asking about. Do you think you could post the result of a 'view source' of that page? Or send me by email/PM, if you prefer - that might work better. I will look into it and try to help.

Best regards,
Apsona

http://apsona.com

10 Mar 2010, 4:15 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Is there a way to limit the quantity displayed?

A note about file edits:

You should NEVER edit the default version of a file; COPY it to a /your_template/ folder in the correct folder tree structure, and edit the copy there.
So instead of
includes/templates/template_default/templates/tpl_product_info_display.php
edit
includes/templates/your_template/templates/tpl_product_info_display.php
(replace your_template with your actual custom template name).

For the listing page, copy
/includes/modules/product_listing.php
to
/includes/modules/your_template/product_listing.php
and edit that.

10 Mar 2010, 7:14 PM
#10
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

Apsona -

My website is https://www.ccg-singles.com
(I keep 100 - 300 products per category page, so the view source of the product listing page is a little large to post here)

The majority of my buyers will just click on the categories and make their selections from there.

Currently when you click on a category it will show you the entire number of each product in stock. But thanks to your edit when you click on a product and go to the product info page, if I have more than 4 in stock it will only show that there are 4 in stock. This is what I would like to reflect on the Product Listing pages as well (which is what I believe you are looking at when you click on a category)

gjh42-

Thank you for that information, I will be sure to that now when editing these files.

10 Mar 2010, 8:10 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Is there a way to limit the quantity displayed?

For the listing page,
/includes/modules/your_template/product_listing.php

The case 'quantity': section in the second set of cases will be the location to edit.

10 Mar 2010, 9:55 PM
#12
apsona avatar

apsona

Zen Follower

Join Date:
Jan 2010
Posts:
190
Plugin Contributions:
1

Re: Is there a way to limit the quantity displayed?

Hi rubbercarp,

It looks like you will need to edit line 154 or thereabouts. The 4 lines around there should currently look like this:

    case 'PRODUCT_LIST_QUANTITY':
    $lc_align = 'right';
    $lc_text = $listing->fields['products_quantity'];
    break;

Change to this:

    case 'PRODUCT_LIST_QUANTITY':
    $lc_align = 'right';
    $lc_text = min (4, $listing->fields['products_quantity']);
    break;

That should do it.

Oh, by the way, thanks for the PM. You are quite welcome. Glad I could be of use to you.

Regards.

Apsona

http://apsona.com

10 Mar 2010, 11:11 PM
#13
apsona avatar

apsona

Zen Follower

Join Date:
Jan 2010
Posts:
190
Plugin Contributions:
1

Re: Is there a way to limit the quantity displayed?

And of course I should have said that the file to me modified is /includes/modules/your_template/product_listing.php, as gjh42 pointed out. Sorry for the omission.

Regards.

Apsona

http://apsona.com

15 Mar 2010, 5:58 PM
#14
rubbercarp avatar

rubbercarp

New Zenner

Join Date:
Feb 2010
Posts:
21
Plugin Contributions:
0

Re: Is there a way to limit the quantity displayed?

Fantastic!
Thanks guys