Forums / All Other Contributions/Addons / Stock For Product With Different Attributes (OLD)

Stock For Product With Different Attributes (OLD)

Locked

Started by dafonz on 30 Nov 2005, 8:52 PM · Views: 80,867

Results 121 to 140 of 273
This thread is locked. New replies are disabled.
14 Feb 2006, 6:18 PM
#121
cslhypnotech avatar

cslhypnotech

Zen Follower

Join Date:
Aug 2005
Posts:
133
Plugin Contributions:
0

Stock For Product With Different Attributes (OLD)

grayson:

It's in these lines (all of them, I'd guess):

if ($products_options->fields['quantity']) > 0)

> 
> Remove the ) before the >. Typo ;).
 Same typo on lines 206 and 215. Working great now, thanks a ton.   ::tup
15 Feb 2006, 5:09 PM
#124
ringy avatar

ringy

New Zenner

Join Date:
Dec 2005
Posts:
62
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Stunning! Works a treat, thanks dafonz, BigWil and grayson :D

So, in my bid for perfection, I have two more questions:

  1. Can I add an image in place of the text created by TEXT_ATTRIBUTES_IN_STOCK and TEXT_ATTRIBUTES_NOT_IN_STOCK strings? I ask, because it would be more striking, and I could embed some text into the image that says "your choice will be ordered straight away.....blah blah", or create a pop-up or hover-text that explains this. B)

  2. I use Easy Populate to manage my inventory. Any ideas on how to extend it to deal with the extra database table for attribute stock? (Sorry, bit of a newbie, but learning fast ;) )

Cheers!

15 Feb 2006, 8:36 PM
#125
yahaira avatar

yahaira

New Zenner

Join Date:
Feb 2006
Posts:
77
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

grayson's addition is just what I was looking for! I made the changes in main_template_vars_attributes.php to get the stock number but I cant seem to get it working. is there something I need to do in admin?

http://www.pureknits.com/catalog/index.php...products_id=180

thanks!

15 Feb 2006, 9:11 PM
#126
ringy avatar

ringy

New Zenner

Join Date:
Dec 2005
Posts:
62
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

**grayson's addition is just what I was looking for! I made the changes in main_template_vars_attributes.php to get the stock number but I cant seem to get it working. is there something I need to do in admin? **

A long shot, but have you installed the original contribution and added a table to your database as described in earlier posts in this thread?

15 Feb 2006, 9:24 PM
#127
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Yahaira, it looks like dropdowns don't use the same variables to display the attributes as all the other options do (oddly enough). That's why you aren't seeing the changes. If you temporarily switch your attributes to one of those two, you should see the stock amounts show up (just to test that it's working properly for that).

If you want it to show up for dropdowns, you'll have to go searching in there to find where the text values for the dropdown menu entries get set, and add in this part:

' [' . $products_options->fields['quantity'] . ' '. TEXT_ATTRIBUTES_PIECES . ']' 
15 Feb 2006, 9:46 PM
#128
yahaira avatar

yahaira

New Zenner

Join Date:
Feb 2006
Posts:
77
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

thanks grayson! you were exactly right, it's working with the radio buttons but not the dropdown menu. Ill dig around and report back on what I find ; )

15 Feb 2006, 10:16 PM
#129
yahaira avatar

yahaira

New Zenner

Join Date:
Feb 2006
Posts:
77
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

// find default attribute if set to for default dropdown
if ($products_options->fields['attributes_default']=='1') {
$selected_attribute = $products_options->fields['products_options_values_id'];
}

      $products_options->MoveNext();

    }

