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 181 to 200 of 273
This thread is locked. New replies are disabled.
24 Feb 2006, 9:36 PM
#181
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Stock For Product With Different Attributes (OLD)

Couple of small mods you might be interesed in:

First... this 2-liner will pre-fill the quantity box when you are editing a stock level. This seems logical to me so that you have a visual reminder of what stock is currently entered.

in /admin/includes/products_with_attributes_stock.php, Find (Line 349 of a fresh copy)

echo '<p><strong>Quantity: </strong>'.zen_draw_input_field('quantity').'</p>'."\n";

And replace with```
echo '<p><strong>Quantity: </strong>'.zen_draw_input_field('quantity', $_GET['q']).'</p>'."\n"; //s_mack:prefill_quantity


And find (Line 458 of a fresh copy)

echo '<a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=edit&products_id=".$products->fields['products_id'].'&attributes='.$attribute_products->fields['stock_attributes'], 'NONSSL').'">Edit Quantity</a>';
And replace with
echo '<a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=edit&products_id=".$products->fields['products_id'].'&attributes='.$attribute_products->fields['stock_attributes'].'&q='.$attribute_products->fields['quantity'], 'NONSSL').'">Edit Quantity</a>'; //s_mack:prefill_quantity


The second mod is a little more involved. This skips the confirmation step for add and edit. It bugged me when I was trying to change the quantity on several items - its kinda useless anyway. The changes are to the same file as the above mod... its too sporatic to show the changes individually, so here is the file in its entirety - look for lines that end with "s_mack:noconfirm".

<?php // // +----------------------------------------------------------------------+ // |zen-cart Open Source E-commerce | // +----------------------------------------------------------------------+ // | Copyright (c) 2003 The zen-cart developers | // | | // | http://www.zen-cart.com/index.php | // | | // | Portions Copyright (c) 2003 osCommerce | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the GPL license, | // | that is bundled with this package in the file LICENSE, and is | // | available through the world-wide-web at the following url: | // | http://www.zen-cart.com/license/2_0.txt. | // | If you did not receive a copy of the zen-cart license and are unable | // | to obtain it through the world-wide-web, please send a note to | // | [email][email protected][/email] so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // $Id: orders.php 528 2004-11-10 15:56:02Z wilt $ // /* CREATE TABLE `zen_products_with_attributes_stock` ( `stock_id` INT NOT NULL AUTO_INCREMENT , `products_id` INT NOT NULL , `stock_attributes` VARCHAR( 255 ) NOT NULL , `quantity` INT NOT NULL , PRIMARY KEY ( `stock_id` ) ) */ require('includes/application_top.php'); require(DIR_WS_CLASSES . 'currencies.php'); require(DIR_WS_CLASSES . 'products_with_attributes_stock.php'); $stock = new products_with_attributes_stock; if(isset($_SESSION['language_id'])){ $language_id = $_SESSION['language_id'];} else { $language_id=1;} if(isset($_GET['action'])) { $action = $_GET['action']; } else { $action = ''; } switch($action) { case 'add': if(isset($_GET['products_id']) and is_numeric((int)$_GET['products_id'])) { $products_id = (int)$_GET['products_id']; } if(isset($_POST['products_id']) and is_numeric((int)$_POST['products_id'])) { $products_id = (int)$_POST['products_id']; } if(isset($products_id)) { if(zen_products_id_valid($products_id)) { $product_name = zen_get_products_name($products_id); $product_attributes = $stock->get_products_attributes($products_id); $hidden_form .= zen_draw_hidden_field('products_id',$products_id)."\n"; } else { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } } else { $query = 'SELECT DISTINCT attrib.products_id, description.products_name FROM '.TABLE_PRODUCTS_ATTRIBUTES.' attrib, '.TABLE_PRODUCTS_DESCRIPTION.' description WHERE attrib.products_id = description.products_id and description.language_id='.$language_id.' order by description.products_name'; $products = $db->execute($query); while(!$products->EOF) { $products_array_list[] = array( 'id' => $products->fields['products_id'], 'text' => $products->fields['products_name'] ); $products->MoveNext(); } } break; case 'edit': $hidden_form = ''; if(isset($_GET['products_id']) and is_numeric((int)$_GET['products_id'])) { $products_id = $_GET['products_id']; } if(isset($_GET['attributes'])) { $attributes = $_GET['attributes']; } if(isset($products_id) and isset($attributes)) { $attributes = explode(',',$attributes); foreach($attributes as $attribute_id){ $hidden_form .= zen_draw_hidden_field('attributes[]',$attribute_id)."\n"; $attributes_list[] = $stock->get_attributes_name($attribute_id); } $hidden_form .= zen_draw_hidden_field('products_id',$products_id)."\n"; } else { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } break; case 'confirm': if(isset($_POST['products_id']) and is_numeric((int)$_POST['products_id'])) { if(!isset($_POST['quantity']) || !is_numeric($_POST['quantity'])) { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } $products_id = $_POST['products_id']; $product_name = zen_get_products_name($products_id); if(is_numeric($_POST['quantity'])) { $quantity = $_POST['quantity']; } $attributes = $_POST['attributes']; foreach($attributes as $attribute_id) { $hidden_form .= zen_draw_hidden_field('attributes[]',$attribute_id)."\n"; $attributes_list[] = $stock->get_attributes_name($attribute_id); $s_mack_noconfirm .="attributes[]=" . $attribute_id . "&"; //s_mack:noconfirm } $hidden_form .= zen_draw_hidden_field('products_id',$products_id)."\n"; $hidden_form .= zen_draw_hidden_field('quantity',$quantity)."\n"; $s_mack_noconfirm .="products_id=" . $products_id . "&"; //s_mack:noconfirm $s_mack_noconfirm .="quantity=" . $quantity . "&"; //s_mack:noconfirm if(sizeof($attributes) > 1) { sort($attributes); $stock_attributes = implode(',',$attributes); } else { $stock_attributes = $attributes[0]; } $query = 'select * from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' where products_id = '.$products_id.' and stock_attributes="'.$stock_attributes.'"'; $stock_check = $db->Execute($query); if(!$stock_check->EOF) { $hidden_form .= zen_draw_hidden_field('add_edit','edit'); $hidden_form .= zen_draw_hidden_field('stock_id',$stock_check->fields['stock_id']); $s_mack_noconfirm .="stock_id=" . $stock_check->fields['stock_id'] . "&"; //s_mack:noconfirm $s_mack_noconfirm .="add_edit=edit&"; //s_mack:noconfirm $add_edit = 'edit'; } else { $hidden_form .= zen_draw_hidden_field('add_edit','add')."\n"; $s_mack_noconfirm .="add_edit=add&"; //s_mack:noconfirm } } else { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, $s_mack_noconfirm . "action=execute", 'NONSSL')); //s_mack:noconfirm break; case 'execute': $attributes = $_POST['attributes']; if ($_GET['attributes']) { $attributes = $_GET['attributes']; } //s_mack:noconfirm $products_id = $_POST['products_id']; if ($_GET['products_id']) { $products_id = $_GET['products_id']; } //s_mack:noconfirm /* s_mack:noconfirm if(is_numeric((int)$_POST['quantity'])) { $quantity = (int)$_POST['quantity']; } else */ s_mack:noconfirm $quantity = $_GET['quantity']; //s_mack:noconfirm if ($_GET['quantity']) { $quantity = $_GET['quantity']; } //s_mack:noconfirm if(!is_numeric((int)$quantity)) //s_mack:noconfirm { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } if(sizeof($attributes) > 1) { sort($attributes); $stock_attributes = implode(',',$attributes); } else { $stock_attributes = $attributes[0]; } //if($_POST['add_edit'] == 'add') if(($_POST['add_edit'] == 'add') || ($_GET['add_edit'] == 'add')) //s_mack:noconfirm { $query = 'insert into `'.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.'` (`products_id`,`stock_attributes`,`quantity`) values ('.$products_id.',"'.$stock_attributes.'",'.$quantity.')'; } elseif(($_POST['add_edit'] == 'edit') || ($_GET['add_edit'] == 'edit')) //s_mack:noconfirm //elseif($_POST['add_edit'] == 'edit') { /* s_mack:noconfirm if(is_numeric((int)$_POST['stock_id'])) { $stock_id = (int)$_POST['stock_id']; } else */ s_mack:noconfirm $stock_id = $_POST['stock_id']; //s_mack:noconfirm if ($_GET['stock_id']) { $stock_id = $_GET['stock_id']; } //s_mack:noconfirm if(!is_numeric((int)$stock_id)) //s_mack:noconfirm { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, zen_get_all_get_params(array('action')), 'NONSSL')); } $query = 'update `'.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.'` set quantity='.$quantity.' where stock_id='.$stock_id.' limit 1'; } $db->Execute($query); $stock->update_parent_products_stock($products_id); $messageStack->add_session('Product successfully updated', 'success'); zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, '', 'NONSSL')); break; case 'delete': if(!isset($_POST['confirm'])) { // do nothing } else { // delete it if($_POST['confirm'] == 'Yes'){ $query = 'delete from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' where products_id="'.$_POST['products_id'].'" and stock_attributes="'.$_POST['attributes'].'" limit 1'; $db->Execute($query); $stock->update_parent_products_stock((int)$_POST['products_id']); $messageStack->add_session('Product Variant was deleted', 'failure'); zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, '', 'NONSSL')); } else { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, '', 'NONSSL')); } } break; case 'resync': if(is_numeric((int)$_GET['products_id'])){ $stock->update_parent_products_stock((int)$_GET['products_id']); $messageStack->add_session('Parent Product Quantity Updated', 'success'); zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, '', 'NONSSL')); } else { zen_redirect(zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, '', 'NONSSL')); } break; default: // Show a list of the products break; } ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS"> <script language="javascript" type="text/javascript" src="includes/menu.js"></script> <script language="javascript" type="text/javascript" src="includes/general.js"></script> <script type="text/javascript"> <!-- function init() { cssjsmenu('navbar'); if (document.getElementById) { var kill = document.getElementById('hoverJS'); kill.disabled = true; } } // --> </script> </head> <body onload="init()"> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <div style="padding: 20px;"> <!-- body_text_eof //--> <!-- body_eof //--> <? switch($action) { case 'add': if(isset($products_id)) { echo zen_draw_form('final_refund_exchange', FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'action=confirm', 'post', '', true)."\n"; echo $hidden_form; echo '<p><strong>'.$product_name.'</strong></p>'; foreach($product_attributes as $option_name => $options) { echo '<p><strong>'.$option_name.': </strong>'; echo zen_draw_pull_down_menu('attributes[]',$options).'</p>'."\n"; } echo '<p><strong>Quantity: </strong>'.zen_draw_input_field('quantity').'</p>'."\n"; } else { echo zen_draw_form('final_refund_exchange', FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'action=add', 'post', '', true)."\n"; echo zen_draw_pull_down_menu('products_id',$products_array_list)."\n"; } ?>
<p><input type="submit" value="submit"></p>
</form>
<? break; case 'edit': echo zen_draw_form('final_refund_exchange', FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'action=confirm', 'post', '', true)."\n"; echo '<h3>'.zen_get_products_name($products_id).'</h3>'; foreach($attributes_list as $attributes) { echo '<p><strong>'.$attributes['option'].': </strong>'.$attributes['value'].'</p>'; } echo $hidden_form; echo '<p><strong>Quantity: </strong>'.zen_draw_input_field('quantity').'</p>'."\n"; ?>
<p><input type="submit" value="submit"></p>
</form>
<? break; case 'delete': if(!isset($_POST['confirm'])) { echo zen_draw_form('final_refund_exchange', FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'action=delete', 'post', '', true)."\n"; echo 'Are you sure you want to delete this product?'; foreach($_GET as $key=>$value) { echo zen_draw_hidden_field($key,$value); } ?>
<p><input type="submit" value="Yes" name="confirm"> * <input type="submit" value="No" name="confirm"></p>
</form>
<? } break; case 'confirm': echo '<h3>Confirm '.$product_name.'</h3>'; foreach($attributes_list as $attributes) { echo '<p><strong>'.$attributes['option'].': </strong>'.$attributes['value'].'</p>'; } echo '<p><strong>Quantity</strong>'.$quantity.'</p>'; echo zen_draw_form('final_refund_exchange', FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'action=execute', 'post', '', true)."\n"; echo $hidden_form; ?>
<p><input type="submit" value="submit"></p>
</form>
<? break; default: ?>
<table width="100%" style="text-align: left">
<tr>
<th>Product ID</th> <th>Product Name</th> <th>Quantity of all variants</th> <th>Add Quantity For Product Variant</th> <th>Sync Quantities</th> </tr> <?

// Show a list of the products
$query = 'select distinct
attrib.products_id, description.products_name, products.products_quantity
FROM
'.TABLE_PRODUCTS_ATTRIBUTES.' attrib, '.TABLE_PRODUCTS_DESCRIPTION.' description, '.TABLE_PRODUCTS.' products
WHERE
attrib.products_id = description.products_id and
attrib.products_id = products.products_id and description.language_id='.$language_id.' order by description.products_name ';

$products = $db->Execute($query);

while(!$products->EOF)
{
echo '<tr style="background: #ccc">'."\n";
echo '<td>'.$products->fields['products_id'].'</td>';
echo '<td>'.$products->fields['products_name'].'</td>';
echo '<td>'.$products->fields['products_quantity'].'</td>';
echo '<td><a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=add&products_id=".$products->fields['products_id'], 'NONSSL').'">Add Quantity For Product Variant</a></td>';
echo '<td><a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=resync&products_id=".$products->fields['products_id'], 'NONSSL').'">Sync Quantities</a></td>';
echo '</tr>'."\n";

$query = 'select * from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' where products_id="'.$products->fields['products_id'].'"';

$attribute_products = $db->Execute($query);
if($attribute_products->RecordCount() > 0)
{

echo '<tr>'."\n";
echo '<td colspan="5" style="padding:10px;">'."\n";
echo '<table width="100%" style="text-align: left">';
echo '<tr>';
echo '<th style="border-bottom: 1px solid #ccc">Stock id</th><th style="border-bottom: 1px solid #ccc">Variant</th><th style="border-bottom: 1px solid #ccc">Quantity in stock</th><th style="border-bottom: 1px solid #ccc">Edit</th><th style="border-bottom: 1px solid #ccc">Delete</th>';
echo '</tr>';


while(!$attribute_products->EOF)
{	

echo '<tr>';
echo '<td style="border-bottom: 1px dashed #ccc">'."\n";
echo $attribute_products->fields['stock_id'];
echo '</td>'."\n";
echo '<td style="border-bottom: 1px dashed #ccc">'."\n";

$attributes_of_stock = explode(',',$attribute_products->fields['stock_attributes']);
$attributes_output = array();
foreach($attributes_of_stock as $attri_id)
{
$stock_attribute = $stock->get_attributes_name($attri_id);
$attributes_output[] = '<strong>'.$stock_attribute['option'].':</strong> '.$stock_attribute['value'].'<br/>';
}
sort($attributes_output);
echo implode("\n",$attributes_output);

echo '</td>'."\n";
echo '<td style="border-bottom: 1px dashed #ccc">'."\n";
echo $attribute_products->fields['quantity'];
echo '</td>'."\n";
echo '<td style="border-bottom: 1px dashed #ccc">'."\n";
echo '<a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=edit&products_id=".$products->fields['products_id'].'&attributes='.$attribute_products->fields['stock_attributes'], 'NONSSL').'">Edit Quantity</a>';
echo '</td>'."\n";
echo '<td style="border-bottom: 1px dashed #ccc">'."\n";
echo '<a href="'.zen_href_link(FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK, "action=delete&products_id=".$products->fields['products_id'].'&attributes='.$attribute_products->fields['stock_attributes'], 'NONSSL').'">Delete Variant</a>';
echo '</td>'."\n";
echo '</tr>';

$attribute_products->MoveNext();
}
echo '</table>';
echo '</td>'."\n";
echo '</tr>'."\n";
}

$products->MoveNext();

}
?>
</table>

<? break; } ?> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> <br /> </div> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> ```
  • Steven
