Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Customization Questions


mattman3891

Recommended Posts

Hi,

I'm starting to look at different types of shopping carts and stumbled upon osCommerce, I have a questions regarding something I'm wondering if osCommerce can accomplish. I would like a customer to select a product and then upload an image to have printed on by us or select a set of images that are already available. I was searching around and couldn't really find anything related to this, is there an easy way to do this in osCommerce or will I have to build my own shopping cart to accomplish this. If anyone has any ideas or could point me in the right direction I would appreciate it.

 

Thanks!

 

-matt

Link to comment
Share on other sites

Hi,

I'm starting to look at different types of shopping carts and stumbled upon osCommerce, I have a questions regarding something I'm wondering if osCommerce can accomplish. I would like a customer to select a product and then upload an image to have printed on by us or select a set of images that are already available. I was searching around and couldn't really find anything related to this, is there an easy way to do this in osCommerce or will I have to build my own shopping cart to accomplish this. If anyone has any ideas or could point me in the right direction I would appreciate it.

 

Hey Matt - you can this. The great thing about oscommerce is that is exceedingly customizable. It is really only limited by your imagination! oh - and you're abilities. ;-0

 

I've written code to do this a couple of months ago. It's prettty straight forward :

 

 

The user selects their jpg file locally, and the application renames the file to their order_id - they do this from the confirm button.

 

I'll leave it up to you to decide *when* you want to error check the file properties. You probably want to capture the order details, whether the file upload fails or not right ? This way you can contact the customer immediately if their upload fails for whatever reason. You'll have not lost a sale.

 

Also you will likely want to include the URL to the uploaded file in the confirmation email as well. Just add a line to the

$email_order .=

using the web site address, uploaded path, and then the insert_id variable.

Add a definition variable to the /languiages/checkout_confirmation.php file to show something like this :

existing --> EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n" .

 

path to file --> tep_href_link(EMAIL_TEXT_PATH_TO_FILE, . $insert_id, 'SSL', false) . "\n";

 

 

Also - I have not checked for file type or for file size.

I would highly recommend you implement both these checks.

