Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:14+00:00 2026-06-15T23:56:14+00:00

Using my own controller, I’m adding a product to the Magento cart. It has

  • 0

Using my own controller, I’m adding a product to the Magento cart. It has 3 custom options: 2 dropdown options (color and size) and a file option (design). The code adding the product to the cart is

// obtain the shopping cart
$cart = Mage::getSingleton('checkout/cart');

// load the product
$product = Mage::getModel('catalog/product')
    ->load($productId);

// do some magic to obtain the select ids for color and size ($selectedSize and $selectedColor)
// ...

// define the buy request params
$params = array(
    'product'       => $productId,
    'qty'           => $quantity,
    'options'       => array(
        $customOptionSize->getId()  => $selectedSize,
        $customOptionColor->getId() => $selectedColor,

        // set the file option, but how? 
    ),
);

// add this configuration to cart
$cart->addProduct($product, $paramObject);
$cart->save();

// set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

My question is: How do I attach a certain file to the design option?

The file has already been transferred to the server side (actually via the request). I could, however, fake uploading if this would be required. But until now I have not found a single source of information on setting file custom options…

My best guess from a tour through the Magento sources, is that the buy request needs some additional data (not in the options, but in the params object), like: option_123_file => something, but what exactly is needed I did not figure out yet. This part of the Magento sources is rather, uhh, not so straight forward. Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:56:15+00:00Added an answer on June 15, 2026 at 11:56 pm

    Ok finally figured this out. The params array needs special entry to tell the custom option with the key “options_xx_file_action” what to do with a file (‘save_new’ or ‘save_old’). This would look like:

    $params = array(
        'product'       => $productId,
        'qty'           => $quantity,
        'options'       => array(
            $customOptionSize->getId()  => $selectedSize,
            $customOptionColor->getId() => $selectedColor,
        ),
        'options_'.$customOptionDesign->getId().'_file_action'=>'save_new',
    );
    

    Obviously, you will need to add the file to the post request (via form or therelike). The name of the file should be “options_xx_file”. For example, in my case my $_FILES looked like:

    Array (
    [options_108_file] => Array
        (
            [name] => i-like.png
            [type] => application/octet-stream
            [tmp_name] => C:\xampp\tmp\phpAAB8.tmp
            [error] => 0
            [size] => 6369
        )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after using own custom cms for over 6 years, I decided to go for
I am using my own custom navigationBar, but i need to access it in
I am using my own controller factory in an MVC 2 app, and this
I'm trying to write my own controller for a USB device instead of using
I am using my own controller factory and sometimes in function public IController CreateController(RequestContext
I am using spring mvc3 now,and I found that most of my controller own
In FuelPHP when using Controller_REST I can't use \Response as REST controller has its
I am using an Account Controller which doesnt have its own table but uses
I am using my own implementation of the UserDetailsService interface to load a User
I'm using my own class for database queries, extending mysqli: class iDatabase extends mysqli

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.