25 Feb 2006, 12:40 AM
#182
studmuffin avatar

studmuffin

New Zenner

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

Re: Stock For Product With Different Attributes (OLD)

thanks s_mack

i will try both your suggestions and see how i get on :/

nice on :)

25 Feb 2006, 5:34 AM
#183
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

Geeze... ok, back to the drawing board.

A bit of obvious logic escaped me until now. Grayson... that code change you did to show stock leves for attributes... that won't work with more than one level (say size & color, for example), right? I fought with this all night until I finally realized that it would have to reload data to know now what attribute combination we're looking at. Yeah, yeah.. I know you guys already thought of this and that's where that ajax conversation came from. I skimmed through it and though that you had solved it :) My bad.

Ok, but maybe there is a way. Either with Ajax, or something simpler. I, like others here, don't like the idea of having a customer just take a shot in the dark and not know ahead of time if something is in stock or not so I want to get this resolved.

Ajax may be the way to go... but if we're going to do javascripting anyway maybe there is an alternative. Perhaps we can create a simple (not really scalable) database for the javascript to interact with... if the current selected permutation matches an entry in the database, then we can inform the user there is stock.

Downside (also with Ajax I believe) is that for really busy sites the item could very well be out of stock before the add to cart button is hit since the javascript db isn't dynamically tied to the sql db. That doesn't matter for my purposes.

