· 8 years ago · Dec 28, 2017, 12:16 PM
1$logoSku = 'lg-brnd01';
2$productLogo = Mage::getModel('catalog/product')->loadByAttribute('sku',$logoSku);
3$logoOptions = $productLogo->getOptions();
4$opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($productLogo);
5$i =0;
6$cart = Mage::getModel('checkout/cart');
7$cart->init();
8$params = array(
9 'product' => $productLogo->getId(),
10 'qty' => 1,
11 'form_key' => Mage::getSingleton('core/session')->getFormKey(),
12);
13foreach ($opts->getData() as $data) {
14 $optionId = $data['option_id'];
15 $image = $paths[0]['name'];
16 $options = array(
17 $optionId => array(
18 'type' => $paths[0]['type'],
19 'title' => $image,
20 'quote_path' => DS.'media'.DS.'uploads'.DS.'logo-branding'.DS.$quote_id.DS.$image,
21 'order_path' => DS.'media'.DS.'uploads'.DS.'logo-branding'.DS.$quote_id.DS.$image,
22 'fullpath' => $path.$image,
23 'secret_key' => substr(md5(file_get_contents($path.$image)), 0, 20)
24 ),
25 );
26 $params['options_'.$optionId.'_file_action'] = 'save_new';
27}
28$params['options'] = $options;
29print_r($params);
30$request = new Varien_Object();
31$request->setData($params);
32try {
33 $cart->addProduct($productLogo->getId(), $request);
34 $cart->save();
35 $i++;
36} catch (Exception $e) {
37 print_r($e->getMessage());
38}
39
40Please specify the product's required option(s)