Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

QTPro Contribution question


Guest

Recommended Posts

I have downloaded and installed QTPro 2 for an OSC installation. Works beautifully - except a products stock level per option does not seem to automatically update when I make a purchase.

 

Am I missing something fundamental???

 

I have assigned product attrubtes/quantities for T-shirts - so a tshirt may come in Large Black (lets say we have 10 of these in stock), Large Blue (lets say we have 20 of these in stock), and Small Red (say 5 in stock)

 

Someone comes in and purchase a tshirt - a small red tshirt. The OVERALL quantity of these tshirts reduces, but not the attribute specific quantity.

 

Am i losing my mind, or have others seen this before?

Link to comment
Share on other sites

Yet another fix for QTPro...

 

add this to application_top.php in your catalog folder:

 

  define('TABLE_PRODUCTS_STOCK', 'products_stock');

 

now, in checkout_process.php on approx line 141 there is a segment of code that reads:

 

        if (is_array($products_attributes)) {

         $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[$i]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[$i]['value_id'] . "'";

       }

       $stock_query = tep_db_query($stock_query_raw);

     } else {

 

add this code in after that block:

 

 if (is_array($products_attributes)){

       For($j=0; $j< sizeof($products_attributes); $j++){

        $products_stock_attributes_array[] = $products_attributes[$j]['option_id']."-".$products_attributes[$j]['value_id'];

       }

        $products_stock_attributes = implode(",",$products_stock_attributes_array);

        $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);

        $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];

        if ($attributes_stock_left < 1) {

          tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '0' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        }else{

          tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        }

     }

 

So the entire 'if' statement will look like this:

 

        if (is_array($products_attributes)) {

         $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[$i]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[$i]['value_id'] . "'";

       }

       $stock_query = tep_db_query($stock_query_raw);

     } else {

     if (is_array($products_attributes)){

       For($j=0; $j< sizeof($products_attributes); $j++){

        $products_stock_attributes_array[] = $products_attributes[$j]['option_id']."-".$products_attributes[$j]['value_id'];

       }

        $products_stock_attributes = implode(",",$products_stock_attributes_array);

        $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);

        $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];

        if ($attributes_stock_left < 1) {

          tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '0' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        }else{

          tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

        }

     }

       $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

     }

 

This isn't how I would prefer to do attribute quantity recording, but QTPro does work and, although not perfect, the framework is acceptable. I plan to add drop down boxes instead of option boxes soon during the check out process (I think the option boxes look kinda nasty and un-intuitive, what does everyone else think? Is there already a fix for that?)

 

If you are having other problems, specifilly with customer getting 'null attributes' check out my other fixes for this mod with a quick search for QTPro.

Nothing Unreal Exists

Link to comment
Share on other sites

the above fix works for subtracting from the main stock, but if you go into the admin section and select a product, then click the stock button where the attribute stocks are, the values havent changed, which will still allow someone to add an out of stock item to their cart contents. i am glad to see this contrib is still kinda alive and kicking and maybe it will be a part of the OSC install eventually.

Link to comment
Share on other sites

My above fix only subtracts stock from the attributes if there are no "special" attributes listed for the product (that is, no attributes that have drop down boxes, only those that use radio buttons, ie check boxs).

 

I have fixed it so it works for combinations of both, but it will be a couple days before I post it. I am busy working on final essays for college and graduating this May sort of takes priority :P

 

sorry! :wink:

Nothing Unreal Exists

Link to comment
Share on other sites

Alright, here is comes. This patch should:

 

1) Fix error related to customers having a 'blank' attribute during checkout.

 

2) Force the customer to make an explicit choice when choosing a required attribute.

 

3) Keep track of attribute Inventory (by subtractiong quantities of items from both the products table and the products_attibutes table).

 

Let me apologize for not posting the code for copying into the files. I made so many changes over such a long period of time I lost track of what lines were changed. In the future I will be more careful.

 

Anyway, here are the files:

http://www.msu.edu/~sloughwi/QTPro_Patch.zip

 

checkout_process.php goes in catalog

 