Other downside (again, also with Ajax) is if JavaScript is disabled in the browser (less of a problem these days) it will not work.

  • Steven
26 Feb 2006, 7:52 AM
#184
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

After playing around with things a bit, I've started to get it how I want it. It uses JavaScript... a language I have avoided for several years now so I'm am very rusty. You can see my work-in-progress implimentation here on my test site.

When the page first loads, and any time you change any of the attributes, it will show you an indication of stock levels. I've put both a text and image example there (the stars images were handy... changes between 0 or three if there is stock or not).

It will work with any number of attributes and any number of options per attribute - however the scalabilty of JS is pretty weak so if you have hundreds or even just dozens of permutations it may be problematic, I don't know.

It can easily be adapted to say "out of stock" instead of "0 in stock" of course... can be anything you want really. I imagine it wouldn't be too hard to dynamically remove elements that aren't in stock, if people found that to be useful.

If people want to work with this, there is some work left to do. 1) Cross-browserify it... I know there are tricks and pitfalls with JS so if someone more familiar with the language wants to have a look that would be great. 2) Some sort of handling in case there is no JS support on the browser (or ignore it and it will just behave like stock... they find out once they get to the checkout). 3) I got lazy and I'm sure I didnt' reference things properly (like hardcoding table names in the SQL queries).

