Zen Cart Logo
Forums / All Other Contributions/Addons / Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Views: 658,733

Results 361 to 380 of 3,609
4 Feb 2008, 5:22 AM
#361
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Follow up:

This is the function I currently have to get product quantity:
Note: I used a function I have in my class to turn the result from db query into string, but if you want to make use of the function below you can easily use a loop to do so.

@Kuroi: can you have a look and tell me if there is anything wrong?
I used the option text name and value instead of the ids because I want to make sure that we either the stock of the exact product and attributes or nothing.

<?php
function retrieve_attribute_stock_from_order($attribute_array,$products_id){
    global $db;
    
    // Lets assume that if table TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK is defined, then we are using the stock by attribute mod
    // we can also query database to check if we want to
    if(defined('TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK')){
        $sql_query = 'SELECT products_attributes_id FROM '.TABLE_PRODUCTS_ATTRIBUTES.' pa,'.TABLE_PRODUCTS_OPTIONS_VALUES.' ov,'.TABLE_PRODUCTS_OPTIONS.' o
                WHERE ';
        $condition_array = array();
        if(count($attribute_array) == 0) return;
        foreach($attribute_array as $attribute){
            $condition_array[] = '(ov.products_options_values_name = \''.$attribute['value'].'\' AND o.products_options_name =\''.$attribute['option'].'\' AND pa.products_id = '.$products_id.' AND pa.options_id = o.products_options_id AND pa.options_values_id = ov.products_options_values_id)';
        }
        $sql_query .= implode(' OR ', $condition_array).' ORDER BY products_attributes_id';
    
        $result = $db->Execute($sql_query);
        $yobj = new yclass();
        $attribute_string = $yobj->db_result_to_string(',',$result);
        $get_quantity_query = 'SELECT quantity FROM ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id="' . $products_id . '" and stock_attributes="' . $attribute_string . '" LIMIT 1';

        $quantity = $db->Execute($get_quantity_query);
        if($quantity->RecordCount() == 1)
            return $quantity->fields['quantity'];
    }
    // get products_quantity directly from products table
    $get_quantity_query = 'SELECT products_quantity FROM ' . TABLE_PRODUCTS . ' where products_id="' . $products_id . '" LIMIT 1';    
    $quantity = $db->Execute($get_quantity_query);
    if($quantity->RecordCount() == 1)
        return $quantity->fields['products_quantity'];
    else
        return 0;
}
?>
4 Feb 2008, 10:49 AM
#362
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

yellow1912:

@Kuroi: can you have a look and tell me if there is anything wrong?
I used the option text name and value instead of the ids because I want to make sure that we either the stock of the exact product and attributes or nothing.The code will generate the broadly the right SQL, but I can see one potentially show stopping problem - but it's easily trapped.

Suppose you had a two attribute product where the attributes are size and color. A customer orders (XXXL, Red). (XXXL, Red) is withdrawn - no longer exists. But you still have (XXXL, White) and (XXXL, Black).

Executing your function against (XXXL, Red) will still return the product_attribute_id for XXXL. Your second query will take that as a parameter and, if the attribute stock for (XXXL, Red) has been removed, will return an array of stock quantities for (XXXL, Black) and (XXXL, White), neither of which you want.

