Hi there.
I believe my above post is correct. I now have this function working on multiple items with no other attributes.
-- Changes --
BUGFIX: The file upload is now required on products even if they do not have other attributes.
-- Instructions --
!!! IMPORTANT: BACKUP includes/classes/shopping_cart.php !!!
1) In file includes/classes/shopping_cart.php
Around Line 1570 find:
PHP Code:
function 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 />';
}
}
}
2) -- ONLY REQUIRED IF YOU HAVE FOLLOWED POST #9 --
If you have followed my instructions in post #9 delete ALL of the text between my BOF and EOF comments including the comments themselves...
PHP Code:
/**
BOF - FORCE FILE UPLOAD (Addition)
NOTE: Upload limits are now controlled entirely by php.ini (upload_max_filesize & post_max_size) also NOTE: post_max_size MUST be greater than upload_max_filesize
For this fix to work ensure that Admin > Configuration > Maximum Values > Maximum File Upload Size is GREATER (in bytes) than upload_max_filesize (in MB)
The Allowed file upload extensions are still controlled by Admin > Configuration > Maximum Values > Allowed Filename Extensions for uploading except a mismatch now prevents the product being added to cart
**/
.. DELETE ME INCLUDING THE COMMENTS IMMEDIATELY ABOVE AND BELOW ME...
//EOF - FORCE FILE UPLOAD (Addition)
3) -- BUGFIX --
Being careful to place it in exactly the right place add all of the code shown between the //BOF and //EOF comments in the code below. Note all of the code NOW comes after the opening brace of the line: isset($_POST['products_id'] ... but before the line if (isset($_POST['id']))...
PHP Code:
if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
// verify attributes and quantity first
$the_list = '';
$adjust_max= 'false';
/**
BOF - FORCE FILE UPLOAD (Addition)
NOTE: Upload limits are now controlled entirely by php.ini (upload_max_filesize & post_max_size) also NOTE: post_max_size MUST be greater than upload_max_filesize
For this fix to work ensure that Admin > Configuration > Maximum Values > Maximum File Upload Size is GREATER (in bytes) than upload_max_filesize (in MB)
The Allowed file upload extensions are still controlled by Admin > Configuration > Maximum Values > Allowed Filename Extensions for uploading except a mismatch now prevents the product being added to cart
**/
if (isset($_GET['number_of_uploads']) and $_GET['number_of_uploads'] > 0) {
if (!zen_not_null($extensions)) { // Fill the $extensions array with the allowed filename extensions
if (!defined(UPLOAD_FILENAME_EXTENSIONS)) define ('UPLOAD_FILENAME_EXTENSIONS','jpg,jpeg,gif,png,eps,cdr,ai,pdf,tif,tiff,bmp,zip');
$extensions=explode(" ",preg_replace('/[.,;\s]+/',' ',UPLOAD_FILENAME_EXTENSIONS));
}
if (empty($_FILES['id']['tmp_name'])) { // If post_max_size is exceeded (the file is WAY too large) then the $_FILES array is empty, throw error
$the_list .= '<span class="alertBlack"> File is too large to upload, please select a smaller file.</span ';
}
foreach ($_FILES['id']['error'] as $error) {
if ($error == UPLOAD_ERR_NO_FILE) { // If no upload was selected throw error
$the_list .= '<span class="alertBlack"> Please select a file to upload. </span>';
}
if ($error == UPLOAD_ERR_INI_SIZE or $error == UPLOAD_ERR_FORM_SIZE) { // If upload_max_filesize is exceeded throw error
$the_list .= '<span class="alertBlack"> File is too large to upload, please select a smaller file.<span class="alertBlack">';
}
if ($error == UPLOAD_ERR_PARTIAL) { // If the upload was interrupted throw error
$the_list .= '<span class="alertBlack"> Sorry the upload was interrupted, please try again. <span class="alertBlack">';
}
if ($error == '') {
foreach ($_FILES['id']['name'] as $filename) { //If no other errors check the file extension against the $extensions array and throw error if there is no match
$error_free = 0;
$pathinfo = pathinfo($filename);
$pathinfo = $pathinfo[extension];
for($i = 0; $i < count($extensions); $i++) {
if ($extensions[$i] == "$pathinfo") {
$error_free = 1;
break;
}
}
if ($error_free != 1) {
$the_list .= '<span class="altertBlack">' . ERROR_FILETYPE_NOT_ALLOWED . '<br/> Allowed extensions: ' . UPLOAD_FILENAME_EXTENSIONS . '</span>';
}
}
}
}
}
//EOF - FORCE FILE UPLOAD (Addition)
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 />';
}
}
}
4) -- ONLY IF YOU HAVE NOT FOLLOWED POST #9 --
Access the php.ini file on your server (or use a .htaccess override) and find:
upload_max_filesize = ...
post_max_size = ...
upload_max_filesize should be set to the maximum file size that you would like to allow users to upload. This now controls the maximum upload file size (NOT THE ZEN CART ADMIN)
post_max_size should be set to a value LARGER (by say +1M) than upload_max_filesize.
5) -- ONLY IF YOU HAVE NOT FOLLOWED POST #9 --
Navigate to Admin > Configuration > Maximum Values > Maximum File Upload Size
Ensure that Maximum File Upload Size is LARGER (in bytes) than upload_max_filesize.
Eg... if upload_max_filesize = 1M set Maximum File Upload Size to 1,048,577 or larger.
6) To change the error messages you give your customer search the above code for the current error message and change it to a more appropriate one. If you had already followed post #9 and then changed the error messages you will now have to change the error messages again
Bookmarks