Check it out. If there is interest I'll post some source. If not, I'll just use it for my own purposes without bothering to clean things up for readability.

  • Steven
27 Feb 2006, 7:32 AM
#185
kyle avatar

kyle

New Zenner

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

Re: Stock For Product With Different Attributes (OLD)

got this up and working fine on 1.27, only problem seems to be the link in admin is titled "FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK"....where should i look to fix this up?

27 Feb 2006, 4:23 PM
#186
jettrue avatar

jettrue

Totally Zenned

Join Date:
Jan 2005
Location:
USA, St. Louis
Posts:
3,651
Plugin Contributions:
5

Re: Stock For Product With Different Attributes (OLD)

Kyle,

I'm also trying to install in a 1.2.7 store, but I just get a blank page when I go to the "Products with Attributes stock" page in the admin.

It may be because I've dowloaded an old version of this? It seems that upgrades and or changes that were mentioned in this thread were not applied to the version I downloaded.

It would be really great if the updated mod could be uploaded somewhere, vs. having to dig through the thread and find the changes?

For example, in the readme.txt, the incorrect SQL file is still listed.

Also, s_mack, on a post on the previous page (Feb 24 2006, 03:36 PM) You first list some changes to /admin/includes/products_with_attributes_stock.php (which I'm guess is a type and actually should be /admin/products_with_attributes_stock.php), then you post the entire /admin/products_with_attributes_stock.php file but without the changes you showed right above it. Which changes, if any, should we apply?

I'm not trying to be rude, I understand a lot of these mods and downloads are "as is", and are not guaranteed to work in all cases, but I think with offering mods for distribution, there comes a bit of responsibility to try and offer correct files, at least in my opinion. Or perhaps I'm just missing something obvious, where you listed an updated link?

Utterly confused,

27 Feb 2006, 4:44 PM
#187
jettrue avatar

jettrue

Totally Zenned

Join Date:
Jan 2005
Location:
USA, St. Louis
Posts:
3,651
Plugin Contributions:
5

Re: Stock For Product With Different Attributes (OLD)

I found the problem, the fixes below are for the original file from the download on page 1.

Though I don't see how the original file was working for anyone either? Unless this was an addressed issue somewhere in this thread that I missed. Or perhaps its only happening with my browser (I use Safari)

Anyway, my error log showed an error on line 201 of admin/produccts_with_attributes_stock.php. It said there was an unexpected ':'.

On line 201, I see this:

*/ s_mack:noconfirm

In dreamweaver, that s:mack:noconfirm isn't hidden text, so I chaged it to

s_mack:noconfirm */

so it is hidden. Now I can get to the page. This is also an issue on line 233. Same on the file you posted on the previous page.

27 Feb 2006, 5:58 PM
#188
jettrue avatar

jettrue

Totally Zenned

Join Date:
Jan 2005
Location:
USA, St. Louis
Posts:
3,651
Plugin Contributions:
5

Re: Stock For Product With Different Attributes (OLD)

grayson:

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 . ']'

 I got this working.

Open up includes/modules/pages/product_info/main_template_vars_attributes.php

and around line 122 replace:

$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'],
'text' => $products_options->fields['products_options_values_name']);


