CS 2.0 In Stock Available/Unavailable or Yes/No

I am loving this new template editor and if it knows what your changes are, like I believe is how it is supposed to work, to avoid conflicts in future upgrades, it is totally awesome.



Anyway, this took me all of about 3 minutes to find and edit. It’s taking me longer to post it. LOL



EDIT THIS AND ALL OF YOUR FUTURE TEMPLATE EDITS VIA DEMO MODE IF POSSIBLE



Activate Demo mode and go to your store and select a product. Hover on the icon for the product box. You want to select views/products/components/buy_now.tpl and make the changes below in [COLOR=“Blue”]blue[/COLOR].



You can edit it how you like but you will also need to create language variables as well:



stock - need to create - I replace in stock

available - already in languages - Can substitute for Yes

unavailable - need to create - Can substitute for No


<div class="form-field product-list-field"><br />
	<label>{$lang.[COLOR="Blue"]stock[/COLOR]}:</label><br />
	<span id="qty_in_stock_{$obj_id}" class="qty-in-stock"><br />
	{if ($product.amount <= 0 || $product.amount < $product.min_qty) && $product.tracking == "B"}<br />
		{$lang.[COLOR="Blue"]unavailable[/COLOR]}<br />
	{else}<br />
		{$lang.[COLOR="Blue"]available[/COLOR]}<br />
	{/if}<br />
	</span><br />
</div><br />
{else}<br />
	<span id="qty_in_stock_{$obj_id}" class="qty-in-stock"><br />
	{if ($product.amount <= 0 || $product.amount < $product.min_qty) && $product.tracking == "B"}<br />
		{$lang.[COLOR="Blue"]unavailable[/COLOR]}<br />
	{/if}<br />
	</span><br />
{/if}

This works if there are no options. It shows as “available” for a split second until the page fully loads on products with options.

Sorry moka, I don’t do options. Try using the editor in the product with options page and see if you can’t find something.

Customization mode works well for helping to find your way around the the templates and making changes. Unfortunately, those changes are made to the base TPL file which means that they will need to be reconciled when any future updates replace that TPL file.



The better approach would be to make changes using the ‘hooks’ feature which is vaguely documented at [url]http://docs.cs-cart.com/cscart-architecture[/url] (see the Template Hook section). tbirnseth does a better job of explaining it in this post:

[url]http://forum.cs-cart.com/showpost.php?p=47011&postcount=1[/url] (review the desciption of how it works part):


[QUOTE]As an example, to replace the cart’s standard ‘bottom’ section (set of links and other formatting), you

would create the file:

skins/[active_skin]/customer/addons/local/hooks/index/bottom.override.tpl.

This will tell the system to replace the content inside of the ‘hook’ template tag

{hook name=“index:bottom”}

Standard content

{/hook}

with the content contained within the bottom.override.tpl file.[/QUOTE]



There is a hook starting at line 107 and ending at line 128 which deals with displaying the stock quantity:

{hook name="products:options_advanced"}



If you make your changes using a hook, future upgrades won’t overwrite your mod which is in a local file.



The real problem, at this point, is that we have a real, working solution using tbirseth’s Local add-on but it has not been ‘blessed’ by the developers who seem to be doing there own thing with the “My changes” add-on. Any changes using tbirnseth’s add-on should be easily ported to the “My changes” add-on when it becomes available - well, at least in theory.



Bob

I want to write on some products Stock : “Contact us for delivery time”, how can this may be possible ?

[quote name=‘miracles’]I want to write on some products Stock : “Contact us for delivery time”, how can this may be possible ?[/QUOTE]

For conditional displaying, you have to know the condition!

What does this mean ?

[quote name=‘moka’]This works if there are no options. It shows as “available” for a split second until the page fully loads on products with options.[/QUOTE]



Same problem here. I also use Options, and I would like to show “Available” only, not the number of items. How can I do this?



Thank you.

To get Available/Unavailable to display for products with options, do the following:



In /js/exceptions.js, change:

pstock.html(pr_a[id][i]['amount'] + ' ' + lang.items);

to

pstock.html('' + lang.available + '');



AND, just below, change:

pstock.html('' + lang.text_out_of_stock + '');

to

pstock.html('' + lang.unavailable + '');

You can remove the ‘class=“price”’ if you don’t want “Unavailable” in bold red text.



Then, add the lines in red to /skins/YOURSKIN/customer/common_templates/scripts.tpl:

var lang = {$ldelim}
cannot_buy: '{$lang.cannot_buy|escape:"javascript"}',
no_products_selected: '{$lang.no_products_selected|escape:"javascript"}',
error_no_items_selected: '{$lang.error_no_items_selected|escape:"javascript"}',
delete_confirmation: '{$lang.delete_confirmation|escape:"javascript"}',
[COLOR="Red"]available: '{$lang.available|escape:javascript}',
unavailable: '{$lang.unavailable|escape:javascript}',[/COLOR]
text_out_of_stock: '{$lang.text_out_of_stock|escape:javascript}',
items: '{$lang.items|escape:javascript}',




Create the language variable ‘unavailable’ if it does not exist.



The quantity flashes briefly before “Available” or “Unavailable” is displayed but this otherwise seems to works perfectly.



Note that you still need to do the mod in the first post for products without options.



Bob

Consolidated in post #9 above.

Rookie whish: How about displaying stock level using “trafic light” or a “smiley” ?



See example here



Green: > 1 pce in stock

Orange: = 1 pce in stock

Red: <= 0 pce in stock

[quote name=‘aerofan’]Rookie whish: How about displaying stock level using “trafic light” or a “smiley” ?



See example here



Green: > 1 pce in stock

Orange: = 1 pce in stock

Red: <= 0 pce in stock[/QUOTE]

If you are not using options, you need to add your additional if statements and change the result to display to your image in /skins/YOURSKIN/customer/views/products/components/buy_now.tpl. You want the following block of code:

```php

[COLOR=“Red”]{if ($product.amount <= 0 || $product.amount < $product.min_qty) && $product.tracking == “B”}

{$lang.text_out_of_stock}[/COLOR]

[COLOR=“Blue”]{else}

{$product.amount} {$lang.items}[/COLOR]

{/if}



{else}

[COLOR="red"]{if ($product.amount <= 0 || $product.amount < $product.min_qty) && $product.tracking == "B"}
{$lang.text_out_of_stock}[/COLOR]
{/if}
```

The parts in red deal with out of stock conditions, so you just need to display your graphic instead of the language variable.

You will need to modify the part in blue to add your additional if statements testing for quantities of 1 and >1 and to display your graphic.

Bob

The solution in #9 works great! Thank you!



However, there seems to be one problem. I am using Options. New language I added cannot seems to be displayed in the options. For example, I added text_stock_available in Language. Then I added



text_stock_available: ‘{$lang.text_stock_available|escape:javascript}’,



in scripts.tpl



Then I added pstock.html(‘’ + lang.text_stock_available + ‘’);



in exceptions.js. But it displays as “Undefined” on the webpage. Why? My temporary solution is to hardcode the text in exceptions.js and also buy_now.tpl.

You need to add text_stock_available in skins/YOURSKIN/customer/common_templates/scripts.tpl as shown above.



Bob

After doing changes in post #9 above for items with inventory tracking with options, the in-stock products indicated “undefined” in the front end. So I made the following changes:



Instead of putting:

pstock.html(‘’ + lang.available + ‘’);



I put:

pstock.html(‘’ + {$lang.available} + ‘’);





and instead of:

pstock.html(‘’ + lang.unavailable + ‘’);



I put:

pstock.html(‘’ + {$lang.unavailable} + ‘’);

Note I just added the {$ and }



Now product with options display same a those without.



OK: One little note. I checked to make sure before posting. Turns out the product with options that are out of stock show as “Available”



Oh well, I can live with that until someone figures it out.

[quote name=‘marvinjh’]

OK: One little note. I checked to make sure before posting. Turns out the product with options that are out of stock show as “Available”



Oh well, I can live with that until someone figures it out.[/QUOTE]



Weird, double check the logic and make sure you entered the correct code at the correct condition.



For me available/not available displays fine. Just that I hardcoded the text instead of using $lang… now since it works, I am lazy to change to $lang already, haha.

Hi



Have checked and double checked, but available flashes on and then undefined appears.



using options!



have I missed something?



Barry

No worries, it started to work!!! :confused:

I have the same Undefined problem using 2.0.10 electro skin. if anyone stumbles across a good solution please post. I have just switched to track without options for now.

cheers

Scott



Followed instructions from post 1 and 9

how to do this again?

there is no more of buy_now.tpl

where is buy_now.tpl and how to show inventory quantity in product page?