1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Please specify the product's required option(s) Custom Option type file

Discussion in 'Programming/Internet' started by Hunter, Aug 1, 2020.

  1. Hunter

    Hunter Guest

    I got only one custom option, which is file type, I tried to add product to cart programmatically like this:

    $logoSku = 'lg-brnd01';
    $productLogo = Mage::getModel('catalog/product')->loadByAttribute('sku',$logoSku);
    $logoOptions = $productLogo->getOptions();
    $opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($productLogo);
    $i =0;
    $cart = Mage::getModel('checkout/cart');
    $cart->init();
    $params = array(
    'product' => $productLogo->getId(),
    'qty' => 1,
    'form_key' => Mage::getSingleton('core/session')->getFormKey(),
    );
    foreach ($opts->getData() as $data) {
    $optionId = $data['option_id'];
    $image = $paths[0]['name'];
    $options = array(
    $optionId => array(
    'type' => $paths[0]['type'],
    'title' => $image,
    'quote_path' => DS.'media'.DS.'uploads'.DS.'logo-branding'.DS.$quote_id.DS.$image,
    'order_path' => DS.'media'.DS.'uploads'.DS.'logo-branding'.DS.$quote_id.DS.$image,
    'fullpath' => $path.$image,
    'secret_key' => substr(md5(file_get_contents($path.$image)), 0, 20)),
    );
    $params['options_'.$optionId.'_file_action'] = 'save_new';
    }
    $params['options'] = $options;
    print_r($params);
    $request = new Varien_Object();
    $request->setData($params);
    try {
    $cart->addProduct($productLogo->getId(), $request);
    $cart->save();
    $i++;
    } catch (Exception $e) {
    print_r($e->getMessage());
    }


    but I got an error like this:


    Please specify the product's required option(s)

    Login To add answer/comment
     

Share This Page