with
         

$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'],
'text' => $products_options->fields['products_options_values_name'] .' [' . $products_options->fields['quantity'] . ' '. TEXT_ATTRIBUTES_PIECES . ']');


This is after applying the changes that grayson noted on page 14 of this thread.

See it in action here at a test site:
[http://www.zencart.jadetrue.com/testing-pr...roduct-p-1.html](http://www.zencart.jadetrue.com/testing-product-p-1.html)
27 Feb 2006, 6:35 PM
#190
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

Yes, but try getting that to work if you have more than one attribute!

Which is the beauty of this contrib vs. the other one that's out there because it DOES work with multiple attributes... that modification, unfortunately, does not.

Jettrue - I hear you... it is a pain going through the entire thread. The problem is (as I just pointed out in the previous paragraph) is that not all the mods we are discussing here are compatible with one another or desired by all. I haven't confirmed whether or not I had typos, but changing the comments the way you did seems it would hide entire blocks... not what you want. I'll have a look.

EDIT You are correct. The file reference was a typo (no 'includes' part) and the comments were done poorly as you showed (odd that I didn't get an error though) as I've been working with a different language that comments like that. You seemed to be confused because the first set of mods I wrote weren't included in the 2nd set... that's because they are two seperate mods. That's the thing about mods, as I said above - not all are desired or compatible. In this case, they will work fine together but you might not want both. Who am I to package it up and say its the "right" package? END_EDIT

Everyone - a page or so back I posted what I had done to make dropdowns work WITH multiple attributes and posted a link to my site so you could see it in action... unfortunately, if any of you tested it before now you would have seen a "down for maintenance" (oops). I have corrected that so you can see it in action here. I'm constantly working on it so ignore the layout and crap - just see how it shows you the number of that combination in stock and changes the (meaningless) graphic above it.

27 Feb 2006, 7:26 PM
#191
yahaira avatar

yahaira

New Zenner

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

Re: Stock For Product With Different Attributes (OLD)

thank you jettrue!!! I will definitely send you chocolates if youd like :D Im glad someone got it working, I was leaving out the single quotes I think and therefore getting a blank page. sigh.

27 Feb 2006, 7:37 PM
#192
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

Do you guys only have single-attribute products? Or am I missing something? As far as I can tell, the greyson, et al. mod for showing stock levels (culminating finally in the drop down fix by jettrue) will not work with multiple attributes and, I think, would in fact break your code if you did have multiple attributes.

Eg in case i'm not clear:

Red T-shirts: 5 units (ok)
Large T-shirts: 5 units (ok)

But...

Large, Red t-shirts: ???? (not ok)

  • Steven
27 Feb 2006, 7:43 PM
#193
yahaira avatar

yahaira

New Zenner

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

Re: Stock For Product With Different Attributes (OLD)

I only have single attributes (colors) for my products

27 Feb 2006, 7:44 PM
#194
jettrue avatar

jettrue

Totally Zenned

Join Date:
Jan 2005
Location:
USA, St. Louis
Posts:
3,651
Plugin Contributions:
5

Re: Stock For Product With Different Attributes (OLD)

s_mack:

Do you guys only have single-attribute products? Or am I missing something? As far as I can tell, the greyson, et al. mod for showing stock levels (culminating finally in the drop down fix by jettrue) will not work with multiple attributes and, I think, would in fact break your code if you did have multiple attributes.

Eg in case i'm not clear:

Red T-shirts: 5 units (ok)
Large T-shirts: 5 units (ok)

But...

Large, Red t-shirts: ???? (not ok)

  • Steven
    Correct, it only works with one attribute option, I just tested it.

I'd love to use your new way of handling it, as long as it'll work on all of the newer browsers. It seems to work fine on Safari and Firefox over here. I tested it with Javascript off, and as long as it's still allowing them to add to cart (and if there's not enough instock they get the message in the cart), works for me!

However, even with it limited to 1 attribute is a great improvement over the default zen cart behavior... and I love having the availability listed in the drop down. :-)

