Help me change Product Page code?

It seems like I need to adjust some code to fix my inventory problems. I found the code, but my attempts to change it keep breaking the cart :frowning:



I need the cart to track inventory, but not show that inventory to the customers. Apparently these two conditions are mutually exclusive in 2.012. Other threads discussing this refer to older versions and files that no longer exist in 2.012, hence the call for help.



Ideally, Iā€™d like the ā€œAdd to Cartā€ button to appear normally if thereā€™s product in inventory, and ā€œOut of Stockā€ to appear when there is 0 in inventory. (Yes, thereā€™s a checkbox that does that, but it disables inventory tracking :mad:)



I only have ā€œList without optionsā€ enabled for the Product List, and the inventory does not show up there when ā€œDisplay In stock as a fieldā€ is enabled. So, I only need to execute this change on the product details page.



Can anyone (pretty please!) tell me where/how can I hide the inventory with a code edit?

If you can live with the ā€œIn stockā€ display, you can do all this without any code changes.



In Design->Appearance settings, uncheck ā€œDisplay stock as fieldā€.



On your product, set inventory to ā€œTrack with optionsā€ then go to the options tab and either rebuild your option combinations or enter the inventory for each option combination.



When the customer views the product, he will see either ā€œIn stockā€ or ā€œOut of stockā€. The inventory will be reduced based on the ā€œInventoryā€ setting in Order Statuses.



If you feel you just must change this, you will need to sort out the code in /skins/YOURSKIN/customer/common_templates/product_data.tpl:

{capture name="product_amount_`$obj_id`"}
{if $show_product_amount && $product.is_edp !== "Y" && $settings.General.inventory_tracking == "Y" && $product.tracking != "D"}
{if $settings.Appearance.in_stock_field == "Y"}
{if ($product.amount >= 0 && $product.amount >= $product.min_qty) || $product.tracking != "B"}




{$product.amount} {$lang.items}


{/if}
{else}
{if ($product.amount >= 0 && $product.amount > $product.min_qty) || $product.tracking != "B"}

{$lang.in_stock}


{/if}
{/if}
{/if}
{/capture}




You will also need to make changes in /js/exceptions.js:

// ***************************************** A M O U N T I N S T O C K **********************************/
//
// Changes amount in stock if product inventory is in track with options
//
function fn_change_amount(id)
{
var key = '';
var pqty = $('#qty_' + id); // input with qty
var pstock = $('#qty_in_stock_' + id); // qty in stock line
var istock = $('#in_stock_info_' + id); // "in stock" text
var padd = $('#cart_buttons_block_' + id); // add to cart button
var spadd = $('#cart_add_block_' + id);
var badd = $('#bulk_addition_' + id); // bulk add to cart checkbox

key = fn_get_option_combination_key(id, '_');

if (typeof(pr_a[id][key]) != 'undefined') {
if (pr_a[id][key]['amount']) {
if (pr_a[id][key]['amount'] > 0) {
pstock.show();
pstock.html(pr_a[id][key]['amount'] + ' ' + lang.items);
istock.show().addClass('in-stock').removeClass('out-of-stock').html(lang.in_stock);
pqty.show();
padd.show();
spadd.show();
badd.attr('disabled', false);
} else {
if (allow_negative_amount) {
pstock.hide();
istock.hide();
pqty.show();
padd.show();
spadd.show();
badd.attr('disabled', false);
} else {
pstock.html('' + lang.text_out_of_stock + '');
istock.addClass('out-of-stock').removeClass('in-stock').html(lang.text_out_of_stock);
pqty.hide();
padd.hide();
spadd.hide();
badd.attr('disabled', true);
}
}
return true;
}
}

for (var i in pr_a[id]) {
pstock.html('' + lang.text_out_of_stock + '');
pqty.hide();
padd.hide();
spadd.hide();
badd.attr('disabled', true);
break;
}

return true;
}




I will try to take a look at this if I have a chance later.



Bob

Thatā€™s sounding good! Will it still work if I do what you said, but donā€™t have any options? Not using any at this time.

[quote name=ā€˜Dardanusā€™]Thatā€™s sounding good! Will it still work if I do what you said, but donā€™t have any options? Not using any at this time.[/QUOTE]

Are you talking about not changing the code? If so, it should work fine. If you want to change the code, the product_data.tpl sets the display for items without options and the exceptions.js sets the display for items with options (as least as best I can remember).



Bob

Oh, I would love to fix this without changing the code! Iā€™m no PHP expert, that is for sure.



I tried your steps and only see ā€œTrack without Optionsā€ and ā€œDo Not Trackā€ in a productā€™s inventory settings. Do I need to enable ā€œTrack with Optionsā€ somewhere else? :confused:



Also, it sounds like this will need to be set on all products. Thatā€™s the ā€œInventory Trackingā€ field on product export, right? Sounds like a good job to handle in a CSV and then import that column back in.

In Administration->General settings, check ā€œEnable inventory trackingā€ - this will allow you to set the track with options.



Yes, the ā€˜Inventory trackingā€™ field in the export specifies this setting. The options are:

D - Do not track

B - Track without options

O - Track with options