You can use the $_FILES['userfile']['type'] to check the type of file being uploaded (no exe's for example) and you can use the $_FILES['userfile']['size'] method to make sure a one gig file is not being uploaded! lol.

Easiest would be to only allow jpgs.

 

 

 

Here are the steps to implement :

 

1. checkout_confirmation.php :

change :

echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');

 

to :

echo tep_draw_form('checkout_confirmation', $form_action_url, 'post', 'enctype="multipart/form-data"');

 

This simply passes the enctype parameter to the draw_form function.

 

 

2. checkout_confirmation.php

After the :

if (is_array($payment_modules->modules)) {

echo $payment_modules->process_button();

}

 

But before the :

echo tep_image_submit('button_confirm_order.gif', IMAGE_BUTTON_CONFIRM_ORDER) . '</form>' . "\n";

 

add the upload form like this (I've include the above two lines) :

 

if (is_array($payment_modules->modules)) {

echo $payment_modules->process_button();

}

?>

 

<tr>

<td class="main">File to upload:</td>

<td class="main"><input type="file" name="fileupload" class="textfield" size="30"></td></tr>

 

<?php

echo tep_image_submit('button_confirm_order.gif', IMAGE_BUTTON_CONFIRM_ORDER) . '</form>' . "\n";

?>

 

3.checkout_process.php

After the :

include('includes/application_top.php');

 

put in a function to replace any crazy characters in the file name :

 

function replace($o) {

$o=str_replace("/","",$o);

$o=str_replace("\\","",$o);

$o=str_replace(":","",$o);

$o=str_replace("*","",$o);

$o=str_replace("?","",$o);

$o=str_replace("<","",$o);

$o=str_replace(">","",$o);

$o=str_replace("\"","",$o);

$o=str_replace("|","",$o);

return $o;

}

 

4. checkout_process.php

 

Here is where you assign the order_id number to the uploaded file :

 

At any point AFTER this for loop :

for ($i=0; $i<$size; $i++) {

$sql_data_array = array('orders_id' => $insert_id,

'title' => $order_totals[$i]['title'],

'text' => $order_totals[$i]['text'],

'value' => $order_totals[$i]['value'],

'class' => $order_totals[$i]['code'],

'sort_order' => $order_totals[$i]['sort_order']);

tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);

}

 

process the file.

 

Provide the upload directory path, assign the temporary name to the file, and copy it :

 

 

$dir_store= "/home/username/public_html/client_files/".$insert_id.".jpg";

$fileupload_name=$_FILES[fileupload][name];

 

if ($fileupload_name) {

tep_session_register('checkfile');

 

if(copy($_FILES['fileupload']['tmp_name'], $dir_store)) {

$checkfile = $fileupload_name." was Successful";

} else {

$checkfile = $fileupload_name." Upload failed";

}

} else {

$checkfile = "No file was chosen to upload";

global $checkfile;

}

 

 

Then you can echo it out on the checkout_success page like this :

 

<tr><td><?php echo $checkfile; ?> </td><tr>

 

Let me know if this is not clear - or you get stuck or whatever.

 

 

Corrina

Link to comment
Share on other sites

Hi,

I'm starting to look at different types of shopping carts and stumbled upon osCommerce, I have a questions regarding something I'm wondering if osCommerce can accomplish. I would like a customer to select a product and then upload an image to have printed on by us or select a set of images that are already available. I was searching around and couldn't really find anything related to this, is there an easy way to do this in osCommerce or will I have to build my own shopping cart to accomplish this. If anyone has any ideas or could point me in the right direction I would appreciate it.

 

Thanks!

 

-matt

 

should also mention that the contribs are invaluable :

http://www.oscommerce.com/community/contributions

Link to comment
Share on other sites

Thank You Corrina, I will take a look at implementing this later today, doesn't seem to difficult. Now this would add an image upload to a product correct, and then the user would get a confirmation email with the image that was uploaded and the product ordered? I'll start messing around with it, Thank You for your help...

 

-matt

Link to comment
Share on other sites

Now this would add an image upload to a product correct, and then the user would get a confirmation email with the image that was uploaded and the product ordered?

 

 

During the checkout process, the user is asked to browse their local PC and upload an image.

 

The confirmation is up to you.

Personally - I would accept and insert the order into the database so as to not rely on the upload being successful to accept the sale.

 

You could include the URL to the uploaded image in the confirmation email if you want to wait for it - or include the URL to the image on the success page.

But - if the upload fails, I would guess you'd like to immediately contact the client and let them know - 'we have your order, but the upload failed, can you please just email us your file' or whatever.

 

Corrina

Link to comment
Share on other sites

Corrina - you should release your code as a contribution. A lot of people would find it useful ;-)

 

 

Hi Jason - thanks for the kudos.

 

I don't think it would be a responsible idea to post the code without putting the necessary file checks in place do you ?

Like :

check file size - say less than a meg

file type - jpg, bmp, gif

return code - which would really check the path structure of the uploaded file, make sure it gets renamed properly

etc, etc, etc.

 

The code I posted works perfectly - but you need to have the technical knowledge to be able to implement error checking properly, and as it stands right now it would be the responsibility of the user to do this - which many people would not have.

 

What do you think ?

Not to mention I'm NOT a documentation girl! lol. :-)

I'd have to write a supporting document for it wouldn't I ?

Any volunteers ?

 

Corrie

Link to comment
Share on other sites

I don't think it would be a responsible idea to post the code without putting the necessary file checks in place do you ?

So put the file checks in and release it ;-)

 

You wouldn't need any documentation other than installation instructions (which you've already written above) and maybe a sentence of two describing what your contribution does. Granted it may need some more work to get it from where it is now to where you feel it needs to be to release it as a mod - but that's half the fun ;-)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...