27 Feb 2006, 9:27 PM
#196
voltage avatar

voltage

Totally Zenned

Join Date:
Apr 2005
Location:
Houston, TX
Posts:
1,356
Plugin Contributions:
1

Re: Stock For Product With Different Attributes (OLD)

s_mack:

the beauty of this contrib vs. the other one that's out there because it DOES work with multiple attributes... that modification, unfortunately, does not.

.......
see it in action here. I'm constantly working on it so ignore the layout and crap - just see how it shows you the number of that combination in stock and changes the (meaningless) graphic above it.
? he seems to have it working for 2 different types of attributes

27 Feb 2006, 10:08 PM
#197
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

Yes voltage... my way of doing it will work with unlimited attributes (well... i suppose there's a conceptual limit somewhere) using JavaScript.. completely different method than Grayson's way so they can't be used together.

As I have it now, it is NOT documented, ONLY working for drop downs (cause that's all I use) and probably isn't coded correctly for everyone's use (I probably got lazy and hardcoded table references and if you use table prefixes then the code will break).

So if you guys like my implementation and want to use it, I can clean it up and try to make a sensible release out of it but it will take a bit. If you are happy with the single-attribute method, then stick with Grayson's because it is FAR less complicated and doesn't rely on JavaScript support.

As jettrue pointed out... if a browser doesn't have JavaScript it simply won't show you the stock levels or show/change the stock status image. Whether or not it allows you to add it to your cart and/or show you out of stock once in your cart depends on your zen cart config settings.

Worst case scenario: Your cart is set to NOT allow out of stock items be added to the cart AND your visitor doesn't have JavaScript (<1% of browsers) then the page will just reload when they hit "add to cart" with no errors, warnings, explanation, or anything else. That's a flaw with ZC really, not my mod.

  • Steven
2 Mar 2006, 8:10 PM
#198
seizer avatar

seizer

New Zenner

Join Date:
Jun 2005
Posts:
22
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Steven

First of all many props to those who hvve worked so hard on this contrib. ::tup I am going to start working with it tonight.

I'd actually like to get that contrib if you don't mind.
Great looking site by the way.

Thanks

I came here to learn. I left here wiser.

3 Mar 2006, 2:27 AM
#199
seizer avatar

seizer

New Zenner

Join Date:
Jun 2005
Posts:
22
Plugin Contributions:
0

Re: Stock For Product With Different Attributes (OLD)

Great contrib. Got it working on the first try :D
That's a first for this newbie.

Question: Is it possible to use this so that even if you have mroe than one attrib for a product yuou can select which attribs to include in the stock level?

ie I wouldlike to be able to select one attrib out of four that I have to track the stock level. I have attribs that don't necessarily belong to the item but are general to all products.

Our customers can choose to have an item gift wrapped or gift boxed at an additional cost, choose a bow color and insert a free gift message These are available to all products, sizes etc.

The problem I am having is that when I try and create a stock quantity for a size let's say it takes into account the gift box attrib as well as the bow color, gift message...you get the picture.

Does anyone know of a way to maybe create an on/off switch for each of the attribs so you can include or exclude it? I can give it a try (although php is new to me :blink: ) if someone can point me in the right direction.

I came here to learn. I left here wiser.

3 Mar 2006, 2:45 AM
#200
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Stock For Product With Different Attributes (OLD)

That's a good point seizer... I hadn't thought of that, but I can see how a lot of carts might work like that... have attributes that really don't affect stock at all.

I don't think it would be too terribly difficult. I'd add a column to the products_attributes table (eg. products_attributes_checkstock) and make it binary, then edit the PWAS (this) mod with a simple if (products_attributes_checkstock == true) condition. I think that would work.

  • Steven