You currently have a check that the record count is one, so your response to this situation would be to not return a false attribute stock result (which is good) but instead to drop through and return the overall product stock instead, which I suspect is bad (and a reason why I don't personally like code that relies on returns to control the logic).

Better would be to test earlier that the number of products_attributes_id returned matches the number of attributes in the original array and if not, deal with the exception at that point.

4 Feb 2008, 2:00 PM
#363
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

@yellow1912> kuroi:

if the attribute stock for (XXXL, Red) has been removedshould read
kuroi:

if the attribute for Red has been removed

4 Feb 2008, 3:11 PM
#364
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Thanks Kuroi, that does make sense. I added a simple checking to make sure that we get the number of attribute id we expected, if not then just return 0.

<?php
function retrieve_attribute_stock_from_order($attribute_array,$products_id){
    global $db;
    
    // Lets assume that if table TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK is defined, then we are using the stock by attribute mod
    // we can also query database to check if we want to
    if(defined('TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK')){
        $sql_query = 'SELECT products_attributes_id FROM '.TABLE_PRODUCTS_ATTRIBUTES.' pa,'.TABLE_PRODUCTS_OPTIONS_VALUES.' ov,'.TABLE_PRODUCTS_OPTIONS.' o
                WHERE ';
        $condition_array = array();
        if(count($attribute_array) == 0) return;
        foreach($attribute_array as $attribute){
            $condition_array[] = '(ov.products_options_values_name = \''.$attribute['value'].'\' AND o.products_options_name =\''.$attribute['option'].'\' AND pa.products_id = '.$products_id.' AND pa.options_id = o.products_options_id AND pa.options_values_id = ov.products_options_values_id)';
        }
        $sql_query .= implode(' OR ', $condition_array).' ORDER BY products_attributes_id';
    
        $result = $db->Execute($sql_query);
        
        if($result->RecordCount() != count($attribute_array))
            return 0;
            
        $yobj = new yclass();
        $attribute_string = $yobj->db_result_to_string(',',$result);
        $get_quantity_query = 'SELECT quantity FROM ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id="' . $products_id . '" and stock_attributes="' . $attribute_string . '" LIMIT 1';

        $quantity = $db->Execute($get_quantity_query);
        if($quantity->RecordCount() == 1)
            return $quantity->fields['quantity'];
    }
    // get products_quantity directly from products table
    $get_quantity_query = 'SELECT products_quantity FROM ' . TABLE_PRODUCTS . ' where products_id="' . $products_id . '" LIMIT 1';    
    $quantity = $db->Execute($get_quantity_query);
    if($quantity->RecordCount() == 1)
        return $quantity->fields['products_quantity'];
    else
        return 0;
}
?>
5 Feb 2008, 7:43 PM
#365
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Happy to find this module, but as a TOTAL NEWBIE :shocking: :blush: I am confused by the installation instructions.

  1. I see no folders to rename to my template??

  2. Your wiki instructions say to drop the admin and includes directories into the root directory of your site. BUT the files extracted to a directory: CART. Where exactly do we upload and/or overwrite each directory for this plugin? (Will dropping the 'cart' directory distribute itself to where it needs to go on its own? -- I use WS_FTP Pro)

THANK YOU!!

5 Feb 2008, 10:39 PM
#366
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

aly22:

Happy to find this module, but as a TOTAL NEWBIE :shocking: :blush: I am confused by the installation instructions.Both your questions, and your need to go to the Wiki to find installation instructions, point to you having downloaded something other than this add-in. There are other similarly named modules and I suspect you must have one of those.

6 Feb 2008, 1:47 AM
#367
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

kuroi:

Both your questions, and your need to go to the Wiki to find installation instructions, point to you having downloaded something other than this add-in. There are other similarly named modules and I suspect you must have one of those.

Hmmm ... Thanks. That must be the problem. I downloaded "stockAttribute3.0.1.1"
Any chance there's a link to the RIGHT one from this thread?

Meanwhile, I'll go try to find the one I downloaded ... :oops:

EDIT: Here's the file I downloaded: stockattribute_by_danielcor_3.01.1.zip

6 Feb 2008, 1:56 AM
#368
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

NEVERMIND ... I've now downloaded YOUR Stock by Attributes and will see how that goes. (Any clue how to UNinstall the SQL Patch I installed for the wrong one?) Thanks

6 Feb 2008, 2:59 AM
#369
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Yikes!!!!!!

1062 Duplicate entry 'STOCK_SHOW_LOW_IN_CART' for key 2
in:
[INSERT INTO zen_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Show available stock level in cart when less than order', 'STOCK_SHOW_LOW_IN_CART', 'false', 'When customer places more items in cart than are available, show the available amount on the shopping cart page:', '9', '6', NULL, now(), NULL, "zen_cfg_select_option(array('true', 'false')," );]

I really really messed up now :cry: DROPPED the table "products_with_attributes_stock" but now cannot re-create without the error above.

6 Feb 2008, 7:01 AM
#370
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

aly22:

Yikes!!!!!!

1062 Duplicate entry 'STOCK_SHOW_LOW_IN_CART' for key 2
in:
[INSERT INTO zen_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Show available stock level in cart when less than order', 'STOCK_SHOW_LOW_IN_CART', 'false', 'When customer places more items in cart than are available, show the available amount on the shopping cart page:', '9', '6', NULL, now(), NULL, "zen_cfg_select_option(array('true', 'false')," );]

6 Feb 2008, 3:25 PM
#371
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Pefect, thank you so much! I'm installed and all is working well so far :)

28 Mar 2008, 6:30 PM
#372
cache529 avatar

cache529

New Zenner

Join Date:
Mar 2008
Posts:
14
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Kuroi,

I was hoping you can help me with my issue. I'm running ZC 1.3.7 and installed the correct version of Stock by Attribute.

My issue is that when I add a variant for any product...it shows up fine in the product display info page, but when it is "added to cart" it shows as out of stock. I have show stock available set to true....and it will say "Stock Available: 0". Any ideas how I can fix this?

Thanks.

28 Mar 2008, 7:51 PM
#373
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

cache529:

My issue is that when I add a variant for any product...it shows up fine in the product display info page, but when it is "added to cart" it shows as out of stock. I have show stock available set to true....and it will say "Stock Available: 0". Any ideas how I can fix this?
As you've eliminated the possibility of a mismatch between your version of Stock by Attributes and your version of Zen Cart, these types of problems always come down to 1) installation problems (usually files that didn't get properly uploaded) or 2) the presence of files that shouldn't be there (usually renamed versions of the files over-written being kept in their original folders just-in-case, and in practise getting in the way).

28 Mar 2008, 8:17 PM
#374
cache529 avatar

cache529

New Zenner

Join Date:
Mar 2008
Posts:
14
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I checked the includes/classes/order.php file and line 8 says "@version $Id: order.php 0000 2007-09-19 00:00:00Z kuroi $". Also, I don't have any *.bak files in the same folders as my testing site...so that's odd...I'll keep trying. Thanks.

2 Apr 2008, 11:18 AM
#375
melbel avatar

melbel

New Zenner

Join Date:
Jan 2008
Posts:
1
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

hi...I am new to all this zencart stuff and I am sure there is an answer to my question somewhere but I am buggered if I can find it. I have installed the stock by attributes module and it all works fine. I then added the modifications by Grayson and now I have issues. I have some items on my site that are made to order but have attributes namely size and colour. I do not want to set individual stock levels for every possible variable as that would create a very ugly looking page. What I had was radio boxes for people to select the colour and another set of radio boxes for the size. When I added Graysons addon I lost all my boxes so now nothing appears on the page for that item. Is there any way to get thhem back without having to fill in stock for every combo? I hope that makes sense?
Any help appreciated!
cheers
Melanie

6 Apr 2008, 1:15 PM
#376
lampivimpa avatar

lampivimpa

New Zenner

Join Date:
Mar 2008
Location:
Finland
Posts:
15
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Can I eliminate this type of problem:
If I change forexamble price for one product with several atributes (11 sizes with 4 prices) and copy new properties to another product with same atributes PWA_VARIANTS are missing.
Only ":" is shown. In product data total stock is shown but shopping cart shows that product is sold out.
If I want, how can I remove "Stock by Attributes v4.7" from ZenCart?

6 Apr 2008, 1:24 PM
#377
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

@melbel

I've never implemented the "Grayson solution", but seem to remember that it was designed for situations where there was only one attribute.

@Lampivimpa

Copying of attributes to another product is done by core code which knows nothing about stock by attributes which is an add-on. Whether this will change in Zen Cart 1.4 when stock by attributes is absorbed into core code, I don't know. It's possible that the developers may take the view that a desire to manage stock at the attribute level doesn't automatically imply the same desire for the new product.

The mod can be uninstalled at several different levels. This is explained here.

7 Apr 2008, 1:00 AM
#378
2pt avatar

2pt

New Zenner

Join Date:
Mar 2008
Location:
British Columbia
Posts:
7
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Hi
I hope you can help me. I'm having a hard time getting stock by attributes to run.
I'm using zen cart 1.3.8 and I'm trying to install v4.7.
I think I've created the sql patch because when I try to do it now I get a duplication error (1062, like the one in previous posts).
I've transferred the files to my home directory, I think that's my root directory. When I was uploading them I had to override a bunch of files, so I thought I finally had it, but no.
I've read the readme instructions and the detailed instructions on this thread in post #113.
I just can't seem to get it working. Any ideas?
Thanks

7 Apr 2008, 1:43 AM
#379
adoy avatar

adoy

New Zenner

Join Date:
Feb 2008
Posts:
45
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

@kuroi

i really appreciate this mod and currently using it on my site. is there any conflict on it with mod dual pricing / wholesale pricing?

a thread on the prob i encountered is found here: http://www.zen-cart.com/forum/showthread.php?t=35450&page=20&highlight=dual+pricing

thankz!

8 Apr 2008, 12:11 AM
#380
xrobvx818 avatar

xrobvx818

New Zenner

Join Date:
Mar 2008
Posts:
17
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

kuroi:

As you've eliminated the possibility of a mismatch between your version of Stock by Attributes and your version of Zen Cart, these types of problems always come down to 1) installation problems (usually files that didn't get properly uploaded) or 2) the presence of files that shouldn't be there (usually renamed versions of the files over-written being kept in their original folders just-in-case, and in practise getting in the way).

I'm having a the same problem where my admin settings are set to "false" for allow checkout. but customers are able to checkout. at the shopping cart customers are correctly informed about how many items are in stock for the item with the specific attribute, if they try to order more than available, but they can still checkout.

I really doubt i have any backup files, but where would they be and what files are typically backed up?

I have reinstalled all the files using filezilla, 1st I originally used windows explorer. So that shouldn't be the issue.

I'm using a custom template, and the paypal module.