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
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:
{$lang.in_stock}{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"}
{/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?
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 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.
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 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?
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