// normal dropdown menu display
if (isset($_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']])) {
$selected_attribute = $_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']];
} else {

these are the 2 instances that i find "dropdown" in, would I change one of these? sorry im still a php newb

15 Feb 2006, 10:33 PM
#130
studmuffin avatar

studmuffin

New Zenner

Join Date:
Nov 2005
Posts:
9
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

guys

installed this mod, its cool thx but when an order is placed it takes the stock off the product stock rather than the attributes stock.

i see it says to edit orders.php but i cant find it, and dont know what to edit.

can anyone help a newbie pls

thx x :)

16 Feb 2006, 5:27 AM
#131
bigwil avatar

bigwil

New Zenner

Join Date:
Dec 2005
Posts:
35
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

afx114:

Actually I'm finding out that an On/Off switch is pretty useless, because the code already handles everything normally whether or not there are products with attribute stock entered.

BigWil, what were you hoping to accomplish by making this module toggleable?
afx114,

Sorry I missed this post until I was reviewing the progress just now. What I intended by the toggle was to turn it off so that the core code revisions wouldn't go into effect if not turned on. Thus it wouldn't effect the stock attribute operations. If it already doesn't then thats great but a toggle would still be convenient so as to not confuse the store owner with the extra admin screens.

I swear I had some sort of problems trying to do stock operations with this installed though. I will have to go back and test again.

Any idea of when the new release will be available? I saw some cool modifications by Grayson that you might also want to include.

Cheers,

BigWil

Install Zen Cart and all the best goodies in less than 60 seconds. http://www.hyperconx.com - Now serving v1.2.7d

16 Feb 2006, 8:41 AM
#132
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

I found a problem with my code a few posts back to display the stock quantity for each attribute next to that attribute: it breaks text attributes (because they don't have a quantity). Here's the fix.

In includes/modules/pages/product_info/main_template_vars_attributes.php, replace

    $sql = "select  pov.products_options_values_id,
             pov.products_options_values_name,
             pwas.quantity,
             pa.*
        from   " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
        where   pa.products_id = '" . (int)$_GET['products_id'] . "'
        and    pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
        and    pa.options_values_id = pov.products_options_values_id
        and    pwas.stock_attributes = pa.products_attributes_id
        and    pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
        $order_by;

with

    if ($products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_TEXT && $products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_FILE && $products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_READONLY) {
    $sql = "select  pov.products_options_values_id,
             pov.products_options_values_name,
             pwas.quantity,
             pa.*
        from   " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
        where   pa.products_id = '" . (int)$_GET['products_id'] . "'
        and    pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
        and    pa.options_values_id = pov.products_options_values_id
        and    pwas.stock_attributes = pa.products_attributes_id
        and    pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
        $order_by;
    } else {
    $sql = "select  pov.products_options_values_id,
             pov.products_options_values_name,
             pa.*
        from   " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
        where   pa.products_id = '" . (int)$_GET['products_id'] . "'
        and    pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
        and    pa.options_values_id = pov.products_options_values_id
        and    pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
        $order_by;
    }

This uses the original query for text, readonly, and file type attributes, and uses the new query with quantity for dropdowns, checkboxes, and radio buttons.

16 Feb 2006, 10:06 AM
#133
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

studmuffin:

guys

installed this mod, its cool thx but when an order is placed it takes the stock off the product stock rather than the attributes stock.

i see it says to edit orders.php but i cant find it, and dont know what to edit.

can anyone help a newbie pls

thx x :)
Go into the contribution files you downloaded, open up classes/order.php, and copy over the code changes beginning at line 645 or thereabouts. They are clearly marked as additions for this contribution. Copy over everything down through the "end of change" marker.

16 Feb 2006, 11:23 AM
#134
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Originally posted by studmuffin
**hmm, i double checked what i did, and i copied order.php over the top of my origonal so this code should be there :/

any ideas x

thanks again**
Did you copy classes/order.php over? The instructions refer to "classes/orders.php" but that's a typo. It may be confusing you since there's also an admin/orders.php file. (And an admin/includes/classes/order.php -- that's NOT the one you want to modify.)

16 Feb 2006, 11:24 AM
#135
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Another thought: this mod will still take the number of items sold off the product stock (as that is the sum of the stock for all attributes). Are you sure it isn't also decrementing the individual attribute stock?

16 Feb 2006, 11:58 AM
#136
studmuffin avatar

studmuffin

New Zenner

Join Date:
Nov 2005
Posts:
9
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

yeah i guessed it was a typo, its replaced the correct one - includes/classes/order.php.

if i do a test order it only updates the total stock amount not the attribs, so eg the attribs will say red = 50 blue = 50 but the total will be 99 cos 1 just got bought...... ' hope i explained that ok...

here is my order.php

http://netfinity.co.uk/order.zip

sorry to be a pain :) thx for any input...

16 Feb 2006, 1:07 PM
#137
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

studmuffin, I compared your order.php to mine and there are no appreciable differences between your attributes with stock code and mine. (Just a couple of extra spaces at the end of one or two lines, but I don't see how that could make a difference.)

The problem lies elsewhere....

16 Feb 2006, 1:44 PM
#138
yahaira avatar

yahaira

New Zenner

Join Date:
Feb 2006
Posts:
77
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

grayson:

I found a problem with my code a few posts back to display the stock quantity for each attribute next to that attribute: it breaks text attributes (because they don't have a quantity). Here's the fix.

In includes/modules/pages/product_info/main_template_vars_attributes.php, replace

       $sql = "select    pov.products_options_values_id,
                         pov.products_options_values_name,
                         pwas.quantity,
                         pa.*
               from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
               where     pa.products_id = '" . (int)$_GET['products_id'] . "'
               and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
               and       pa.options_values_id = pov.products_options_values_id
               and       pwas.stock_attributes = pa.products_attributes_id
               and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
               $order_by;

> with
> ```
       if ($products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_TEXT && $products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_FILE  && $products_options_names->fields['products_options_type'] != PRODUCTS_OPTIONS_TYPE_READONLY) {
        $sql = "select    pov.products_options_values_id,
                          pov.products_options_values_name,
                          pwas.quantity,
                          pa.*
                from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
                where     pa.products_id = '" . (int)$_GET['products_id'] . "'
                and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
                and       pa.options_values_id = pov.products_options_values_id
                and       pwas.stock_attributes = pa.products_attributes_id
                and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                $order_by;
        } else {
        $sql = "select    pov.products_options_values_id,
                          pov.products_options_values_name,
                          pa.*
                from      " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
                where     pa.products_id = '" . (int)$_GET['products_id'] . "'
                and       pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
                and       pa.options_values_id = pov.products_options_values_id
                and       pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                $order_by;
        }

This uses the original query for text, readonly, and file type attributes, and uses the new query with quantity for dropdowns, checkboxes, and radio buttons.
so would this typo fix allow for the stock number to be shown in the dropdown menu?

16 Feb 2006, 1:52 PM
#139
grayson avatar

grayson

Totally Zenned

Join Date:
Oct 2005
Location:
Netherlands
Posts:
516
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Yahaira - no, it won't fix the display of stock for dropdown menu attributes. It fixes a problem with text and file attributes, which don't have any associated quantity, and therefore were not being selected by the SQL query I used.

16 Feb 2006, 11:17 PM
#140
studmuffin avatar

studmuffin

New Zenner

Join Date:
Nov 2005
Posts:
9
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

hmmmz

any ideas....i'm at a loss :(

x ::frust