Contributions
Product Attributes - Option Type Feature
The purpose of this contribution is to allow the use of various option types when setting up product attributes. With the current CVS version of osCommerce, all options are displayed with select lists for user input. This contribution specifically adds the ability to display options with text input boxes. This allows a store owner to collect customization/personalization information for a product from the end user. The contribution is written in such a way that the addition of other option types such as Radio Buttons should be reasonably simple to add.
Expand All / Collapse All
No file contribution here... Just a note, that if downloading this module or the various "fixes", note that if you add a product with a text option to your cart, and subsequently add the same product with different text entered for the option, it will overwrite the first (as opposed creating a wholly new product, which is the expected behavior)
Lors du rappel d'un article depuis le panier, la valeur des TEXTAREA ne s'affiche pas.
Textarea zeigt den Wert nicht / Textarea doesn't show the value wenn ein Artikel vom shopping cart aufgerufen wird.
Recalling an article from the shopping cart, the TEXTAREA value is not shown.
Bei der Produkt-Info wird der Wert der Textarea nicht angezeigt, da ein kleiner Fehler im Code ist..
------
If the Textarea doesn't show you the right value (Product Info), try this simple replacement
The following code restores the text attribute values when a user
has added items to the cart before logging in. Without the fix,
all text values were lost in the restore_contents logic.
Files to modify
/catalog/includes/classes/shopping_cart.php
FIND:
// OTF contrib begins
//$attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . $customer_id . "' and products_id = '" . $products['products_id'] . "'");
$attributes_query_raw = "select products_options_id, " .
"products_options_value_id, products_options_value_text from " .
TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" .
(int)$customer_id . "' and products_id = '" .
tep_db_input($products['products_id']) . "'";
$attributes_query = tep_db_query($attributes_query_raw);
// OTF contrib ends
// OTF contrib begins
if ($attributes['products_options_value_id'] == PRODUCTS_OPTIONS_VALUE_TEXT_ID) {
$this->contents[$products['products_id']]['attributes_values'][$attributes['products_options_id']] = $attributes['products_options_value_text'];
}
// OTF contrib ends }
REPLACE with
//LPM fix to restore text attribute values to cart object
$attributes_query = tep_db_query("select products_options_id, products_options_value_id, products_options_value_text from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
while ($attributes = tep_db_fetch_array($attributes_query))
{
$this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
if ($attributes['products_options_value_id'] == PRODUCTS_OPTIONS_VALUE_TEXT_ID)
{
$this->contents[$products['products_id']]['attributes_values'][$attributes['products_options_id']] = $attributes['products_options_value_text'];
}
}
//LPM
Attributes disappearing when quantity is updated in shopping cart.
I just tried to fix my shoping cart by using this contribution ..
And it works with the all option ecept the text field.
After that i use this code and it works in all case.
File
catalog/includes/classes/shopping_cart.php
Just replace this function
function update_quantity($products_id, $quantity = '', $attributes = '')
{
----
---
}
with this new
function update_quantity($products_id, $quantity = '', $attributes = '') {
global $customer_id;
if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..
$this->contents[$products_id]['qty'] = $quantity;
// update database
if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
if (is_array($attributes)) {
reset($attributes);
while (list($option, $value) = each($attributes)) {
// BOM - Options Catagories
$attr_value = NULL;
if ( !is_array($value) ) {
$this->contents[$products_id]['attributes'][$option] = $value;
$attr_value = $value;
if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
} elseif ( isset($attributes[$option]['t']) && !empty($attributes[$option]['t']) ) {
$this->contents[$products_id]['attributes'][$option] = $value;
$attr_value = htmlspecialchars(stripslashes($attributes[$option]['t']), ENT_QUOTES);
if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
} elseif ( isset($attributes[$option]['c']) ) {
$this->contents[$products_id]['attributes'][$option] = $value;
foreach ($value as $v) {
$attr_value = $v;
if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
}
}
// EOM - Options Catagories
}
}
}
Pls mail me in both case if this come useful to u or not
Thanks
kishore
just to tell that this solution work in my osC_rc2a
By - Dhananjaya 13 Jan 2008
Attributes disappearing when quantity is updated in shopping cart.
Thanks to Bob O for solving the problem of attributes disappearing when quantity is updated in shopping cart. See…
http://forums.oscommerce.com/index.php?s=&showtopic=57259&view=findpost&p=1158833
The following instruction in Product Attributes - Option Type Feature (OTF) v. 2.02
Manual Installation breaks the store. Uncomment that line to fix it.
Open catalog/shopping_cart.php
----------------------
FIND: (around line 81)
echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
REPLACE with (comment out)
// BOF Product Attributes - Option Type Feature (contribution 160)
//echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
// EOF Product Attributes - Option Type Feature (contribution 160)
note: file is empty
- Modified to work with OsCommerce 2.2 Milestone 2 RC2a
- Adjusted some variables and lines
- Fixed some codes to work properly
- However, there is still a bug with original files which I'm unable to solve until now.
(BUG: It's when you add a product in cart and press "UPDATE", the text of custom TEXT/TEXTARAE field disappears. Anyone to fix that?)
these fixes will make it possible so that the attributes will retain values if present in the URL.
Mainly for when you link from the shopping_cart.php back to the product_info.php, values are passed.
These fixes make sure they are displayed correctly.
Based on v2.02 add fixes for text amd textarea option types. Better handling with the 'values' fields and some minor layout issue's on admin side.
Notice i do not expect this version to be flawless but at least it saves you a few days of analysing raw sql errors. As next step it would be nice to replace the included source files with ms2.2rc2 versions, anyone?
Recent editions of OTF don't include a line in includes/classes/shopping_cart.php that was present in earlier versions of OTF. The absence of this line makes it impossible for customers to delete items from their cart if one of the OTF text fields is populated by a value that includes either an apostrophe or quote marks. I haven't checked all versions, but I know this fix applies to 2.02, 2.01, and several of the manual installs.
Attributes disappearing when quantity is updated in shopping cart.
Thanks to Bob O for solving the problem of attributes disappearing when quantity is updated in shopping cart. See…
http://forums.oscommerce.com/index.php?s=&showtopic=57259&view=findpost&p=1158833
The following instruction in Product Attributes - Option Type Feature (OTF) v. 2.02
Manual Installation breaks the store. Uncomment that line to fix it.
Open catalog/shopping_cart.php
----------------------
FIND: (around line 81)
echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
REPLACE with (comment out)
// BOF Product Attributes - Option Type Feature (contribution 160)
//echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
// EOF Product Attributes - Option Type Feature (contribution 160)
Advanced search with products attributes...
This is another powerfull package for "Products Attributes" (One sreen shot included).
-install:
Just change your old files with new files
(catalog/advanced_search.php and catalog/advanced_search_result.php ).
product_attributes_option_type_2.02 by faaliyet ( Complete Package ) ( With Another "Product Attribute" Powerfull Packages )
--In this package one missing sql query( insert_text_option_value.sql ) added and two bugs fixed.
--Updates_and_fixes_by_faaliyet.txt and option_type_feature-v2.0.2_manual_installation.txt files has been attached.
###############################################
##This is the last fullpackage with all fixes##
###############################################
--Added in zip there is a folder(if you want to work with clone attribute (just replace your file(admin/products_attributes.php)) ) for -->
-->"clone to product attributes" with "product attributes option type".-
-Added in zip there is a folder(if you want to work with -Dynamic_force_attribute_selection-) for -->
-->"dynamic force attribute selection".-
Screen shots included(from product_info.php , shopping_cart.php , checkout_confirmation.php , admin/products_attributes.php pages).
That's all. Enjoy.
Files packaged for overwriting fresh MS2.2 install with SQL file.
Also includes jsruok's Manual Installation instructions
Fixed typos, added comments.
(This file combines "Show attribute name properly 1.1" by me and "Update to Manual Installation" by PD_Steve, and adds one more thing in checkout_process.php to properly store the attributes in the database.
Code includes comments marking beginning and end of each update, and maintains the original code (commented out).)
small fix so if product is clicked in cart the textarea will retain values from url.
still trying to fix radio buttons and checkboxes.
textbox and drop-downs already work.
PS. Thanks to Pawel Suwinski for vanishing attributes on update fix!!
And ones more, diff file did not include full paths to files (order.php -> includes/classes/order.php). Caused by fancy svn diff output :|. Sorry.
ps. There should be some way to delete own garbage posts in contributions :|. Is there any?
Hello
I realized that previous contribution was not complete. It did not include order part. This is final version. If someone find any issue please let me know.
Someone ask me how to use the attachment. So, it is unified diff format from my svn repository. If patching does not work for you (`cd Osc_dir; patch -p0 < /path/to/file.diff` - try it with your test osC instance!) you may do it manual. It is not hard, especially that contribution is rather short:
http://en.wikipedia.org/wiki/Diff#Unified_format
--
regars
Pawel Suwinski
Hello
I am setting osC for printing house, and I needed some way to recalculate price depends on more than one text value (number of copies and number of pages). PA-OTF was good starting point. There were just need to add simply modification. Patch is in attachment.
It works that way, that quantity is multiply by every input text value which product attribute has prefix set to '*' .
--
regards
Pawel Suwinski
Hello
After patching osC 2.2 with last PA-OTF I have noticed that quantity update in shopping_cart.php is broken. After updating all attributes vanished (?). I found in application_top.php some issue in /case 'update_product'/ part. $attributes doesn't use that fancy '+++N' and it should be:
(near 360 line)
$attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i].'+++'.$i]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i].'+++'.$i] : '';
AfterER
Hello
After patching my osC with last OTF I have noticed that quantity update in shopping_cart.php doesn't work properly (?). After quantity updating whole attributes vanished (text one and any others).
Looking through source code I find some issue in application_top.php in the /case 'update_product' / part.
$attributes didn't use that fancy '+++N' and it should be:
$attributes =($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i].'+++'.$i]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i].'+++'.$i] : '';
After that it works fine. But I didn't fix case of PHP_VERSION<4. If I have some time, I will look into and send some. Unless some one will be faster than me :).
If I am wrong with this issue, please correct me. I am supprised that only I have noticed that. Maybe I did some bug somewhere else and that why it doesn't work for me (?).
--
regards
Pawel Suwinski
This file combines "Show attribute name properly 1.1" by me and "Update to Manual Installation" by PD_Steve, and adds one more thing in checkout_process.php to properly store the attributes in the database.
Also, the updated code now includes comments marking beginning and end of each update, and maintains the original code (commented out).
Sql should be without any reference to customers_basket_attributes table.
Manual installation has instructions to update attribute value ($attr_value) in shopping_cart.php and includes/classes/order.php. This works just fine, but in some cases attribute *name* does not come out right. Just add the following code (in both files) after the first $attr_value assignment to show name.
$attr_name_sql_raw = 'SELECT po.products_options_name FROM ' .
TABLE_PRODUCTS_OPTIONS . ' po, ' .
TABLE_CUSTOMERS_BASKET_ATTRIBUTES . ' cba, ' .
TABLE_PRODUCTS_ATTRIBUTES . ' pa WHERE ' .
' pa.products_id="' . $products[$i]['id'] . '" AND ' .
' pa.products_id="' . $products[$i]['id'] . '" AND ' .
' pa.options_id="' . $option . '" AND ' .
' pa.options_id=po.products_options_id AND ' .
' po.language_id="' . $languages_id . '" AND ' .
' cba.products_id="' . $products[$i]['id'] . '" AND ' .
' cba.products_options_value_id="' . $value . '"';
$attr_name_sql = tep_db_query($attr_name_sql_raw);
if ($arr = tep_db_fetch_array($attr_name_sql)) {
$attr_name = $arr['products_options_name'];
}
Also remember to set default value for $attr_name in the else clause, say,
$attr_name = $attributes_values['products_options_name'];
in shopping_cart.php, and
$attr_name = $attributes['products_options_name'];
in includes/classes/order.php.
Then, in shopping_cart.php, replace
'option' => $$attributes_values['products_options_name'],
with
//'option' => $$attributes_values['products_options_name'],
'option' => $attr_name,
and in includes/classes/order.php, replace
'option' => $$attributes['products_options_name'],
with
//'option' => $$attributes['products_options_name'],
'option' => $attr_name,
That should fix the name issue.
I was having trouble getting text entries to write to the database when using the paypal ipn module but after 3 hours I figured it out.
in catalog\includes\modules\payment paypal_ipn.php
changle line 254
which looks like this:
'products_options_values' => $attributes_values['products_options_values_name'],
to this:
'products_options_values' => $order->products[$i]['attributes'][$j]['value'],
Many thanks to Zaxxon for identifying a missing addition. This has now been included in the install text.
The missing section was in includes/functions/general.php
You need to add the following function before the final ?>
// Decode string encoded with htmlspecialchars()
function tep_decode_specialchars($string){
$string=str_replace('>', '>', $string);
$string=str_replace('<', '<', $string);
$string=str_replace(''', "'", $string);
$string=str_replace('"', """, $string);
$string=str_replace('&', '&', $string);
return $string;
}
Manual Installation notes now include this addendum. Please let me know if any other problems are found while doing this install and I'll be only to happy to assist.
Steve
For anyone using a modified version of OsCommerce, I have created a text file which shows all the changes you need to make to each file to get this installed.
This is fully tested as I used these instructions to install the package myself
This is not a full package
Added lines 39 and 40 on catalog/admin/product_attributes.php
which make it so you no longer have to update the products_options_values_to_products_options table manually.
Each time a new textbox, checkbox or textarea option is added, a 'TEXT' entry is put into that database.
Also, the link to the support forum is:
http://forums.oscommerce.com/index.php?showtopic=57259
Changelog :
- fixed product_info.php page line 27 : dropped opening html comment tag that has no closing tag (oeps..shame on me :-( )
- fixed /admin/products_attributes.php (added lines 418 and 419) : when creating a new option, you can enter immediately the type and length. Thanks to Scott Moore for this bug report.
Version v1.6 has been updated to include textarea option type fields so that text is not limited anymore to 32 characters. This new feature has been requested *a lot* on the support thread.
This is the changelog for v1.7 :
- Updated file "ReadMe.html" to include correct information on new textarea type option (read Step 4)
- /includes/configure.php : added new value 'PRODUCTS_OPTIONS_TYPE_TEXTAREA (4)'.
- changed column datatype of customers_basket_attributes.products_options_value_text from varchar(32) to "text".
- added admin support of fields products_options_length and products_options_comment (no need anymore to update the database manually).
- added javascript "Form Field Progress bar" to indicate how many characters are left for the customer to type. The size is determined by the 'products_options_length' field. THanks to Dynamic Drive for this script (http://www.dynamicdrive.com).
- added stylesheet.css in package : needed for javascript Form Field Progress bar (new style '.progress')
- includes price tax fix of 26.07.2004 by Patrick_S
- includes dutch language file for admin/producs_attributes.php (thanks to Stef Verlint)
This is my thirst contribution for oscommerce.
*********************************
Dutch products_attributes.php for 1.6 release
*********************************
This is the translated products_attributes.php for the adminincludeslanguagesdutchproducts_attributes.php
Just copy directory structure to your catalog folder.
All credits go to: Chandra Roukema for making this great contribution.
All I did was the translation.
Enjoy it and let me know what you think of it.
Stef Verlint
verli159@planet.nl
Änderungen in der product_info.php damit der Preis der neuen Produkt_Attribute
inkl. Steuern angezeigt werden:
vorher:
$product_info_values['products_tax_class_id'])
jetzt:
tep_get_tax_rate($product_info['products_tax_class_id']))
.................................................................................
Changes in "product_info.php" to Display the Price of the new Product_Attrib with current Tax:
old:
$product_info_values['products_tax_class_id'])
new:
tep_get_tax_rate($product_info['products_tax_class_id']))
........................................................
MfG Patrick_S
I think there is a small section of code that is repeated and does not get called because the array is not reset.
v1.6 includes a ReadMe.html updated to explain how to use radio buttons and checkboxes with the contribution.
This page includes a link to a demo store using the contribution http://www.OpenStoreSolutions.com/option_type_contribution.php
v1.5 upgrades the feature to the osc 2.2 ms2 code base. v1.5 also includes support for radio buttons and checkboxes in addition to text options.
v1.4 upgrades the feature to the osc 2.2 ms1 code base. v1.4 also includes for the first time an interface for setting the option type of an option. See the Release Notes and Read Me file for more information.
V1.3 upgrades the option type feature to the January 7th, 2003 snapshot of osCommerce. It also fixes a couple of bugs.
V1.2 upgrades the option type feature to the October 20th, 2002 snapshot of osCommerce.
Here is the description of the original contribution:
The purpose of this contribution is to allow the use of various option types
when setting up product attributes. With the current CVS version of
osCommerce, all options are displayed with select lists for user input. This
contribution specifically adds the ability to display options with text input
boxes. This allows a store owner to collect customization/personalization
information for a product from the end user. The contribution is written in
such a way that the addition of other option types such as Radio Buttons should
be reasonably simple to add.
V1.1 fixes several bugs (most notable is the text option display in the confirmation email) and adds a few new features like the ability to set a max length for text options and the ability to add comments to options.
Here is the description of the original contribution:
The purpose of this contribution is to allow the use of various option types when setting up product attributes. With the current CVS version of osCommerce, all options are displayed with select lists for user input. This contribution specifically adds the ability to display options with text input boxes. This allows a store owner to collect customization/personalization information for a product from the end user. The contribution is written in such a way that the addition of other option types such as Radio Buttonsshould be reasonably simple to add.
The purpose of this contribution is to allow the use of various option types when setting up product attributes. With the current CVS version of osCommerce, all options are displayed with select lists for user input. This contribution specifically adds the ability to display options with text input boxes. This allows a store owner to collect customization/personalization information for a product from the end user. The contribution is written in such a way that the addition of other option types such as Radio Buttons should be reasonably simple to add.
Note: Contributions are used at own risk.