Re: Editing cart contents -- esp products with attributes
Hi Justin
Hope you don't mind, but I thought it might be helpful if I jumped in and provided some additional information about the long product ID (aka prid).
You are correct that this is added for attributes. Its primary purpose is to allow the shopping cart to differentiate between variants of the same product that differ only due to the attributes selected. So, for example, the shopping cart will merge products with the same prid, but know to keep the separate products with different prids.
The prid is generated by applying MD5 encryption to the attribute information. There's no particular benefit to the data being encrypted - the real benefit is that MD5 is pretty well guaranteed to produce a unique result for each combination of attributes and therefore there is virtually zero risk of accidentally merging different product variants.
However, MD5 is a one-way encryption technique, so the attribute information cannot be extracted from it. Instead it is passed from the product info page in a $_POST array and is picked up by the shopping cart which then holds the information in a php session array indexed by the prid and from which it can be referenced when needed.
Hope this helps.
Re: Editing cart contents -- esp products with attributes
OK that is good information Kuroi, thanks. I wish all of Zen Cart was documented so well.
I figured it was an attributes hash but never bothered to follow the program logic right through. (In fact I don't know why, if this logic is in place, the "edit cart" functionality is not standard.)
In any case, there is a products_id GET parameter that we can use to establish if an item in the cart has attributes selected or not. Because if an item has attributes, the value of the products_id parameter will include an md5 hash as Kuroi described.
For anyone reading who isn't following this, a GET parameter will appear after the main part of the URL, ie the part after index.php, and looks a bit like this param1=a¶m2=b etc
A POST parameter is invisible. You cannot see it in the URL.
I do not know if this is Shockers problem, but it may be, because he is using SEO optimized URLs which do not have any GET parameters on them. It may be that the products_id parameter is not being seen by the Edit Cart mod, and so it is not working properly. The Edit Cart mod, doesn't do much with this information it just directs the form to a special shopping cart action. This all occurs in this section:
Code:
if(is_numeric($_GET['products_id'])) {
$cartAction="add_product";
}else{
$cartAction = "edit_product_in_cart";
}
Later on we add a hidden field, edit_item_id, too
Code:
//make the edit button
$the_button = '<input type="hidden" name="cart_quantity" value="' . $existing_quantity . '" />' .
zen_draw_hidden_field('products_id', (int)$_GET['products_id']) .
zen_draw_hidden_field('edit_item_id', $_GET['products_id']) .
zen_image_submit(BUTTON_IMAGE_EDIT_CART_CONTENTS, BUTTON_IMAGE_EDIT_CART_CONTENTS_ALT);
Shocker if you have added an SEO module recently, my bet is that this is causing the problem. Can you advise?
Re: Editing cart contents -- esp products with attributes
Quote:
Originally Posted by
justinhunt
Shocker if you have added an SEO module recently, my bet is that this is causing the problem. Can you advise?
I do have an Ultimate SEO Urls 2.106 mod installed, but this was installed on 1/28/08
I installed Edit Cart 1.1. on 2/29/08.
I had tested this successfully with flying colors.
other mods I've installed AFTER Edit Cart:
Tabbed Products Pro 1.02
Image Handler 2
RSS Feed 2.1.3
Linkpoint API
Thanks for any help.
Re: Editing cart contents -- esp products with attributes
I don't know which, if any, of those mods has broken EditCart. If SEO urls was working fine before, it should be working fine now too though.
In your first post you said that the button was not showing, but it seems to be showing now. What did you do to get the button back? When did you last verify the edit cart was working as it should?
The fact that product edits are clearing the cart looks very much like the bug that was fixed on 24th of Feb. What does the extra_cart_actions/edit_cart_item.php file look like? If it is only 10 or so lines, then it is the old version.
I am working in the dark a bit here.
Re: Editing cart contents -- esp products with attributes
Quote:
Originally Posted by
justinhunt
I don't know which, if any, of those mods has broken EditCart. If SEO urls was working fine before, it should be working fine now too though.
In your first post you said that the button was not showing, but it seems to be showing now. What did you do to get the button back? When did you last verify the edit cart was working as it should?
The fact that product edits are clearing the cart looks very much like the bug that was fixed on 24th of Feb. What does the extra_cart_actions/edit_cart_item.php file look like? If it is only 10 or so lines, then it is the old version.
I am working in the dark a bit here.
I have to revisit this because I noticed too that the button was showing up, but I don't know in what circumstances that it doesn't. I'll get back to you on this.
This is the edit_cart_item.php
Code:
<?php
/**
* Edit_Cart
*
* Edit an existing product by removing it before it hits the add to cart action
* Author: Justin Hunt http://www.kuroobiya.com 20071120
* Version: 1.1
*/
// intercept add_product actions and if the edit_item_id paramater is set,
//If set, remove that item from cart, and proceed to add it again
if (($_GET['action'] == 'edit_product_in_cart')) {
// $_SESSION['cart']->actionAddProduct($goto, $parameters);
global $messageStack, $db;
if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
// verify attributes and quantity first
$the_list = '';
$adjust_max= 'false';
if (isset($_POST['id'])) {
foreach ($_POST['id'] as $key => $value) {
$check = zen_get_attributes_valid($_POST['products_id'], $key, $value);
if ($check == false) {
$the_list .= TEXT_ERROR_OPTION_FOR . '<span class="alertBlack">' . zen_options_name($key) . '</span>' . TEXT_INVALID_SELECTION . '<span class="alertBlack">' . (zen_values_name($value) == 'TEXT' ? TEXT_INVALID_USER_INPUT : zen_values_name($value)) . '</span>' . '<br />';
}
}
}
// verify qty to add
// $real_ids = $_POST['id'];
//die('I see Add to Cart: ' . $_POST['products_id'] . 'real id ' . zen_get_uprid($_POST['products_id'], $real_ids) . ' add qty: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty);
$add_max = zen_get_products_quantity_order_max($_POST['products_id']);
$cart_qty = $_SESSION['cart']->in_cart_mixed($_POST['products_id']);
$new_qty = $_POST['cart_quantity'];
//here we adjust the existing cart quantity because we are going to remove existig items shortly
$cart_qty= $cart_qty-$new_qty;
//echo 'I SEE actionAddProduct: ' . $_POST['products_id'] . '<br>';
$new_qty = $_SESSION['cart']->adjust_quantity($new_qty, $_POST['products_id'], 'shopping_cart');
if (($add_max == 1 and $cart_qty == 1)) {
// do not add
$new_qty = 0;
$adjust_max= 'true';
} else {
// adjust quantity if needed
if (($new_qty + $cart_qty > $add_max) and $add_max != 0) {
$adjust_max= 'true';
$new_qty = $add_max - $cart_qty;
}
}
if ((zen_get_products_quantity_order_max($_POST['products_id']) == 1 and $_SESSION['cart']->in_cart_mixed($_POST['products_id']) == 1)) {
// do not add
} else {
// process normally
// bof: set error message
if ($the_list != '') {
$messageStack->add('product_info', ERROR_CORRECTIONS_HEADING . $the_list, 'caution');
// $messageStack->add('header', 'REMOVE ME IN SHOPPING CART CLASS BEFORE RELEASE<br/><BR />' . ERROR_CORRECTIONS_HEADING . $the_list, 'error');
} else {
// process normally
// iii 030813 added: File uploading: save uploaded files with unique file names
$real_ids = isset($_POST['id']) ? $_POST['id'] : "";
if (isset($_GET['number_of_uploads']) && $_GET['number_of_uploads'] > 0) {
/**
* Need the upload class for attribute type that allows user uploads.
*
*/
include(DIR_WS_CLASSES . 'upload.php');
for ($i = 1, $n = $_GET['number_of_uploads']; $i <= $n; $i++) {
if (zen_not_null($_FILES['id']['tmp_name'][TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]]) and ($_FILES['id']['tmp_name'][TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] != 'none')) {
$products_options_file = new upload('id');
$products_options_file->set_destination(DIR_FS_UPLOADS);
$products_options_file->set_output_messages('session');
if ($products_options_file->parse(TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i])) {
$products_image_extension = substr($products_options_file->filename, strrpos($products_options_file->filename, '.'));
if ($_SESSION['customer_id']) {
$db->Execute("insert into " . TABLE_FILES_UPLOADED . " (sesskey, customers_id, files_uploaded_name) values('" . zen_session_id() . "', '" . $_SESSION['customer_id'] . "', '" . zen_db_input($products_options_file->filename) . "')");
} else {
$db->Execute("insert into " . TABLE_FILES_UPLOADED . " (sesskey, files_uploaded_name) values('" . zen_session_id() . "', '" . zen_db_input($products_options_file->filename) . "')");
}
$insert_id = $db->Insert_ID();
$real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] = $insert_id . ". " . $products_options_file->filename;
$products_options_file->set_filename("$insert_id" . $products_image_extension);
if (!($products_options_file->save())) {
break;
}
} else {
break;
}
} else { // No file uploaded -- use previous value
$real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] = $_POST[TEXT_PREFIX . UPLOAD_PREFIX . $i];
}
}
}
$_SESSION['cart']->add_cart($_POST['products_id'], $_SESSION['cart']->get_quantity(zen_get_uprid($_POST['products_id'], $real_ids))+($new_qty), $real_ids);
// iii 030813 end of changes.
} // eof: set error message
} // eof: quantity maximum = 1
if ($adjust_max == 'true') {
$messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . ' B: - ' . zen_get_products_name($_POST['products_id']), 'caution');
}
}
if ($the_list == '') {
// no errors
// display message if all is good and not on shopping_cart page
if (DISPLAY_CART == 'false' && $_GET['main_page'] != FILENAME_SHOPPING_CART) {
$messageStack->add_session('header', SUCCESS_ADDED_TO_CART_PRODUCT, 'success');
}
//remove the existing item
$_SESSION['cart']->remove($_POST['edit_item_id']);
//head off to our destination
zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
} else {
// errors - display popup message
}
}
?>
Re: Editing cart contents -- esp products with attributes
I'm still trying to work out a ZenId weirdness issue. Could this affect the edit cart functionality?
Re: Editing cart contents -- esp products with attributes
Sorry Shocker I have been out of action for a few weeks. Started a new job, sigh. Zencart was supposed to rid me of that tyranny!
I don't know what you mean by Zenid weirdness issue. I really don't have enough information to work with to help you out. You talked about a button problem but I could not see that.
The only problem I could see was where an edited product, was quietly removed from the cart. That looks like the workings of the old version. The new version only removes the pre edit product after the post edit one has been added. If the post edit one can't be added, the pre edit one is not removed. Are you sure you don't have old files from the previous edit cart version in there?
No one else is reporting this problem, so I think something is screwy is going on, in your system.
You might want to try:
1) creating a new dummy product with only one dummy attribute and seeing how edit cart mod works.
2) removing edit cart completely and re installing
3) removing other mods you have installed and see if their removal affects edit cart
If you are experiencing weirdness in other areas (you said zenid, and the mysterious button) then it may be connected. But I don't know the specifics so I can't really say.
Justin Hunt
Re: Editing cart contents -- esp products with attributes
hello
I installed edit cart, works fine, I believe but the "click to edit" text is missing from product link on shopping cart. Please assist
Thank you again
Re: Editing cart contents -- esp products with attributes
Quote:
Originally Posted by
justinhunt
Sorry Shocker I have been out of action for a few weeks. Started a new job, sigh. Zencart was supposed to rid me of that tyranny!
I don't know what you mean by Zenid weirdness issue. I really don't have enough information to work with to help you out. You talked about a button problem but I could not see that.
The only problem I could see was where an edited product, was quietly removed from the cart. That looks like the workings of the old version. The new version only removes the pre edit product after the post edit one has been added. If the post edit one can't be added, the pre edit one is not removed. Are you sure you don't have old files from the previous edit cart version in there?
No one else is reporting this problem, so I think something is screwy is going on, in your system.
You might want to try:
1) creating a new dummy product with only one dummy attribute and seeing how edit cart mod works.
2) removing edit cart completely and re installing
3) removing other mods you have installed and see if their removal affects edit cart
If you are experiencing weirdness in other areas (you said zenid, and the mysterious button) then it may be connected. But I don't know the specifics so I can't really say.
Justin Hunt
Thanks for getting back to me. I don't know what's up. The edit cart contents mod seems to be fine now.
I'll check this from time to time and try to pay more close attention to the scenario.
Thanks for your attention.
Re: Editing cart contents -- esp products with attributes
OK Shocker, glad it is working for you.
Zafer, You will have to edit your tpl_shopping_cart_default.php file, and add the "click to edit" text. The details are in the read me file with the edit cart mod you downloaded.
Justin