我只有一个自定义选项,即文件类型,我试图通过编程方式将产品添加到购物车,如下所示:
$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());
}
但我得到了这样的错误:
请指定产品的必需选项
您能否在183行的app / code / core / Mage / Catalog / Model / Product / Option / Type / File.php中记录原始异常并将其发布?
—
LDusan '18