Change them and then reimport but you will also need to make sure you have options specified on your product - the cart will not allow you to track with option an item that has no options.



Bob

[quote name=ā€˜jobosalesā€™]Change them and then reimport but you will also need to make sure you have options specified on your product - the cart will not allow you to track with option an item that has no options.[/QUOTE]



Arrrgh :wink: I donā€™t have options for any products. So, to make this work I either need to enable an option for everything, or mess with the code. I guess I could make an option that does not really do anything - option ā€œleave out packing slipā€ for example. That would serve someone who is sending a gift direct, and would leave me with no extra work to do no matter what they selected.



Guess I have my work cut out for me. Iā€™ll post back if anything goes wrong, but in the meantime, thanks very much for your help!

Maybe I am missing something but if you do not need options on your products, why canā€™t you just track the inventory without options? If your inventory is maintained at the product level and not the product option level, this is the way I would go.



Bob

Iā€™d love to track inventory without options. I also need to not show that inventory to my customers. If I check that box in adminā€¦ the cart stops keeping track of inventory. It just wonā€™t add or remove anything from stock. Itā€™s like I can hide it or track it, but not both.



So, where do I go from here?

I just checked this in 2.0.14 and it works properly. As far as I know, it has always worked.



In General Settings, make sure that ā€œEnable inventory trackingā€ is checked.



In Appearance Settings, make sure that ā€œDisplay In stock as a fieldā€ is unchecked (the quantity will be shown as ā€œIn stockā€ or ā€œOut of stockā€)



For each of your products, set Inventory to ā€œTrack without optionsā€ and set the ā€œIn stockā€ quantity for each item. You should also specify the product code if you have one. You will not need to do anything with options.



When you place the your order, the stock should be reduced if the order status is ā€˜Openā€™ or ā€˜Processedā€™.



Bob

[quote name=ā€˜jobosalesā€™]In General Settings, make sure that ā€œEnable inventory trackingā€ is checked.[/QUOTE]



Done.


[QUOTE]In Appearance Settings, make sure that ā€œDisplay In stock as a fieldā€ is unchecked (the quantity will be shown as ā€œIn stockā€ or ā€œOut of stockā€)[/QUOTE]



Done.


[QUOTE]For each of your products, set Inventory to ā€œTrack without optionsā€ and set the ā€œIn stockā€ quantity for each item. You should also specify the product code if you have one. You will not need to do anything with options.[/QUOTE]



Done, done, and done.


[QUOTE]When you place the your order, the stock should be reduced if the order status is ā€˜Openā€™ or ā€˜Processedā€™. [/QUOTE]



Many a test order, not happening. I adjust status of the test orders, then go refresh the inventory, and nothing changes. :cry:



Not trying to pick a fight here, just an explanation: What got me thinking that ā€œhideā€ and ā€œtrackā€ are mutually exclusive, was this post and the thread it refers to. These refer to older versions and the buy.tpl file is no longer available in 2.012, or I would have just attempted the mods discussed there. Has inventory handling changed since those threads were posted? The statements made there are the reason I was assuming that code mods were necessary to resolve this mess.



So, should I be troubleshooting my store, or trying to tackle the product_data.tpl changes? I tried the code first, and all I accomplished was creating smarty template errors on my live store :shock: Swiftly rectified errors, but still :wink:

[quote name=ā€˜Dardanusā€™]Not trying to pick a fight here, just an explanation: What got me thinking that ā€œhideā€ and ā€œtrackā€ are mutually exclusive, was this post and the thread it refers to. These refer to older versions and the buy.tpl file is no longer available in 2.012, or I would have just attempted the mods discussed there. Has inventory handling changed since those threads were posted? The statements made there are the reason I was assuming that code mods were necessary to resolve this mess.



So, should I be troubleshooting my store, or trying to tackle the product_data.tpl changes? I tried the code first, and all I accomplished was creating smarty template errors on my live store :shock: Swiftly rectified errors, but still ;)[/QUOTE]

I posted part of the solution in the ā€œAvailable/Unavailableā€ thread if I recall. The issue there was that you had to display the actual stock quantity if inventory tracking was enabled. The change the developers made was basically the inclusion of our ā€œAvailable/Unavailableā€ mods using the new ā€œDisplay In stock as fieldā€ setting.



As I said, everything works for me in a 2.0.14 installation - maybe something has changed since 2.0.12, but I thought it always worked the way it currently works for me.



Bob

I canā€™t help but think this is connected to my unchangeable product status problem which apparently has a historic connection to inventory levels.



Iā€™ll test it some more tomorrow. On some of my tests, status code changes were adjusting inventory, sort of, but not in a reliable way. Today nothing seemed to change no matter what status I chose.



I can handle some inventory by hand for a short time while getting this fixed, but need to find an answer quickly, or this becomes a dealbreaker. I really donā€™t want to give up on this cart, it has so many things I need! Inventory control is key for me though and here it is failing in a major way. (Or apparently failing. We donā€™t have floods of other people complaining about this, so my cart/changes/hooks are certainly suspect.)



Iā€™d consider an upgrade to 14 but it looks like thereā€™s some issues (messy product pages for one) I was hoping to avoid by staying with 12 for a while.

