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