order_details.php goes in catalogincludesmodules

 

order.php goes in catalogincludesclasses

 

shopping_cart.php goes in catalog

 

product_info.php goes in catalog

 

PLEASE make backups of your old files just in case!

 

Let me know of any problems and I will, of course, do what I can.

Also, keep in mind I am using the SPG shipping mod (for manual entries of orders). That might have some effect, so mention if you use it when you report a problem.

 

Good luck

Nothing Unreal Exists

Link to comment
Share on other sites

Ok, here is a bug I found:

 

in checkout_process.php under the line:

 

      

if (is_array($products_attributes)){

 

add the line:

$products_stock_attributes_array = array();

 

 

Eliot: I'm not sure why it is not working for you. I have a snap shot from of OsCommerce from the begining of February, I'm not sure of the version number (or where to get the version number in the code).

I am using QTPro 2.0 as well. The SPG mod really shouldn't effect anything. Make sure you are updating the right files and give me an idea of what effects my patch are having, so I can determain "this works but this doesn't".

 

Also, for those of you using SPG...this fix does not subtract attribute inventory from manual orders, only customer placed orders. I am working on fix for that right now.[/code]

Nothing Unreal Exists

Link to comment
Share on other sites

Hi Paul

 

I realised that it wasn't working for me 'cause i wasn't selecting 'Special' under Product options. However having to select 'Special' i find limiting as it only allows a single option i.e. Colour. I actually want Colour and Size so i commented out some of your code ...

 

         //If($products_attributes[$j]['special'] != 0){

        $products_stock_attributes_array[] = $products_attributes[$j]['option_id']."-".$products_attributes[$j]['value_id'];

        //}

 

from around line 146 of checkout_process.php.

 

I then had a new problem in that if someone adds several items with multiple attributes like in the following ....

 

Billabong T-Shirt - Red - Xlarge

Billabong T-Shirt - Blue - Small

etc

 

Stock is only removed for the first item. I figured out that what was happening was that the array $products_stock_attributes_array wasn't getting cleared down so i inserted

 

    unset($products_stock_attributes_array);

 

just under line 123

 

       if (STOCK_LIMITED == 'true') {

 

this seems to have solved my problems. however i'm still testing.

Link to comment
Share on other sites

Hi Paul

 

I've got rid of my Radio Buttons that the original QTPro made you use for all attributes by replacing their code in product_info.php with the code that i already had in my snapshot of Mar 25 03. Now the null attributes problem has gone away. If you want the replacement code PM me

 

cheers

Link to comment
Share on other sites

The null problem that you talk about shoudl be fixed in my files by javascript code that ensures an option is checked.

I don't know why its not working for you, I have sent the fix to other people and they have not yet had a problem.

 

Any one else out there try this patch and experiance problems?

Nothing Unreal Exists

Link to comment
Share on other sites

Please keep in mind I did not write QTPro. I am not really not impressed with how it was implimented. The PHP is rather impressive but the design is lacking and I think this could have been implimented in a much cleaner way.

 

Anyway, keeping that in mind this category should not be called "special". It shoudl have been called "Infinite Inventory" or "Do not keep track of inventory?". It is there so that you don't have to record stock for it (that is why it disappears under stock.php when its checked). That is why that "IF" statement is there, because stock should not be subtracted from "infinite" attributes.

 

Some people might be confused about why there are radio buttons and not drop down boxes, so let me post something here to clear that up. Drop down boxes would be very nice (and they do appear if you select "special" and force the script to ignore inventory). However, concider for a moment what it would be like to have all drop-down boxes.

 

If you have 2 different attributes for an item, each with 5 choices and you only have one combiniation of all of those in stock, a customer might have to try 25 combinations to find the product that is in stock. Instead, it is better to list every possible combination availible for convienance.

The reason we can use drop-down boxes for attributes that have no stock is because every combination is always valid.

 

Again, this code could have been done a different way. For example, we could have java script look at the customers choice for the first attribute then dynamiclly generate a second attribute drop down box based on the first, etc etc. That would slick, but time consuming to code.

 

If you have any questions post them here so I'm not getting PM'd the same questions over and over! :)

Nothing Unreal Exists

Link to comment
Share on other sites

  • 3 months later...

I'm having problems adding QTpro. It updates the total stock level fine, but does not update the stock levels for indivual attributes. Can anyone with this contrib working post their checkout_process.php so that I can compare it with mine & try to fond the fault?

 

thanks

Link to comment
Share on other sites

I think that is just how it works (or doesn't work, depending on your point of view). In other words, it is nothing that you did. It is part of how the contribution is written. I've seen a couple other people post about this, so there is a decent chance that someone will post a fix.

 

Good luck,

Matt

Link to comment
Share on other sites

  • 1 month later...

I now have thanks to Lynda a working install of QTPro. It looks very exciting although I still need to do plenty of testing.

 

I am looking forward to adapting this to be closer to what I need to handle the attibutes and I still have a lot of questions as I try to get to grips with it. I hope someone can answer some of my questions.

 

Was there an install step missing - adding the definition of the new table TABLE_PRODUCTS_STOCK to catalog/includes/application_top.php?

 

The attributes are all jumbled up together instead of being sorted alphabetically as they were before I installed this. Does anyone understand how to add back the sorting to it. I tried changing the query in a similar way to the way it had been before but, although there was no error, they remained unsorted.

 

There was a suggestion in the forums to use the original products_info with its drop-down menus and perform the stock check in shopping_cart.php. This seemed like a good idea but when I tried it there was no warning given by the shopping cart that the attribute was out of stock as you would normally expect when a product is out of stock.

 

The way I think it should work when out of stock checkout is enabled is:

 

to list the attributes (alphabetically) with next to them a field saying 'out of stock', 'low stock' , or 'in stock'. The check should be performed in the shopping cart as above.

 

The other thing that is a bit strange is that the attributes all have (+0.00) next to them (again unlike the standard version of product_info.php)

 

If you can help with any of these things do reply to this thread.

 

Thanks

Link to comment
Share on other sites

I'm working blind here but I may have solved the sorting problem in product_info.php. :o

I simply removed a bit of seemingly useless code that said:

asort($sa1);

and changed the last bit of the q1 query to

$languages_id . "'" . " order by pov.products_options_values_name");

 

I doesn't seem to have blown anything up :o

Link to comment
Share on other sites

Whilst I have this thread to myself on to the next one...........

 

I notice that although the options for both colour and size are listed, the heading only says 'colour'.

 

I read somewhere in the forums that qtpro may not support more than one attribute which, if true, would severely limit its usefulness. It seems to handle both attributes from the point of view of checking the stock and adding it to the shopping cart. Is it perhaps that it doesn't update the stock correctly?

Link to comment
Share on other sites

Whilst I have this thread to myself on to the next one...........

 

I notice that although the options for both colour and size are listed, the heading only says 'colour'.

 

I read somewhere in the forums that qtpro may not support more than one attribute which, if true, would severely limit its usefulness. It seems to handle both attributes from the point of view of checking the stock and adding it to the shopping cart. Is it perhaps that it doesn't update the stock correctly?

It seems to work fine for me for multiple attributes, but I have only products with attributes selected with radio buttons in the catalog. Are you using radio buttons or dropdowns for your attribute listing?

Link to comment
Share on other sites

Hi Lynda,

I am using the radio buttons.

Which of your products have multiple attributes? I had a look on your site to see if it worked but couldn't find any.

 

I have just sorted out the reason it wasn't showing out of stock in the shopping basket is that I had turned off the stock check feature in admin :oops:

I thought I was just turning off the feature that doesn't show the product in the catalog when it goes out of stock. It turned out I also wasn't checking that there was sufficient stock. It seems there is no way in admin to do one without the other.

Link to comment
Share on other sites

There aren't any products atm with multiple attributes, but once I've finished making some changes to the site, I'll post a link to one.

 

There's code posted somewhere in these forums for showing out of stock products with a greyed out buy button. Searching for *greyed out* or *grayed out* should find it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...