Why donā€™t you install a clean version of 2.0.12 and test it to see if it works the way you want? If it does, then just move over your changes to it and your images and switch it to use your current database.

I just tested this on a 2.0.12 install and it works as I described above. Perhaps some changes you have made are affecting this.



Bob

[quote name=ā€˜Dardanusā€™]I canā€™t help but think this is connected to my unchangeable product status problem which apparently has a historic connection to inventory levels.



Iā€™ll test it some more tomorrow. On some of my tests, status code changes were adjusting inventory, sort of, but not in a reliable way. Today nothing seemed to change no matter what status I chose. [/QUOTE]

Try processing an order using an offline payment method like ā€œPhone Orderingā€. This should set the order status to ā€˜Openā€™ and reduce the inventory and this test will remove one variable. If this works properly, then we can focus on how your payment methods are interfering with the inventory adjustments; if it does not work properly then we will need to look at changes made to the code. As I said above, I tested it again with a 2.0.12 install and everything appears to work properly.



Bob

Okay, I think I may have figured out part of the problem. Are your orders still getting the ā€˜Backorderedā€™ status from the processor? Since the the inventory movement for the ā€˜Backorderedā€™ status is increase, I think the inventory is not being affected. As I suggested above, try an offline method (which should return an 'Open" status) to see if inventory is being reduced.



I am not sure why you get the ā€˜Backorderedā€™ status on your orders with online payments - it seems most people get either ā€˜Processedā€™ or ā€˜Declinedā€™. I am wondering if it has something to do with your configuration. For your Authorize.net payment method, do you have the ā€˜transaction typeā€™ set to ā€œAuthorize onlyā€ or ā€œAuthorize and captureā€? I am thinking that there are some inconsistencies between your payment configuration and the settings in your Authorize.net account that prevent getting an appropriate response from the processor in which case CS-Cart sets the status to ā€˜Backorderedā€™.



Bob

I have been getting ā€œbackorderedā€ statuses. Looks like I have some extensive testing to do and will definitely try a test install to compare. Switching to a fresh install will be a lot less hassle than trying to find a mystery glitch!



I will post back with results later today.



Thanks again, donā€™t know what I would do without this user forum. Everybody here rocks!

I closed the store last night, put Authorize.net into test mode, and swapped to an unaltered skin. I was hoping to avoid a reinstall and it looks like I have traced the Mysterious Inventory/Order Status Gremlin.



Itā€™s twofold. First of all, playing extensively with test orders assured me that the cart is indeed adjusting inventory just as it should. Thatā€™s a huge relief ā€“ no error in the cartā€™s core functionality.



The key issue then became order status. Putting Authorize.net in test mode (which returns an instant ā€œpaid/approvedā€ status), resulted in immediate updates to ā€œpaidā€ on some orders, but not all. ā€œPay by phoneā€ same results ā€“ some orders were assigned ā€œopenā€ status, and others "backordered. Any order that processed as ā€œopenā€ would be fine, any order that processed to ā€œbackorderā€ would be stuck that way. WHY?



I soon found Reason #1. Thanks to Ogiaā€™s experience with PayFlow Pro errors, it occured to me to compare character usage between good orders and problem orders. That was it - curly quotes and/or slashes in the product names! I removed the offending characters, saved the product, and one of my problem test orders accepted a status change to Paid and removed the products from inventory. Woooo!



Reason #2 was just a lack of understanding on my part. I read elsewhere that if changing a backordered order to ā€œpaidā€ would create a negative inventory, the cart wonā€™t change the status. I played long enough with order statuses and manually adjusting inventory amounts to assure myself that this is the case. Any order that would not allow a status change after character cleanup was proven to have low quantities on at least one product, and in every case where I manually added to the item in question - status would update and inventory would be adjusted appropriately.



I donā€™t allow negative inventory, so this behavior makes sense. If a status change would mean subtracting inventory to a negative total, but negative totals are disallowed, the cart wisely does nothing. Now that I know that, it will not be an issue to work around it.



I re-opened the store and locked up the office with a smile on my face last night, and an order that came through this morning processed with no issues. Wooo!



Rather than re-installing the cart, I now have the fun-filled project of find-and-replacing all the #$@#^ curly quotes that got inserted in my product names. I knew that was happening, actually, because I was using NeoOffice to work a product spreadsheet and it was ā€œhelpfullyā€ changing my straight quotes. Didnā€™t bother fixing them at the time, because who knew that curly quotes in the product names could cause so much trouble? :wink:



So, unless further issues come up, thanks heartily to you, Bob, and also to everyone else who documents their issues and solutions here so others can learn. Hopefully someone else will be save a future hassle by reading this. (Hopefully I wonā€™t be posting later today with a new chapter in the saga!)



Also: I promise to use a real text editor for the CSV handling from now on.

Thatā€™s some great investigative work and reporting. Thanks for documenting it so clearly - I am sure it will help someone in the future.



This issue seems like a bug to me. If you can enter something in the cart, it should later be able to use that information without issue. There have been several problems reported caused by extended characters; I wish they could address this once and for all so that this does not crop up over and over again.



Bob